NC201607 DDoS

由于可以在任意时刻发送数据包,对于1到n的所有路径,尽管所用时间不同,可你完全可以通过调整他们的开始时间,使他们最后在同一时间到达。

故题目转换为求\(1\)~\(n\)的路径数目。规定了图为DAG,拓扑排序即可。

const int N=1e5+10;
vector<PII> g[N];
int din[N];
int f[N];
int n,m;

void topo()
{
    queue<int> q;
    q.push(1);
    f[1]=1;

    while(q.size())
    {
        int t=q.front();
        q.pop();

        for(int i=0;i<g[t].size();i++)
        {
            int j=g[t][i].fi;
            f[j]=(f[j]+f[t])%mod;
            if(--din[j] == 0) q.push(j);

        }
    }
}

int main()
{
    cin>>n>>m;

    while(m--)
    {
        int a,b,c;
        cin>>a>>b>>c;
        g[a].pb({b,c});
        din[b]++;
    }

    topo();

    cout<<f[n]<<endl;

    //system("pause");
}
原文地址:https://www.cnblogs.com/fxh0707/p/14081933.html