rt,弱化版甚至只过了#1
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <queue>
#include <sstream>
using namespace std;
typedef long long LL;
const LL INF = 2147483647;
const int maxn = 1e5 + 5;;
bool vis[maxn];
LL dist[maxn];
vector<pair<int, LL>> adj[maxn];
struct Node {
int idx;
LL d;
Node(int _idx, LL _d) :idx(_idx), d(_d) {}
bool operator<(const Node& n)const {
return d > n.d;
}
};
int main() {
int N, M, S;
scanf("%d %d %d", &N, &M, &S);
for (int i = 1; i <= N; i++) {
dist[i] = INF;
}
dist[S] = 0;
while (M--) {
int v1, v2;
LL cost;
scanf("%d %d %lld", &v1, &v2, &cost);
adj[v1].push_back(make_pair(v2, cost));
}
priority_queue<Node> pq;
pq.push(Node(S, 0));
while (!pq.empty()) {
const Node& n = pq.top();
int v = n.idx;
pq.pop();
if (vis[n.idx]) continue;
vis[v] = true;
for (int i = 0; i < adj[v].size();i++) {
int w = adj[v][i].first;
LL cvw = adj[v][i].second;
if (vis[w]) continue;
if (dist[v] + cvw < dist[w]) {
dist[w] = dist[v] + cvw;
pq.push(Node(w, dist[w]));
}
}
}
for (int i = 1; i <= N; i++) {
if (i != 1) printf(" ");
printf("%lld", dist[i]);
}
return 0;
}