amxxxxx @ 2022-11-24 12:49:23
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=2e5+10;
int n,m,st,dis[N],vis[N];
vector<pair<int,int> >G[N];
priority_queue<int,vector<pair<int, int> >,greater<pair<int,int> > > qu;
inline int read(){
int x=0;
bool f=true;
char ch=getchar();
for(;!isdigit(ch);ch=getchar())
if(ch=='-')f=false;
for(;isdigit(ch);ch=getchar())
x=(x<<1)+(x<<3)+ch-'0';
return f?x:~(x-1);
}
void dfs(){
for(int i=1;i<=n;i++)dis[i]=INT_MAX;
dis[st]=0;
qu.push(make_pair(0,st));
while(!qu.empty()){
pair<int,int>u=qu.top();
int id=u.second;
qu.pop();
if(vis[id])continue;
vis[id]=1;
for(auto i : G[id]){
int v=i.first;
int val=i.second;
if(dis[v]>dis[id]+val){
dis[v]=dis[id]+val;
if(!vis[v])qu.push(make_pair(dis[v],v));
}
}
}
}
signed main(){
n=read(),m=read(),st=read();
for(int i=1;i<=n;i++){
int u,v,w;
u=read(),v=read(),w=read();
G[u].push_back(make_pair(v,w));
}
dfs();
for(int i=1;i<=n;i++){
printf("%lld ",dis[i]);
}
system("pause");
return 0;
}
by amxxxxx @ 2022-11-24 13:15:31
输入错了,全麻,n改成m,此贴完结