关注
求问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-17 09:06
门头沟学院 Java
8527睿:有些地方感觉不太契合实际啊。简单看看第二个项目那里。
比如canal流式读取数据库日志进行缓存同步那里。可不可以加个消息中间件来确保SQL语句的削峰填谷。一般都是canal+消息中间件
双层鉴权登录那里,描述有点模糊,登录是鉴权的前提唉,后面功能都在说是登录,鉴权没有啊 点赞 评论 收藏
分享
牛客热帖
更多
正在热议
更多
# uu们,春招你还来吗? #
14658次浏览 93人参与
# 2025年终总结 #
15072次浏览 233人参与
# 百融云创求职进展汇总 #
285次浏览 0人参与
# 哪一瞬间让你觉得“这班不如不上” #
13210次浏览 164人参与
# 第一份工作能做外包吗? #
87295次浏览 584人参与
# 工作前VS工作后,你的心态变化 #
15016次浏览 167人参与
# 为了去实习,我赌上了___ #
23148次浏览 209人参与
# 父母对你找工作是助力还是阻力? #
14671次浏览 210人参与
# 高薪高压 vs 低薪wlb,你怎么选? #
13458次浏览 147人参与
# 秋招暂停,我将对以下公司做出处罚__ #
42832次浏览 176人参与
# 硬件兄弟们 甩出你的华为奖状 #
117400次浏览 699人参与
# 一人推荐一个值得做的项目 #
10800次浏览 154人参与
# 十二月请对我好一点 #
26944次浏览 358人参与
# 学历or实习经历,哪个更重要 #
203127次浏览 1077人参与
# 运营来爆料 #
69307次浏览 443人参与
# 降低公积金和取消房补怎么选 #
23580次浏览 79人参与
# 晒一晒你收到的礼盒 #
88140次浏览 430人参与
# 面试紧张时你会有什么表现? #
16087次浏览 133人参与
# 大厂无回复,继续等待还是奔赴小厂 #
288984次浏览 1781人参与
# 工作中出现了XX情况正常吗 #
35620次浏览 225人参与
# 浅聊一下我实习的辛苦费 #
259252次浏览 1784人参与
查看16道真题和解析