[Link] https://www.acmicpc.net/problem/1854
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <stack>
// #include <bits/stdc++.h>
using namespace std;
#define for0(i, n) for(int i = 0; i < n; i++)
#define for1(i, n) for(int i = 1; i < n; i++)
#define fori(s, e) for(int i = s; i < e; i++)
#define ll long long
#define endl "\n"
#define nulls '\0'
#define dkdk " "
const int MAX = 5e5 + 1;
const int INF = 987654321;
int n, m, k;
vector<map<int, int>> time;
int update_cnt[1000];
int dijk[1000];
struct cmp {
bool operator()(pair<int, int> p1, pair<int, int> p2) {
return p1.first > p2.first;
}
};
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m >> k;
time.resize(n);
for0(i, m) {
int a, b, c; cin >> a >> b >> c;
a--, b--;
time[a][b] = c;
}
priority_queue<pair<int, int>, vector<pair<int,int>>, cmp> pq;
dijk[0] = 0;
pq.push({ 0, 0 });
while(!pq.empty()) {
pair<int,int> p = pq.top(); pq.pop();
int v = p.first, idx = p.second;
if(update_cnt[idx] >= k) continue;
update_cnt[idx]++;
dijk[idx] = v;
for(auto map_p: time[idx]) {
int dest = map_p.first, edge_val = map_p.second;
if(update_cnt[dest] >= k) continue;
pq.push({ v + edge_val, dest });
}
}
for0(i, n) {
if(update_cnt[i] < k) cout << -1 << endl;
else cout << dijk[i] << endl;
}
return 0;
}