/*the indentation plus the longest road should use topological sequences don't want to write SPFA run for a minute.*/#include<cstdio>#include<algorithm>#include<cstring>#include<queue>#include<iostream>#defineM 500200#definell Long Longusing namespacestd;intBe[m], ed[m], to[m], nxt[m], DFT, Head[m], CNT, belong[m], dfn[m], low[m], dis[m], ver[m], ver2[m], st[m], top, tot;< /c4>BOOLVis[m], isj[m], zz[m];intRead () {intNM =0, F =1; Charc =GetChar (); for(;!isdigit (c); c = GetChar ())if(c = ='-') F =-1; for(; IsDigit (c); c = GetChar ()) NM = NM *Ten+ C-'0'; returnNM *F;}voidPushintXibintVJ) {CNT++; TO[CNT]=VJ; NXT[CNT]=Head[vi]; HEAD[VI]=CNT;}voidTarjan (intx) {dfn[x]= Low[x] = + +DFT; st[++top] =x; VIS[X]=true; for(inti = head[x]; I i =Nxt[i]) { intVJ =To[i]; if(!DFN[VJ]) {Tarjan (VJ); LOW[X]=min (low[x], low[vj]); } Else if(VIS[VJ]) low[x] =min (low[x], dfn[vj]); } if(Dfn[x] = =Low[x]) {Tot++; while(St[top]! =x) {Belong[st[top]]=tot; Ver2[tot]+=Ver[st[top]]; if(Isj[st[top]]) Zz[tot] =true; Vis[st[top]]=false; Top--; } Belong[st[top]]=tot; Ver2[tot]+=Ver[st[top]]; if(Isj[st[top]]) Zz[tot] =true; Vis[st[top]]=false; Top--; }}voidSPFA (intx) {queue<int>Q; DIS[X]=Ver2[x]; memset (Vis,0,sizeof(VIS)); Q.push (x); while(!Q.empty ()) { intOP =Q.front (); Q.pop (); VIS[OP]=false; for(inti = Head[op]; I i =Nxt[i]) { intVJ =To[i]; if(DIS[VJ] < Dis[op] +VER2[VJ]) {DIS[VJ]= Dis[op] +VER2[VJ]; if( !VIS[VJ]) Q.push (VJ), VIS[VJ]=true; } } }}intMain () {intn = Read (), M =read (); for(inti =1; I <= m; i++) {Be[i]= Read (), ed[i] =read (); Push (Be[i], ed[i]); } for(inti =1; I <= N; i++) Ver[i] =read (); ints = Read (), k =read (); for(inti =1; I <= K; i++) Isj[read ()] =true; Tarjan (s); memset (Head,0,sizeof(head)); CNT=0; for(inti =1; I <= m; i++) { intVI = belong[be[i]], VJ =Belong[ed[i]]; if(vi = = VJ)Continue; Push (vi, VJ); } SPFA (Belong[s]); intans=0; for(inti =1; I <= tot; i++) { if(Zz[i]) ans =Max (ans, dis[i]); } cout<<ans; return 0;}
APIO2009 Grab Plan