关注
求问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 评论
相关推荐
05-21 22:02
宝鸡文理学院 Java 点赞 评论 收藏
分享
牛客热帖
更多
- 1... 🌟择难路,未有疑,四非学院本运气拉满,春招拿下大厂后端3.1W
- 2... 腾讯csig暑期一二三面7205
- 3... 史上最细SQL实战系列:sql笔试例题总结篇(建议收藏)6859
- 4... 腾讯云智后台开发暑期面经4420
- 5... 其实主包早就找到工作了,但还是每天都刷3502
- 6... 作为实习生,我问薪无愧3086
- 7... 字节拒绝、百度毁约,7.1 腾讯 Offer 到手:25 届双非碎碎念(25届最晚Offer)2993
- 8... 字节实习week6:听leader吐槽当前的应届生候选人们2798
- 9... 没实习 == 秋招凉?2728
- 10... 离开软件测试才发现外面没有雨2683
正在热议
更多
# 应届生,你找到工作了吗 #
1099次浏览 15人参与
# 双非应该如何逆袭? #
171415次浏览 2839人参与
# 现代汽车前瞻技术研发急速编程挑战赛 #
37224次浏览 271人参与
# 简历当中有水分算不算造假? #
1394次浏览 20人参与
# 春招进度记录 #
339274次浏览 3123人参与
# 实习生的蛐蛐区 #
745次浏览 19人参与
# 三一集团提前批进度交流 #
21864次浏览 138人参与
# 谈薪时HR压价该怎么应对 #
205350次浏览 3174人参与
# 毕业旅行去哪玩儿 #
7428次浏览 121人参与
# 非技术岗投递进展 #
144086次浏览 1264人参与
# 百度工作体验 #
228668次浏览 2002人参与
# 材料进Fab厂真的劝退吗? #
42880次浏览 184人参与
# 机械人与华为的爱恨情仇 #
118288次浏览 951人参与
# 没有合适的工作,你会先找个干着,还是考公考研 #
115730次浏览 1133人参与
# 百度秋招提前批进度 #
104755次浏览 1119人参与
# 双非有机会进大厂吗 #
431977次浏览 4285人参与
# 上班到公司第一件事做什么? #
59752次浏览 513人参与
# 秋招盘点:机械人值得去的企业 #
71623次浏览 670人参与
# 平台or薪资 硬件uu更看重哪个 #
128353次浏览 595人参与
# 工作中,努力重要还是选择重要? #
139140次浏览 1696人参与
# 发工资后,你做的第一件事是什么 #
69080次浏览 232人参与