Loading editor...
/*
Question:
Ask if I can make a profit after a round trip
Analysis:
Whether the directed graph is in a negative ring, because each vertex may have a negative ring,
Directly use flordAlgorithmJust do it.
*/
# Include <iostream>
# Include <string>
# Include <cstring>
Using namespace STD;
# Define x 35
String City [X], S1, S2;
Double map [x] [x];
Int main ()
{
Freopen ("sum. In", "r", stdin );
Freopen ("sum. Out", "W", stdout );
Int m, n, x, y, CNT = 0;
Double DIS;
While (CIN> N, N)
{
Memset (MAP, 0, sizeof (MAP ));
For (INT I = 0; I <n; I ++)
{
Cin> City [I];
Map [I] [I] = 1;
}
Cin> m;
For (INT I = 0; I <m; I ++)
{
Cin> S1> dis> S2;
For (Int J = 0; j <n; j ++) // locate the start point and end point.
{
If (S1 = City [J])
X = J;
If (s2 = City [J])
Y = J;
}
Map [x] [Y] = DIS; // path length of the Directed Graph
}
For (int K = 0; k <n; k ++) // fload Algorithm
For (INT I = 0; I <n; I ++)
For (Int J = 0; j <n; j ++)
If (Map [I] [J] <map [I] [k] * map [k] [J]) // relaxation operation
Map [I] [J] = map [I] [k] * map [k] [J];
Bool flag = true;
For (INT I = 0; I <n; I ++)
If (Map [I] [I]> 1) // if a negative ring exists
Flag = false;
If (! Flag)
Printf ("case % d: Yes \ n", ++ CNT );
Else
Printf ("case % d: NO \ n", ++ CNT );
}
Return 0;
}