Occurs with issues such as DP on the DAG.
using namespace Std;const int maxe = 300010;const int MAXP = 100010;struct n{int v,next;} Edge[maxe];int head[maxp];int top;int ty[maxp];int high[maxp];int lowlink[maxp];int SCCans,dfsclock;int S[MAXP],STop; void Initgraph () {Sccans = Dfsclock = 0; memset (high,0,sizeof (high)); memset (ty,0,sizeof (Ty)); memset (head,-1,sizeof (head)); Top = 0; STop = 0;} void Link (int u,int v) {edge[top].next = Head[u]; EDGE[TOP].V = v; Head[u] = top++;} void Dfs (int s) {High[s] = lowlink[s] = ++dfsclock; s[stop++] = s; int i,v; for (i = head[s]; I! =-1; i = edge[i].next) {v = edge[i].v; if (high[v] = = 0) {dfs (v); Lowlink[s] = min (lowlink[s],lowlink[v]); } else if (ty[v] = = 0) {Lowlink[s] = min (lowlink[s],lowlink[v]); }} if (lowlink[s] = = High[s]) {sccans++; do {v = s[--stop]; TY[V] = Sccans; }while (s! = v); }}vector<int> Vec[maxp];int Main () {int n,m,u,v,i,j; while (scanf ("%d%d", &n,&m)! = EOF) {initgraph (); while (m--) {scanf ("%d%d", &u,&v); Link (U,V); } for (i = 1;i <= n; ++i) if (ty[i] = = 0) dfs (i); for (i = 1;i <= sccans; ++i) vec[i].clear (); for (i = 1;i <= N, ++i) {for (j = head[i];j! = -1;j = Edge[j].next) {if (ty[ I] = ty[edge[j].v]) vec[ty[i]].push_back (TY[EDGE[J].V]); }}} return 0;}
The strong Unicom component Tarjan of the graph