关注
求问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 评论
相关推荐
牛客热帖
更多
正在热议
更多
# 为了去实习,我赌上了___ #
8057次浏览 85人参与
# 2025年终总结 #
1784次浏览 44人参与
# 哪一瞬间让你觉得“这班不如不上” #
4352次浏览 76人参与
# 父母对你找工作是助力还是阻力? #
6094次浏览 125人参与
# 十二月请对我好一点 #
14493次浏览 229人参与
# 工作前VS工作后,你的心态变化 #
6979次浏览 91人参与
# 一人推荐一个值得做的项目 #
4875次浏览 84人参与
# 滴滴工作体验 #
35325次浏览 145人参与
# uu们,春招你还来吗? #
3515次浏览 37人参与
# 高薪高压 vs 低薪wlb,你怎么选? #
5383次浏览 58人参与
# 工作中出现了XX情况正常吗 #
17227次浏览 153人参与
# 得物app工作体验 #
39413次浏览 97人参与
# 你的实习什么时候入职 #
321463次浏览 2170人参与
# bilibili求职进展汇总 #
173563次浏览 1069人参与
# 产品实习,你更倾向大公司or小公司 #
184722次浏览 2040人参与
# 秋招有哪些公司要求提前实习 #
91846次浏览 493人参与
# 公司福利里最没用的一项是啥 #
3577次浏览 70人参与
# 你面试被问到过哪些不会的问题? #
103598次浏览 1859人参与
# 回顾今年你干过的最“勇”的一件事 #
7350次浏览 109人参与
# 被AI治愈的瞬间 #
82330次浏览 674人参与
查看12道真题和解析