关注
求问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 评论
相关推荐
03-13 14:39
门头沟学院 大数据开发工程师 点赞 评论 收藏
分享
查看4道真题和解析 点赞 评论 收藏
分享
牛客热帖
更多
正在热议
更多
# 你和你的mentor相处模式是__ #
3210次浏览 19人参与
# 如果公司降薪,你会跳槽吗? #
160165次浏览 938人参与
# 联宝杯大学生创新大赛,你的技术值得产业级答案 #
25980次浏览 320人参与
# 实习第一天,你在干什么 #
2140次浏览 14人参与
# 华为工作体验 #
322093次浏览 1409人参与
# 你会因为行情,降低找工作标准吗? #
2398次浏览 19人参与
# 非技术2024笔面经 #
501912次浏览 5038人参与
# 机械人与华为的爱恨情仇 #
158489次浏览 1055人参与
# 0offer互助地 #
773044次浏览 4756人参与
# 你是怎么和mt相处的? #
103025次浏览 507人参与
# 联想求职进展汇总 #
356392次浏览 2262人参与
# 运营人求职交流聚集地 #
247208次浏览 1124人参与
# 实习/项目/竞赛奖项,哪个对找工作更重要? #
113548次浏览 1196人参与
# 我的成功项目解析 #
531937次浏览 8611人参与
# 打工人的工作餐日常 #
97012次浏览 558人参与
# 26年哪些行业会变好/更差 #
66194次浏览 534人参与
# 蚂蚁求职进展汇总 #
170971次浏览 1291人参与
# 今年秋招还有金九银十吗 #
82769次浏览 514人参与
# 工作两年想退休了 #
271619次浏览 2048人参与
# 你总挂在第__面? #
14747次浏览 162人参与
# 简历上如何体现你的“AI”能力? #
20118次浏览 405人参与
