//Place your snippets for cpp here. Each snippet is defined under a snippet name and has a prefix, body and 
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the 
// same ids are connected.
// prefix 的格式要求是 acm-[一级标题编号].[二级标题编号][该代码片段的英文简称]
// description 的格式要求是 "插入 [该代码片段的中文名]"

{
    "缩点—强联通分量": {
        "prefix": "acm-3.3Kosaraju",
        "body": [
            "#include<cstring>",
            "#include<cstdio>",
            "#include<queue>",
            "#define Re register int",
            "const int N=1e6+3,M=1e6+3;",
            "int n,m,Q_o,ans,X[M],Y[M],A[N],ip[N],gs[N],dp[N];",
            "inline void in(Re &x){",
            "    int f=0;x=0;char c=getchar();",
            "    while(c<'0'||c>'9')f|=c=='-',c=getchar();",
            "    while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();",
            "    x=f?-x:x;",
            "}",
            "inline int max(Re a,Re b){return a>b?a:b;}",
            "struct Kosaraju{",
            "\tint o,ndfn_o,nQ[N],pan[N],head[N];",
            "\tstruct QAQ{int x,to,next;}a[M<<1];",
            "\tinline void add(Re x,Re y){a[++o].x=x,a[o].to=y,a[o].next=head[x],head[x]=o;}",
            "\tinline void dfs1(Re x){",
            "\t\tpan[x]=1;",
            "\t\tfor(Re i=head[x];i;i=a[i].next)if(!pan[a[i].to])dfs1(a[i].to);",
            "\t\tnQ[++ndfn_o]=x;",
            "\t}",
            "\tinline void dfs2(Re x){",
            "\t\tip[x]=Q_o,gs[Q_o]+=A[x];",
            "\t\tfor(Re i=head[x];i;i=a[i].next)if(!ip[a[i].to])dfs2(a[i].to);",
            "\t}",
            "\tinline void kosaraju(){",
            "\t\tfor(Re i=1;i<=m;++i)add(X[i],Y[i]);",
            "\t\tfor(Re i=1;i<=n;++i)if(!pan[i])dfs1(i);",
            "\t\tmemset(head,0,sizeof(head));",
            "\t\tmemset(pan,0,sizeof(pan));",
            "\t\tmemset(a,0,sizeof(a));o=0;",
            "\t\tfor(Re i=1;i<=m;++i)add(Y[i],X[i]);",
            "\t\tfor(Re i=ndfn_o;i;--i)if(!ip[nQ[i]])++Q_o,dfs2(nQ[i]);",
            "\t}",
            "}T1;",
            "struct Tuopu{",
            "\tint o,x,y,ru[N],pan[N],head[N];std::queue<int>Q;",
            "\tstruct QAQ{int to,next;}a[M<<1];",
            "\tinline void add(Re x,Re y){a[++o].to=y,a[o].next=head[x],head[x]=o;}",
            "\tinline void creat(){",
            "\t\tfor(Re i=1;i<=T1.o;++i)",
            "\t\t\tif((x=ip[T1.a[i].x])!=(y=ip[T1.a[i].to]))",
            "\t\t\t\t++ru[y],add(x,y);",
            "\t}",
            "\tinline void tuopu(){",
            "\t\tcreat();",
            "\t\tfor(Re i=1;i<=Q_o;++i)if(!ru[i])dp[i]=gs[i],Q.push(i);",
            "\t\twhile(!Q.empty()){",
            "\t\t\tRe x=Q.front();Q.pop();",
            "\t\t\tfor(Re i=head[x],to;i;i=a[i].next){",
            "\t\t\t\tto=a[i].to;",
            "\t\t\t\tdp[to]=max(dp[to],dp[x]+gs[to]);",
            "\t\t\t\tif(!(--ru[to]))Q.push(to);",
            "\t\t\t}",
            "\t\t}",
            "\t}",
            "}T2;",
            "int main(){",
            "\tin(n),in(m);",
            "\tfor(Re i=1;i<=n;++i)in(A[i]);",
            "\tfor(Re i=1;i<=m;++i)in(X[i]),in(Y[i]);",
            "\tT1.kosaraju(),T2.tuopu();",
            "\tfor(Re i=1;i<=Q_o;++i)ans=max(ans,dp[i]);",
            "\tprintf(\"%d\",ans);",
            "}",
            ""
        ],
        "description": "插入 缩点—强联通分量"
    }
}