关注
求问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 评论
相关推荐
点赞 评论 收藏
分享
点赞 评论 收藏
分享
牛客热帖
更多
- 1... 27届 两进字节!!从计算机小白开始的打怪升级之路!!1.6W
- 2... 27 届前端鼠鼠拿下 3 家大厂 OC,拒 6 面的上岸攻略9274
- 3... 字节即将LastDay以及大模型应用开发看法7659
- 4... 大家的简历放照片吗?5756
- 5... 临近暑期实习但技术简历还没写好?大厂学长教你怎么写5691
- 6... 请问, 腾讯云智是大厂吗?4637
- 7... 正在实习的你一定要知道的几件事4139
- 8... 开个答疑贴,3年前端,知无不言3804
- 9... 和女朋友双双进入字节!3804
- 10... 史上最细SQL实战系列:基础知识篇2981
正在热议
更多
# 你找实习最大的坎坷是什么 #
24572次浏览 307人参与
# 蔚来工作体验 #
17935次浏览 68人参与
# 实习最想跑路的瞬间 #
17862次浏览 137人参与
# 如果可以,你希望哪个公司来捞你 #
91392次浏览 383人参与
# 我的职场心眼子段位 #
16508次浏览 450人参与
# 机械/汽车制造公司爆料 #
40256次浏览 208人参与
# 比亚迪精密制造工作体验 #
19744次浏览 39人参与
# 比亚迪工作体验 #
58365次浏览 235人参与
# 机械制造公司评价 #
118063次浏览 302人参与
# 理想汽车工作体验 #
30562次浏览 274人参与
# 对妈妈没说出口的话 #
45043次浏览 761人参与
# 大疆今年的机械笔试难吗? #
40993次浏览 452人参与
# 机械制造2023笔面经 #
118638次浏览 756人参与
# 春招别灰心,我们一人来一句鼓励 #
113133次浏览 1295人参与
# 秋招投简历越早越好吗 #
66454次浏览 630人参与
# 这些公司卡简历很严格 #
37995次浏览 190人参与
# 职业发展规划如何回答 #
37980次浏览 236人参与
# 我的求职精神状态 #
90994次浏览 1051人参与
# 市场营销人求职交流聚集地 #
120801次浏览 1089人参与
# 机械人,你被简历秒挂的企业有哪些? #
41091次浏览 275人参与