关注
求问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 评论
相关推荐
牛客热帖
更多
正在热议
更多
# 秋招什么时候开投比较合适? #
23701次浏览 318人参与
# 百度工作体验 #
223389次浏览 1972人参与
# 现代汽车前瞻技术研发急速编程挑战赛 #
27960次浏览 216人参与
# 机械人与华为的爱恨情仇 #
117155次浏览 946人参与
# 发工资后,你做的第一件事是什么 #
68154次浏览 229人参与
# 机械人集合!你是什么工程师? #
15805次浏览 89人参与
# 你觉得实习能学到东西吗 #
36307次浏览 712人参与
# 找不到好工作选择GAP真的丢人吗 #
78265次浏览 938人参与
# 我想去国央企的原因 #
59993次浏览 393人参与
# 如何准备秋招 #
20667次浏览 390人参与
# 工作中哪个瞬间让你想离职 #
25909次浏览 177人参与
# 入职第四天,心情怎么样 #
29451次浏览 417人参与
# 拼多多工作体验 #
28540次浏览 197人参与
# 多益网络求职进展汇总 #
29228次浏览 134人参与
# 快手求职进展汇总 #
547098次浏览 6001人参与
# 硬件应届生薪资是否普遍偏低? #
74083次浏览 514人参与
# 不考虑转正,实习多久合适 #
32324次浏览 145人参与
# 面试中,你被问过哪些奇葩问题? #
68553次浏览 796人参与
# 你们公司几号发工资 #
21227次浏览 140人参与
# 如果再来一次,你还会学硬件吗 #
125786次浏览 1402人参与
# 实习,不懂就问 #
46386次浏览 693人参与