关注
求问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 评论
相关推荐
01-22 18:49
四川大学 Java 点赞 评论 收藏
分享
牛客热帖
更多
正在热议
更多
# 赚钱的意义在这一刻具象化 #
2813次浏览 69人参与
# 哪些瞬间让你真切感受到了工作的乐趣 #
23108次浏览 98人参与
# 今年春招是金一银二嘛? #
3795次浏览 50人参与
# AI求职实录 #
1905次浏览 59人参与
# 1月小结:你过的开心吗? #
925次浏览 30人参与
# 你的第一家实习公司是什么档次? #
2657次浏览 47人参与
# 抛开难度不谈,你最想去哪家公司? #
2115次浏览 63人参与
# 为什么有人零实习也能进大厂? #
3030次浏览 68人参与
# AI时代的工作 VS 传统时代的工作,有哪些不同? #
6069次浏览 140人参与
# 你的landing期是如何度过的? #
5848次浏览 98人参与
# 工作后会跟朋友渐行渐远吗 #
57698次浏览 411人参与
# 除了Java,最推荐学什么技术? #
4160次浏览 114人参与
# 当你问AI“你会取代我的工作吗”,它说_? #
2248次浏览 80人参与
# 汇川技术求职进展汇总 #
177650次浏览 1055人参与
# 我是XXX,请攻击我最薄弱的地方 #
55630次浏览 388人参与
# 选offer应该考虑哪些因素 #
139838次浏览 983人参与
# 你觉得什么岗位会被AI替代 #
36179次浏览 248人参与
# 如果工作一直消耗情绪还要继续做吗 #
18513次浏览 88人参与
# 你上一次加班是什么时候? #
128867次浏览 737人参与
# 非技术岗简历怎么写 #
284103次浏览 3185人参与

字节跳动公司福利 1359人发布
查看4道真题和解析