There are multiple routes between a vertex and a vertex, and the path is open on time. Therefore, you need to record more information on the edge. The stringstream class is unknown when reading the number of rows.
The Code is as follows:
# Include <iostream> # include <cstdlib> # include <cstring> # include <cstdio> # include <queue> # include <string> using namespace STD; const int INF = 0x3f3f3f3f; int n, m, S, T; string STR; struct edge {int V, CT, next; int Ti [20] [2], ways;} e [505]; int idx, head [55]; void insert () {int A [40]; char * s = new char [Str. size () + 1]; strcpy (S, str. c_str (); int I = 0; For (char * P = strtok (S, ""); P! = NULL; ++ I) {A [I] = atoi (p); P = strtok (null, "") ;}++ idx; E [idx]. V = A [1], E [idx]. ct = A [2]; E [idx]. next = head [A [0]; head [A [0] = idx; A [2] = 0; Int J, K; For (j = 3, k = 0; j <I; j + = 2, ++ K) {// read channel closure and start time e [idx]. ti [k] [0] = A [J-1]; // enable time e [idx]. ti [k] [1] = A [J]; // close time} If (j = I) {// This range is always enabled e [idx]. ti [k] [0] = A [J-1]; E [idx]. ti [k] [1] = inf; ++ K;} e [idx]. ways = K-1; ++ idx; E [idx] = E [idx-1]; E [idx]. V = A [0], E [idx]. next = head [A [1]; head [A [1] = idx;/* For (j = 0; j <= E [idx]. ways; ++ J) {printf ("% d \ n", E [idx]. ti [J] [0], E [idx]. ti [J] [1]);} */Delete [] S;} int dis [55]; bool vis [55]; void spfa () {memset (VIS, 0, sizeof (VIS); memset (DIS, 0x3f, sizeof (DIS); queue <int> q; q. push (s); DIS [s] = 0; vis [s] = true; while (! Q. empty () {int v = Q. front (); q. pop (); vis [v] = false; For (INT I = head [v]; I! =-1; I = E [I]. next) {for (Int J = 0; j <= E [I]. ways; ++ J) {// If you can use this channel from V, you can use if (DIS [v] + E [I]. CT <= E [I]. ti [J] [1] & E [I]. CT + E [I]. ti [J] [0] <= E [I]. ti [J] [1]) {int temp = max (DIS [v], E [I]. ti [J] [0]) + E [I]. CT; If (temp <dis [E [I]. v]) {dis [E [I]. v] = temp; If (! Vis [E [I]. v]) {q. push (E [I]. v); vis [E [I]. v] = true ;}} break ;}}} int main () {While (scanf ("% d", & N), n) {memset (Head, 0xff, sizeof (head); idx =-1; scanf ("% d", & M, & S, & T); char C; while (C = getchar ())! = '\ N'); For (INT I = 0; I <m; ++ I) {Getline (CIN, STR); insert () ;} spfa (); printf (DIS [T] = inf? "* \ N": "% d \ n", DIS [T]);} return 0 ;}