多做题呀,不能光看书!学车好浪费时间~~~下午的也不能参加了。。
#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;
}