关注
求问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... 工作半年后更确定:我们依然不欠优绩主义什么6104
- 2... 我建了一个分享实习业务的仓库,欢迎大家贡献哦3792
- 3... 岁末论道:谁才是牛客 2025 最强修仙者?3160
- 4... #牛客2025仙途报告#居然是五颗星2528
- 5... 腾讯 微信支付一面面经2517
- 6... 【2025-年终总结】25届毕业生果果牛这一年~2184
- 7... 仙途报告1964
- 8... 一个程序员的自救书|从酒吧陪玩DM到上岸大厂1918
- 9... 在当下这个社会,在人生这个无常的时代,我真心希望你和各位牛友开心1418
- 10... 壕壕壕,京东发7个月年终,此生要做东孝子1316
正在热议
更多
# 牛客2025仙途报告 #
15318次浏览 260人参与
# 实习要如何选择和准备? #
130380次浏览 1511人参与
# 元旦假期你打算怎么过 #
1180次浏览 39人参与
# 你有哪些缓解焦虑的方法? #
44657次浏览 868人参与
# 格力求职进展汇总 #
197834次浏览 1267人参与
# 实习没人带,苟住还是跑路? #
578次浏览 18人参与
# 上班后和你想的一样吗? #
95228次浏览 701人参与
# 双非本科的出路是什么? #
189531次浏览 1500人参与
# 找工作,行业重要还是岗位重要? #
87736次浏览 1752人参与
# 我们是不是被“优绩主义”绑架了? #
2071次浏览 73人参与
# 今年你最想重开的一场面试是? #
13804次浏览 146人参与
# 一人说一个提前实习的好处 #
24837次浏览 321人参与
# 机械人晒出你的简历 #
148581次浏览 886人参与
# vivo工作体验 #
35116次浏览 136人参与
# 你面试体验感最差/最好的公司 #
30245次浏览 498人参与
# 礼物开箱Plog #
3428次浏览 102人参与
# 牛友们的论文几号送审 #
63169次浏览 833人参与
# 秋招落幕,你是He or Be #
23385次浏览 396人参与
# 你觉得机械有必要实习吗? #
16426次浏览 95人参与
# 机械只有读研才有出路吗? #
30950次浏览 261人参与
