Test instructions
Given a direction graph, from the specified starting point, to any one of the specified end of the stop, to get through all the nodes of the maximum point right and. Points, number of sides <=500000
Because the points within a strongly connected component can reach each other, if you go through one of these points, you should go through all the points within the strongly connected component where it resides, thus shrinking a strong connected component to a point
This gives a direction-free graph, in the figure DP can be
First of all the points can be reached at the point of the topological sort, and then use the queue to maintain a 0-degree point, each time the team to remove the first element, with its answer to update the other points can be
There seems to be a point that will re.
#include <stdio.h> #include <stdlib.h> #include <string.h> int u[500005],v[500005],w[500005],first[
500005],NEXT[500005],BAR[500005],F[500005],D[500005],VIS[500005];
int pre[500005],link[500005],sta[500005],sccno[500005],q[500005];
int clo=0,top=0;
void find (int x) {int i,y;
Pre[x]=link[x]=++clo;
Sta[++top]=x;
for (I=first[x];i!=0;i=next[i]) if (sccno[v[i]]==0) {if (pre[v[i]]==0) find (V[i]);
if (Link[x]>link[v[i]]) link[x]=link[v[i]];
} if (Pre[x]==link[x]) {while (sta[top]!=x) sccno[sta[top--]]=x;
Sccno[sta[top--]]=x;
}} void Dfs (int x) {int i;
Vis[x]=1;
for (I=first[x];i!=0;i=next[i]) if (vis[v[i]]==0) DFS (V[i]);
} int main () {int n,m,s,p,i,head=0,tail=0,max=0;
scanf ("%d%d", &n,&m);
for (i=1;i<=m;i++) {scanf ("%d%d", &u[i],&v[i]);
Next[i]=first[u[i]];
First[u[i]]=i;
} for (i=1;i<=n;i++) scanf ("%d", &w[i]);
scanf ("%d%d", &s,&p);
for (i=1;i<=p;i++) scanf ("%d", &bar[i]);
for (i=1;i<=n;i++) if (sccno[i]==0) find (i);//Compute strong connected Component memset (first,0,sizeof (first));
memset (Next,0,sizeof (next));
for (i=1;i<=m;i++)//indent {u[i]=sccno[u[i]];
V[i]=sccno[v[i]];
if (U[i]!=v[i]) {next[i]=first[u[i]];
First[u[i]]=i;
}} for (i=1;i<=n;i++) if (sccno[i]!=i) w[sccno[i]]+=w[i];
DFS (Sccno[s]);
for (i=1;i<=m;i++) if (u[i]!=v[i]&&vis[u[i]]==1) f[v[i]]++;
Q[tail++]=sccno[s];
while (Head<tail) {D[q[head]]+=w[q[head]];
for (I=first[q[head]];i!=0;i=next[i]) {if (D[v[i]]<d[u[i]) d[v[i]]=d[u[i]];
f[v[i]]--;
if (f[v[i]]==0) q[tail++]=v[i];
} head++;
} for (i=1;i<=p;i++) if (Max<d[sccno[bar[i]]) max=d[sccno[bar[i]];
printf ("%d", max);
return 0; }