MediumRating 1700
3607. Power Grid Maintenance
arrayhash-tabledepth-first-searchbreadth-first-searchunion-findgraphheap-priority-queueordered-set
解題說明
C++ 解法
複雜度分析
虛擬碼
1. Build adjacency list from edges 2. Identify faulty nodes (put in a set) 3. Multi-source Dijkstra: a. Initialize dist[i] = 0 for all non-faulty nodes, push them into min-heap b. Standard Dijkstra relaxation 4. Sum up dist[f] for all faulty nodes f 5. Return total (or -1 if any faulty node is unreachable)