PRabbitdad @ 2023-08-01 22:06:00
#include<bits/stdc++.h>
#define int long long
typedef long long ll;
const int MAXN = 1e5 + 5;
const int MAXT = 2e5 + 5;
const int MAXM = 3e5 + 5;
const int MOD = 998244353;
using namespace std;
int dis[MAXN];
int n,m,s;
vector<pair<int,int> >G[MAXN];
void dijkstra(){
for(int i=0;i<MAXN;i++) dis[i] = INT_MAX;
priority_queue<int,vector<int>,greater<int> >q;
dis[s] = 0;
q.push(s);
while(q.size()){
int now = q.top();
q.pop();
for(int i=0;i<G[now].size();i++){
int u = G[now][i].first;
int d = G[now][i].second;
if(dis[u] > dis[now] + d){
dis[u] = dis[now] + d;
q.push(u);
}
}
}
return;
}
signed main(){
cin >> n >> m >> s;
for(int i=0;i<m;i++){
int u,v,w;
cin >> u >> v >> w;
G[u].push_back(make_pair(v,w));
G[v].push_back(make_pair(u,w));
}
dijkstra();
for(int i=1;i<=n;i++){
cout << dis[i] << " ";
}
return 0;
}
by PRabbitdad @ 2023-08-01 22:17:01
So跪求各位大佬哪里错了。。。。
by wzb13958817049 @ 2023-08-01 22:17:45
@Wf_yjqd 【恐慌】
by Wf_yjqd @ 2023-08-01 22:18:37
@GRATRABBIT 您甚至没有按距离排序啊,
by Wf_yjqd @ 2023-08-01 22:18:49
为啥要按编号排
by FL_sleake @ 2023-08-01 22:19:04
@GRATRABBIT 我觉得数据量蛮大的,然后去翻了一遍题解,要么scanf要么快读
by Wf_yjqd @ 2023-08-01 22:19:59
不是啊,您这 dijkstra 写错了啊
by wzb13958817049 @ 2023-08-01 22:20:22
@GRATRABBIT 应该push(dis[v])
by Wf_yjqd @ 2023-08-01 22:20:47
我没记错的话是堆里存个 pair 然后按 dis 排序吧。
by PRabbitdad @ 2023-08-01 22:21:00
@tuohao 少t了一个
by FL_sleake @ 2023-08-01 22:21:01
priority_queue的问题吧