关注
求问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;
}
查看原帖
1 评论
相关推荐
点赞 评论 收藏
分享
点赞 评论 收藏
分享
牛客热帖
更多
正在热议
更多
# 你实习是赚钱了还是亏钱了? #
30479次浏览 241人参与
# 2022毕业即失业取暖地 #
116578次浏览 705人参与
# 360集团校招 #
21859次浏览 164人参与
# 用一句话形容你的团队氛围 #
18588次浏览 179人参与
# CVTE求职进展汇总 #
23135次浏览 319人参与
# 你找工作是从容有余 or 匆忙滚爬? #
12118次浏览 94人参与
# 联影求职进展汇总 #
51363次浏览 325人参与
# 哪些公司校招卡第一学历 #
220334次浏览 776人参与
# 牛客租房专区 #
122965次浏览 1347人参与
# 机械人与华为的爱恨情仇 #
137423次浏览 1012人参与
# 海康威视工作体验 #
45729次浏览 157人参与
# 腾讯音乐求职进展汇总 #
136166次浏览 1005人参与
# 嵌入式岗知多少 #
58807次浏览 548人参与
# 联影医疗求职进展汇总 #
6212次浏览 25人参与
# 毕业论文进行时 #
6851次浏览 81人参与
# 同bg的你秋招战况如何? #
174768次浏览 1021人参与
# 找实习你看重大厂光环还是业务方向 #
41604次浏览 164人参与
# 58同城求职进展汇总 #
40279次浏览 263人参与
# 我来点评面试官 #
16663次浏览 114人参与
# 面对逼签的应对技巧 #
7200次浏览 37人参与
# 扒一扒那些奇葩实习经历 #
126852次浏览 1100人参与
