Minimum spanning tree and queries
Time limit5sMemory limit256 MB
Given a weighted directed graph G, find the MST weight of G tensor Path_i for each i from 2 to Q+1, where Path_i is a chain of i vertices.
- Level
Hard9 of 10
- Topics
- Minimum spanning tree, Graph, Union-find, Dynamic programming
- Solved
- No attempts yet
문제
is a directed graph with vertices, and for every there is an edge .
The tensor product of a weighted directed graph and a directed graph is defined as follows.
- The vertex set is . It has vertices.
- Two vertices and are joined by an undirected edge if has an edge and has an edge .
- The weight of that edge equals the weight of the edge in .
You are given a directed graph with vertices and edges, and each edge has a positive integer weight. Consider . It is undirected, and each of its edges has a positive integer weight. For every , output the total weight of a minimum spanning tree of . The input guarantees that every asked in a query has a spanning tree.
입력
The first line contains three integers , , and (, ).
Each of the next lines contains three integers , , and , meaning there is an edge with weight (, ).
출력
Print lines. The -th line contains the answer for .