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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
#include <iostream>
#include <vector>
#include <queue>
#include <functional>
#include <algorithm>
#include <cstring>
#include <set>
#define MAXX 1001
#define INF 987654321
using namespace std;
typedef pair<int, int> pp;
vector<pp> edges[MAXX];
priority_queue<int> cost[MAXX];
bool visited[MAXX];
int res[101][1001];
void dijkstra(int k) {
priority_queue<pp, vector<pp>, greater<pp> > pq;
cost[1].push(0);
pq.pop();
for (auto i : edges[now]) {
int n_cost = i.first;
int next = i.second;
if (cost[next].size() < k) {
cost[next].push(n_cost + c_cost);
pq.push(pp(n_cost + c_cost, next));
}
else {
if (cost[next].top() > n_cost + c_cost) {
cost[next].pop();
cost[next].push(n_cost + c_cost);
pq.push(pp(n_cost + c_cost, next));
}
}
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m, k;
cin >> n >> m >> k;
//for (int i = 1; i <= n; i++) cost[i] = INF;
while (m--) {
int a, b, c;
cin >> a >> b >> c;
edges[a].push_back(pp(c, b));
}
//각 도시별로 pq를 돌린다.
dijkstra(k);
for (int i = 1; i <= n; i++) {
if (cost[i].size() < k) cout << -1 << '\n';
else {
cout << cost[i].top() << '\n';
}
}
return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
BOJ/C++