求问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; }

相关推荐

10-17 09:06
门头沟学院 Java
8527睿:有些地方感觉不太契合实际啊。简单看看第二个项目那里。 比如canal流式读取数据库日志进行缓存同步那里。可不可以加个消息中间件来确保SQL语句的削峰填谷。一般都是canal+消息中间件 双层鉴权登录那里,描述有点模糊,登录是鉴权的前提唉,后面功能都在说是登录,鉴权没有啊
点赞 评论 收藏
分享
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务