关注
求问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 评论
相关推荐
牛客78099800...:实习现在还不捞26届的啊,我投了很多,没有进流程的,以为是在搞秋招,但意外发现大三的不少都面实习了 点赞 评论 收藏
分享
10-30 09:48
太原理工大学 Java 点赞 评论 收藏
分享
牛客热帖
更多
- 1... 2025的主旋律是蛰伏,落寞,遗憾1.1W
- 2... 杂记近期所面试的三家中小厂9100
- 3... 圣诞节用 AI 做个牛客运营翻翻乐!(含代码)6067
- 4... 选择即命运—2025年度总结4919
- 5... 大学废物离开优绩主义之后发现外面根本没下雨4667
- 6... 从H200解禁评估:国资算力平台还值得应届就业吗?4184
- 7... 我只是一个脆弱的人3100
- 8... 实习没事做是福也是祸3033
- 9... 互联网实习求职的黑话和timeline,你所需要知道的……2912
- 10... 壕壕壕,京东发7个月年终,此生要做东孝子2723
正在热议
更多
# 2025年终总结 #
172821次浏览 2921人参与
# 找工作,行业重要还是岗位重要? #
85311次浏览 1688人参与
# 职场上哪些行为很加分? #
306914次浏览 3452人参与
# 大家每天通勤多久? #
69800次浏览 442人参与
# 实习的内耗时刻 #
211177次浏览 1539人参与
# 你面试体验感最差/最好的公司 #
17781次浏览 292人参与
# 一人说一个提前实习的好处 #
10719次浏览 204人参与
# 今年你最想重开的一场面试是? #
4080次浏览 69人参与
# 秋招落幕,你是He or Be #
12131次浏览 238人参与
# 互联网行业现在还值得去吗 #
46915次浏览 351人参与
# 实习没事做是福还是祸? #
16740次浏览 255人参与
# 面试吐槽bot #
165003次浏览 814人参与
# 重来一次,你会对开始求职的自己说 #
6076次浏览 154人参与
# 反问环节如何提问 #
126374次浏览 2663人参与
# 礼物开箱Plog #
676次浏览 24人参与
# 工作中听到最受打击的一句话 #
6608次浏览 113人参与
# 团建是“福利”还是是 “渡劫” #
7180次浏览 150人参与
# 我的第一份实习怎么找的 #
208550次浏览 1827人参与
# 比亚迪工作体验 #
74722次浏览 281人参与
# 大家实习每天都在干啥 #
106526次浏览 581人参与