SPFA. Note The state transition condition, ANS solution needs to be solved in the BFS center. As long as the location n is reached, there is no need to wait for other tourist.
It's pretty simple, pay attention to the details.
1 /*229B*/2#include <iostream>3#include <string>4#include <map>5#include <queue>6#include <Set>7#include <stack>8#include <vector>9#include <deque>Ten#include <algorithm> One#include <cstdio> A#include <cmath> -#include <ctime> -#include <cstring> the#include <climits> -#include <cctype> -#include <cassert> -#include <functional> +#include <iterator> -#include <iomanip> + using namespacestd; A //#pragma COMMENT (linker, "/stack:102400000,1024000") at - #defineSTI set<int> - #defineStpii Set<pair<int, int> > - #defineMpii map<int,int> - #defineVI vector<int> - #definePII pair<int,int> in #defineVpii vector<pair<int,int> > - #defineRep (I, A, n) for (int i=a;i<n;++i) to #definePer (i, a, n) for (int i=n-1;i>=a;--i) + #defineCLR Clear - #definePB Push_back the #defineMP Make_pair * #defineFIR First $ #defineSEC SecondPanax Notoginseng #defineAll (x) (x). Begin (), (x). End () - #defineSZ (x) ((int) (x). Size ()) the #defineLson L, Mid, rt<<1 + #defineRson mid+1, R, rt<<1|1 A the Const intMAXN = 1e5+5; + Const intINF =0x3f3f3f3f; - Vpii E[MAXN]; $ Vpii T[MAXN]; $ intDIS[MAXN]; - BOOLVISIT[MAXN]; - intA[MAXN], B[MAXN]; the - intMain () {WuyiIos::sync_with_stdio (false); the #ifndef Online_judge -Freopen ("data.in","R", stdin); WuFreopen ("Data.out","W", stdout); - #endif About $ intN, M; - intu, V, W; - -scanf"%d%d", &n, &m); A while(m--) { +scanf" %d%d%d", &u, &v, &W); the E[U].PB (MP (V, W)); - E[V].PB (MP (U, W)); $ } theRep (I,1, n+1) { thescanf"%d", &m); theRep (J,1, m+1) thescanf"%d", &a[j]); -B[M] =1; inPer (J,1, M) { the if(a[j]+1= = a[j+1]) theB[J] = b[j+1] +1; About Else theB[J] =1; the } theRep (J,1, m+1) + T[I].PB (MP (A[j], b[j])); - } the Bayi inti, TMP; the intAns =INF; thePII P (0,0); - Vpii::iterator iter; -queue<int>Q; theQ.push (1); thememset (DIS,0x3f,sizeof(DIS)); the //May is has 0 in t[1] theITER = Upper_bound (All (t[1]), p); - if(iter!=t[1].end () && iter->fir==0) { thedis[1] = iter->sec; the}Else { thedis[1] =0;94 } thevisit[1] =true; the the while(!Q.empty ()) {98U =Q.front (); About Q.pop (); -Visit[u] =false;101 for(i=0; I<sz (E[u]); ++i) {102v =E[u][i].fir;103W =e[u][i].sec;104TMP = Dis[u] +W; the if(V==n && tmp<ans)106Ans =tmp;107P.fir =tmp;108ITER =Upper_bound (All (T[v]), p);109 if(Iter!=t[v].end () && iter->fir==tmp) { theTMP + = iter->sec;111 } the if(TMP <Dis[v]) {113DIS[V] =tmp; the if(!Visit[v]) { theVISIT[V] =true; the Q.push (v);117 }118 }119 } - }121 122Ans = ans==inf? -1: ans;123printf"%d\n", ans);124 the #ifndef Online_judge126printf"Time =%d.\n", (int) clock ());127 #endif - 129 return 0; the}
"CF" 142 Div.1 B. Planes