牛客小白月赛21 D 菜逼wxy

 

 

多做题呀,不能光看书!学车好浪费时间~~~下午的也不能参加了。。

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <queue>
#include <iostream>
using namespace std;
const int maxn = 100000 + 10;
const int maxm = 200000 + 10;
const int mod = 20010905;
struct Edge
{
    int before;
    int to;
    int w;
} e[maxm];
int n, m, k, head[maxn], dp[maxn], in[maxn], vis[maxn];
void add(int u, int v, int w)
{
    e[k].to = v;
    e[k].w = w;
    e[k].before = head[u];
    head[u] = k++;
}
void topo()
{
    queue<int> q;
    q.push(1);
    dp[1] = 1;
    while (!q.empty())
    {
        int u = q.front();
        q.pop();
        vis[u] = 1;
        for (int i = head[u]; i != -1; i = e[i].before)
        {
            int v = e[i].to;
            in[v]--;
            dp[v] = (dp[v] + dp[u]) % mod;
            if (vis[v] == 0 && in[v] == 0)
            {
                q.push(v);
            }
        }
    }
    cout << dp[n] << endl;
}
int main()
{
#ifdef ONLINE_JUDGE
#else
    freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#endif
    scanf("%d %d", &n, &m);
    memset(head, -1, sizeof head);
    int u, v, w;
    for (int i = 0; i < m; i++)
    {
        scanf("%d %d %d", &u, &v, &w);
        add(u, v, w);
        in[v]++;
    }
    topo();
    return 0;
}
发布了59 篇原创文章 · 获赞 22 · 访问量 3839

猜你喜欢

转载自blog.csdn.net/qq_44115065/article/details/104038847