Description
The electric science training has been over for a long time, but the taste of the electric science makes us think for a long time.
Lzh is particularly profound in the electric science campus, and these strange smells often make him lose appetite. So wherever he goes, he always wants to take the "best route ".
Lzh marks a wi value for all electrical paths. The smaller the WI value, the more strange the smell on the path.
The so-called "best route" from location a to location B refers to the route with the largest sum of W in all possible route schemes from location a to location B.
Note: When lzh repeats the same path, the WI value on this path is calculated only once (the duplicate edge represents different paths ).
Now, lzh has a Q campus browsing plan. He wants you to tell him the sum of W on the "best route" in each plan.
Input
Multiple groups of test data
The first row of each group of test data has three integers, n, m, and Q, respectively, indicating that the electrical subject is composed of N vertices and M undirected edges, and lzh has Q plans (0 <n <= 100, 0 <m <= 10000, 0 <q <= 10000)
In the next m row, each row has three integers a, B, W, indicating that there is a directly connected path between vertex A and vertex B, and the path's "smell value" is W. (0 <a, B <n 0 <W <10000)
In the next Q row, each row has two integers U and V, indicating that the lzh browsing plan is to go from point u to point v.
Output
The output contains a total of Q rows. If the output cannot reach V from u, the output isNo solution
Otherwise, the sum of W on the "Optimal Route" is output.
Sample Input
6 4 3
1 2 3
2 3 4
3 5 1
4 5 2
1 4
4 1
6 4
Sample output
10
10
No solution
**************************************** **************************************** **************************************** **************************************** **********************
Question link:
Http: // 218.194.91.48/acmhome/problemdetail. do? & Method = showdetail & id = 1078
The question is to find the sum of all values in each tree (connected graph), because even if the destination is in front of you, you can go around two circles (only record once) before returning to the destination, no solution is lost only when no connected graph is created.
The question says that if there is a duplicate edge, then when there are multiple paths (the red letter above), so only one merge is performed, but the value of W still needs to be added, I don't know, but it's a pitfall !! You won't be able to throw a tree next time!
ACCode:
# Include <cstdio> # include <algorithm> # include <cstring> using namespace STD; int an [110], n, m, Q, Q1, q2, sum, CNT [110]; void Init () {int I; for (I = 1; I <= N; I ++) An [I] = I ;} int find (int x) {While (X! = An [x]) x = an [X]; return X;} void Union (int A, int B, int c) {int Ra = find (), RB = find (B); An [RB] = Ra; If (Ra! = Rb) CNT [Ra] + = CNT [RB]; // when the root node is not added at the same time, otherwise you need to add more CNT [Ra] + = C; // This is the int main () {int I, d, J, RQ, X, Y; while (~ Scanf ("% d", & N, & M, & Q) {memset (CNT, 0, sizeof (CNT); Init (); for (I = 0; I <m; I ++) {scanf ("% d", & X, & Y, & D); Union (X, y, d) ;}while (Q --) {scanf ("% d", & Q1, & q2); RQ = find (Q1); If (RQ! = Find (Q2) puts ("no solution"); else printf ("% d \ n", CNT [RQ]) ;}} return 0 ;}