Warehouses
Time limit2sMemory limit1024 MB
Given a weighted road graph and each warehouse's company, find for each company the sum of max-bottleneck path values over all its warehouse pairs.
- Level
Medium7 of 10
- Topics
- Union-find, Sorting, Hash map, Tree
- Solved
- No attempts yet
Problem
UCPC City has warehouses, and companies each own some of them. The warehouses are numbered from to , and the companies are numbered from to . bidirectional roads connect pairs of warehouses, and each road has a transfer limit. Two warehouses may be connected by several roads, and there is always a path between any two warehouses.
Suppose goods are shipped between two warehouses. The shipping limit between them is the smallest transfer limit among the roads on a path connecting them. If several paths connect the two warehouses, the path with the largest shipping limit is chosen.
For each company, compute the sum of the shipping limits over all pairs of warehouses owned by that company.
Each company is guaranteed to own at least 2 warehouses.
Input
The first line contains three integers , , and , separated by spaces.
The second line contains integers , separated by spaces. Warehouse is owned by company .
The next lines each contain three integers , , and , separated by spaces. Each line describes a bidirectional road between warehouses and with transfer limit .
Output
Print lines. The -th line contains the sum of shipping limits over all pairs of warehouses owned by company , for from to .