//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.3add",
        "body": [
            "#include<cstring>",
            "#include<cstdio>",
            "#include<queue>",
            "#define Re register int",
            "using namespace std;",
            "const int N=5003,M=5e5+3,inf=2e9,P=80112002;",
            "int n,m,x,y,o,ans,dp[N],ru[N],chu[N],head[N];",
            "struct QAQ{int to,next;}a[M];queue<int>Q;",
            "inline void add(Re x,Re y){a[++o].to=y,a[o].next=head[x],head[x]=o;}",
            "inline void in(Re &x){",
            "\tRe fu=0;x=0;char ch=getchar();",
            "\twhile(ch<'0'||ch>'9')fu|=ch=='-',ch=getchar();",
            "\twhile(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();",
            "\tx=fu?-x:x;",
            "}",
            "",
            "int main(){",
            "\tin(n),in(m);",
            "\twhile(m--)in(x),in(y),add(x,y),++ru[y],++chu[x];",
            "\tfor(Re i=1;i<=n;++i)if(!ru[i])dp[i]=1,Q.push(i);",
            "\twhile(!Q.empty()){",
            "\t\tRe x=Q.front();Q.pop();",
            "\t\tfor(Re i=head[x],to;i;i=a[i].next){",
            "\t\t\t(dp[to=a[i].to]+=dp[x])%=P;",
            "\t\t\tif(!--ru[to])Q.push(to);",
            "\t\t}",
            "\t}",
            "\tfor(Re i=1;i<=n;++i)if(!chu[i])(ans+=dp[i])%=P;",
            "\tprintf(\"%d\\n\",ans%P);",
            "}",
            ""
        ],
        "description": "插入 拓扑排序"
    }
}