求问D为什么建返图就会WA,建正图才能AC。 正图代码 #include<iostream> #include<cstdio> #include<algorithm> #include<cmath> #include<set> #include<map> #include<queue> #include<stack> #include<vector> #include<cstring> #include<cstdlib> #include<iomanip> #include<ctime> #include<string> #include<bitset> #define D(x) cout<<#x<<" = "<<x<<"  " #define E cout<<endl using namespace std; typedef long long ll; typedef pair<int,int>pii; const int maxn=100000+5; const int maxm=200000+5; const int INF=0x3f3f3f3f; const ll mod=20010905; int n,m; int head[maxn],tot=1; int in[maxn]; ll d[maxn]; queue<int>q; struct node{ int from,to,c; }edge[maxm]; void add(int from,int to){ edge[++tot].from=head[from],head[from]=tot,edge[tot].to=to; } void dp(){ d[1]=1; q.push(1); while(q.size()){ int x=q.front();q.pop(); for(int i=head[x];i;i=edge[i].from){ int y=edge[i].to; d[y]=(d[y]+d[x])%mod; if(--in[y]==0){ q.push(y); } } } printf("%lld",d[n]%mod); } int main() { // ios::sync_with_stdio(false); freopen("DDoS.in","r",stdin); scanf("%d%d",&n,&m); int from,to,c; for(int i=1;i<=m;i++){ scanf("%d%d%d",&from,&to,&c); add(from,to);  in[to]++; } dp(); return 0; } 反图代码 #include<iostream> #include<cstdio> #include<algorithm> #include<cmath> #include<set> #include<map> #include<queue> #include<stack> #include<vector> #include<cstring> #include<cstdlib> #include<iomanip> #include<ctime> #include<string> #include<bitset> #define D(x) cout<<#x<<" = "<<x<<"  " #define E cout<<endl using namespace std; typedef long long ll; typedef pair<int,int>pii; const int maxn=100000+5; const int maxm=200000+5; const int INF=0x3f3f3f3f; const ll mod=20010905; int n,m; int head[maxn],tot=1; int in[maxn]; ll d[maxn]; queue<int>q; struct node{ int from,to,c; }edge[maxm]; void add(int from,int to){ edge[++tot].from=head[from],head[from]=tot,edge[tot].to=to; } void dp(){ d[n]=1; q.push(n); while(q.size()){ int x=q.front();q.pop(); for(int i=head[x];i;i=edge[i].from){ int y=edge[i].to; d[y]=(d[y]+d[x])%mod; if(--in[y]==0){ q.push(y); } } } printf("%lld",d[1]%mod); } int main() { // ios::sync_with_stdio(false); // freopen("DDoS.in","r",stdin); scanf("%d%d",&n,&m); int from,to,c; for(int i=1;i<=m;i++){ scanf("%d%d%d",&from,&to,&c); add(to,from); //反图  in[from]++; } dp(); return 0; }

相关推荐

牛客网
牛客企业服务