1#include <cstdio>2#include <cstring>3#include <iostream>4#include <string>5#include <vector>6#include <queue>7#include <stack>8#include <Set>9#include <algorithm>Ten using namespacestd; One #defineN 500001 Astack<int>Sta; -queue<int>Que; - structEdge the { - intU,v,next; - }edge1[n],edge2[n]; - BOOLIsbar[n],instack[n]; + intLow[n],dfn[n],belong[n],money[n],newmoney[n],cnt,time,start; - intMaxmoney[n],head[n],head2[n]; + A voidAddintUintVintID) at { -EDGE1[ID].U =u; -EDGE1[ID].V =v; -Edge1[id].next =Head[u]; -Head[u] =ID; - } in - voidADD2 (intUintVintID) to { +EDGE2[ID].U =u; -EDGE2[ID].V =v; theEdge2[id].next =Head2[u]; *Head2[u] =ID; $ }Panax Notoginseng voidTarjan (ints) - { theDfn[s] = Low[s] = + +Time ; + Sta.push (s); AInstack[s] =true; the for(intU = head[s]; ~u; U =edge1[u].next) + { - intv =edge1[u].v; $ if(Dfn[v] = =0){ $ Tarjan (v); -Low[s] =min (Low[s], low[v]); - } the Else if(Instack[v] = =true){ -Low[s] =min (Low[s], dfn[v]);Wuyi } the } - if(Dfn[s] = =Low[s]) Wu { -CNT + +; About while(!Sta.empty ()) { $ inttemp =Sta.top (); Sta.pop (); -Belong[temp] =CNT; -NEWMONEY[CNT] + =Money[temp]; -Instack[temp] =false; A if(temp = = s) Break; + } the } - } $ the intSPFA () the { the intAns =0; the Que.push (start); -memset (Maxmoney,0,sizeof(Maxmoney)); inMaxmoney[start] =Newmoney[start]; the while(!que.empty ()) the { About intnow =Que.front (); Que.pop (); the for(intU = Head2[now]; ~u; U =edge2[u].next) the { the intv =edge2[u].v; + if(Maxmoney[now] + newmoney[v] >Maxmoney[v]) - { theMAXMONEY[V] = Maxmoney[now] +Newmoney[v];Bayi Que.push (v); the } the if(Isbar[v]) ans =Max (ans, maxmoney[v]); - } - } the returnans; the } the the intMain () - { the intn,m,a,b,s,p; thescanf"%d%d",&n,&m); thememset (head,-1,sizeof(head));94 for(inti =0; I < m; i++) { the /*Code*/ thescanf"%d%d", &a, &b); theAdd (a,b,i+1);98 } About for(inti =1; I <= N; i++) { - /*Code*/101scanf"%d",&money[i]);102 }103scanf"%d%d",&s,&p);104memset (Instack,false,sizeof(Instack)); thememset (Newmoney,0,sizeof(Newmoney));106memset (Isbar,false,sizeof(Isbar));107memset (DFN,0,sizeof(DFN));108CNT = time =0;109 for(inti =1; I <= N; i++)if(Dfn[i] = =0) Tarjan (i); the if(CNT = =1) {printf ("%d", newmoney[cnt]);return 0;}111 for(intI=0; i<p;i++) the {113scanf"%d", &a); theIsbar[belong[a]] =true; the } theStart =Belong[s];117memset (head2,-1,sizeof(head2));118 intKKK =0;119 for(inti =1; I <= N; i + +) - {121 for(intU = head[i]; ~u; U =Edge1[u].next) {122 intv =edge1[u].v;123 if(Belong[i]! =Belong[v]) {124ADD2 (belong[i],belong[v],++KKK); the }126 }127 } - 129 intAns =SPFA (); theprintf"%d", ans);131}
View Code
[Apio2009] Atm