关注
求问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 评论
相关推荐
点赞 评论 收藏
分享
点赞 评论 收藏
分享
10-15 16:40
河南科技大学 Java 点赞 评论 收藏
分享
牛客热帖
更多
正在热议
更多
# 十二月请对我好一点 #
8651次浏览 157人参与
# 父母对你找工作是助力还是阻力? #
3195次浏览 70人参与
# 为了去实习,我赌上了___ #
3090次浏览 41人参与
# 聊聊我眼中的AI #
486099次浏览 6733人参与
# 工作中出现了XX情况正常吗 #
10102次浏览 116人参与
# 哪一瞬间让你觉得“这班不如不上” #
2348次浏览 23人参与
# 一人推荐一个值得做的项目 #
3306次浏览 52人参与
# uu们,春招你还来吗? #
2304次浏览 25人参与
# 高薪高压 vs 低薪wlb,你怎么选? #
3936次浏览 42人参与
# 回顾今年你干过的最“勇”的一件事 #
4939次浏览 73人参与
# 工作前VS工作后,你的心态变化 #
4211次浏览 34人参与
# 秋招有哪些公司要求提前实习 #
91218次浏览 488人参与
# 公司福利里最没用的一项是啥 #
2700次浏览 56人参与
# 机械人的金三校招总结 #
39004次浏览 465人参与
# 如何用一句话描述你的职业 #
28095次浏览 181人参与
# 追觅科技求职进展汇总 #
29016次浏览 181人参与
# 职场上哪些事情令人讨厌 #
32506次浏览 143人参与
# 机械人的薪资开到多少,才适合去? #
150965次浏览 530人参与
# 你收到了团子的OC了吗 #
1469665次浏览 11805人参与
# 毕业季,给职场新人一些建议 #
162193次浏览 2367人参与