//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.3Tarjan",
        "body": [
            "#include<cstring>",
            "#include<cstdio>",
            "#include<queue>",
            "#define Re register int",
            "const int N=1e4+3,M=1e5+3;",
            "int n,m,x,y,Q_o,ans,A[N],ru[N],gs[N],ip[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 min(Re a,Re b){return a<b?a:b;}",
            "inline int max(Re a,Re b){return a>b?a:b;}",
            "struct Tarjan{",
            "\tint o,t,dfn_o,Q[N],low[N],dfn[N],pan[N],head[N];",
            "\tstruct QAQ{int x,to,next;}a[M];",
            "\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 tarjan(Re x){",
            "\t\tdfn[x]=low[x]=++dfn_o,Q[++t]=x,pan[x]=1;",
            "\t\tfor(Re i=head[x],to;i;i=a[i].next)",
            "\t\t\tif(!dfn[to=a[i].to])tarjan(to),low[x]=min(low[x],low[to]);",
            "\t\t\telse if(pan[to])low[x]=min(low[x],dfn[to]);",
            "\t\tif(low[x]==dfn[x]){",
            "\t\t\t++Q_o;",
            "\t\t\twhile(1){",
            "\t\t\t\tip[Q[t]]=Q_o,gs[Q_o]+=A[Q[t]],pan[Q[t]]=0;",
            "\t\t\t\tif(x==Q[t--])break;",
            "\t\t\t}",
            "\t\t}",
            "\t}",
            "\tinline void SuoPoint(){for(Re i=1;i<=n;++i)if(!dfn[i])tarjan(i);}",
            "}T1;",
            "struct Tuopu{",
            "\tint o,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\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]);",
            "\twhile(m--)in(x),in(y),T1.add(x,y);",
            "\tT1.SuoPoint(),T2.creat(),T2.tuopu();",
            "\tfor(Re i=1;i<=Q_o;++i)ans=max(ans,dp[i]);",
            "\tprintf(\"%d\",ans);",
            "}",
            ""
        ],
        "description": "插入 缩点—强联通分量"
    }
}