-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ_10282.cpp
More file actions
46 lines (44 loc) · 1.04 KB
/
BOJ_10282.cpp
File metadata and controls
46 lines (44 loc) · 1.04 KB
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
#include <bits/stdc++.h>
using namespace std;
const int INF = 987654321;
int t, n, d, c, a, b, s, ans[10002], retA, retB;
vector<pair<int, int>> adj[10002];
int main() {
cin >> t;
while (t--) {
retA = 0;
retB = 0;
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
fill(ans, ans + 10002, INF);
cin >> n >> d >> c;
for (int i = 0; i < d; i++) {
cin >> a >> b >> s;
adj[b].push_back({ s, a });
}
pq.push({ 0, c });
ans[c] = 0;
while (pq.size()) {
int here = pq.top().second;
int here_dist = pq.top().first;
pq.pop();
if (ans[here] != here_dist) continue;
for (auto there : adj[here]) {
int _dist = there.first;
int _there = there.second;
if (ans[_there] > _dist + ans[here]) {
ans[_there] = _dist + ans[here];
pq.push({ ans[_there], _there });
}
}
}
for (int i = 1; i <= n; i++) {
if (ans[i] != INF) {
retA++;
retB = max(retB, ans[i]);
}
}
cout << retA << " " << retB << "\n";
for (int i = 1; i <= n; i++) adj[i].clear();
}
return 0;
}