Poj-3286 Silver Cow Party
What is the longest round-trip path for a ox to join the party. Flip the matrix during round-trip, calculate it again, and sum it twice.
# Include
# Include
# Include
# Include
# Include
Using namespace std; const int MAXV = 4010; const int inf = 10000000; int map [MAXV] [MAXV]; // path length int d [MAXV], re_d [MAXV]; // distance from bool vis [MAXV]; int n, m, x; void dijkstra (int s) {for (int I = 1; I <= n; I ++) {vis [I] = 0; d [I] = map [s] [I];} d [s] = 0; while (1) {int min = inf, v =-1; for (int I = 1; I <= n; I ++) if (! Vis [I] & d [I]
D [v] + map [v] [I]) d [I] = map [v] [I] + d [v] ;}} int main () {int I, j, a, B, c; while (scanf (% d, & n, & m, & x )! = EOF) {for (I = 1; I <= n; I ++) for (j = 1; j <= n; j ++) {if (I = j) map [I] [I] = 0; else map [I] [j] = inf;} for (I = 1; I <= m; I ++) {scanf (% d, & a, & B, & c ); if (map [a] [B]> c) map [a] [B] = c;} dijkstra (x); for (int I = 1; I <= n; I ++) re_d [I] = d [I]; for (int I = 1; I <= n; I ++) for (int j = 1; j