# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
140586 |
2019-08-03T15:58:36 Z |
khrbuddy03 |
None (KOI18_robot) |
C++14 |
|
395 ms |
25592 KB |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e5 + 9;
vector<pair<int, int>> tree[inf];
map<pair<int, int>, int> m;
int dist[inf];
int par[inf];
bool vis[inf];
void dfss(int here, int len) {
dist[here] = len;
for (auto i : tree[here]) {
int there = i.first;
int nlen = len + i.second;
if (dist[there] == -1) dfss(there, nlen);
}
}
void dfsm(int here) {
vis[here] = true;
for (auto i : tree[here]) {
if (vis[i.first]) continue;
dfsm(i.first);
par[i.first] = here;
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, x, y; cin >> n >> x >> y;
for (int i = 0; i < n - 1; i++) {
int a, b, c; cin >> a >> b >> c;
tree[a].emplace_back(b, c);
tree[b].emplace_back(a, c);
m[make_pair(a, b)] = c;
m[make_pair(b, a)] = c;
}
fill(&dist[1], &dist[n + 1], -1);
dfss(x, 0);
dfsm(x);
int here = y;
int mpath = 0;
while (here != x) {
mpath = max(mpath, m[make_pair(here, par[here])]);
here = par[here];
}
cout << dist[y] - mpath << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
154 ms |
25592 KB |
Output is correct |
2 |
Correct |
133 ms |
24396 KB |
Output is correct |
3 |
Correct |
136 ms |
22944 KB |
Output is correct |
4 |
Correct |
5 ms |
2936 KB |
Output is correct |
5 |
Correct |
17 ms |
5368 KB |
Output is correct |
6 |
Correct |
20 ms |
5880 KB |
Output is correct |
7 |
Correct |
4 ms |
2684 KB |
Output is correct |
8 |
Correct |
26 ms |
7160 KB |
Output is correct |
9 |
Correct |
6 ms |
3192 KB |
Output is correct |
10 |
Correct |
32 ms |
7800 KB |
Output is correct |
11 |
Correct |
4 ms |
2680 KB |
Output is correct |
12 |
Correct |
4 ms |
2680 KB |
Output is correct |
13 |
Correct |
39 ms |
9464 KB |
Output is correct |
14 |
Correct |
44 ms |
10616 KB |
Output is correct |
15 |
Correct |
7 ms |
3448 KB |
Output is correct |
16 |
Correct |
54 ms |
11768 KB |
Output is correct |
17 |
Correct |
68 ms |
13148 KB |
Output is correct |
18 |
Correct |
72 ms |
14328 KB |
Output is correct |
19 |
Correct |
10 ms |
4160 KB |
Output is correct |
20 |
Correct |
79 ms |
15864 KB |
Output is correct |
21 |
Correct |
97 ms |
17592 KB |
Output is correct |
22 |
Correct |
113 ms |
20728 KB |
Output is correct |
23 |
Correct |
13 ms |
4484 KB |
Output is correct |
24 |
Correct |
120 ms |
21440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
300 ms |
21872 KB |
Output is correct |
2 |
Correct |
129 ms |
22892 KB |
Output is correct |
3 |
Correct |
5 ms |
2936 KB |
Output is correct |
4 |
Correct |
5 ms |
2936 KB |
Output is correct |
5 |
Correct |
29 ms |
5752 KB |
Output is correct |
6 |
Correct |
20 ms |
5880 KB |
Output is correct |
7 |
Correct |
4 ms |
2680 KB |
Output is correct |
8 |
Correct |
32 ms |
7788 KB |
Output is correct |
9 |
Correct |
40 ms |
7440 KB |
Output is correct |
10 |
Correct |
4 ms |
2680 KB |
Output is correct |
11 |
Correct |
45 ms |
10616 KB |
Output is correct |
12 |
Correct |
70 ms |
9304 KB |
Output is correct |
13 |
Correct |
8 ms |
3416 KB |
Output is correct |
14 |
Correct |
8 ms |
3448 KB |
Output is correct |
15 |
Correct |
99 ms |
12024 KB |
Output is correct |
16 |
Correct |
63 ms |
13176 KB |
Output is correct |
17 |
Correct |
83 ms |
15964 KB |
Output is correct |
18 |
Correct |
121 ms |
14708 KB |
Output is correct |
19 |
Correct |
113 ms |
20728 KB |
Output is correct |
20 |
Correct |
222 ms |
17656 KB |
Output is correct |
21 |
Correct |
13 ms |
4600 KB |
Output is correct |
22 |
Correct |
16 ms |
4344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
2940 KB |
Output is correct |
2 |
Correct |
5 ms |
2812 KB |
Output is correct |
3 |
Correct |
6 ms |
2936 KB |
Output is correct |
4 |
Correct |
4 ms |
2680 KB |
Output is correct |
5 |
Correct |
6 ms |
3064 KB |
Output is correct |
6 |
Correct |
6 ms |
3192 KB |
Output is correct |
7 |
Correct |
7 ms |
3192 KB |
Output is correct |
8 |
Correct |
4 ms |
2808 KB |
Output is correct |
9 |
Correct |
4 ms |
2680 KB |
Output is correct |
10 |
Correct |
8 ms |
3320 KB |
Output is correct |
11 |
Correct |
9 ms |
3448 KB |
Output is correct |
12 |
Correct |
8 ms |
3452 KB |
Output is correct |
13 |
Correct |
8 ms |
3448 KB |
Output is correct |
14 |
Correct |
10 ms |
3576 KB |
Output is correct |
15 |
Correct |
10 ms |
3704 KB |
Output is correct |
16 |
Correct |
5 ms |
2808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
304 ms |
22032 KB |
Output is correct |
2 |
Correct |
307 ms |
21948 KB |
Output is correct |
3 |
Correct |
155 ms |
25464 KB |
Output is correct |
4 |
Correct |
136 ms |
24484 KB |
Output is correct |
5 |
Correct |
156 ms |
22904 KB |
Output is correct |
6 |
Correct |
395 ms |
25464 KB |
Output is correct |
7 |
Correct |
5 ms |
2936 KB |
Output is correct |
8 |
Correct |
5 ms |
2936 KB |
Output is correct |
9 |
Correct |
5 ms |
2808 KB |
Output is correct |
10 |
Correct |
17 ms |
5368 KB |
Output is correct |
11 |
Correct |
6 ms |
2936 KB |
Output is correct |
12 |
Correct |
30 ms |
5752 KB |
Output is correct |
13 |
Correct |
29 ms |
5748 KB |
Output is correct |
14 |
Correct |
20 ms |
5880 KB |
Output is correct |
15 |
Correct |
4 ms |
2680 KB |
Output is correct |
16 |
Correct |
7 ms |
3068 KB |
Output is correct |
17 |
Correct |
27 ms |
7196 KB |
Output is correct |
18 |
Correct |
7 ms |
3192 KB |
Output is correct |
19 |
Correct |
31 ms |
7768 KB |
Output is correct |
20 |
Correct |
39 ms |
7412 KB |
Output is correct |
21 |
Correct |
39 ms |
7284 KB |
Output is correct |
22 |
Correct |
7 ms |
3064 KB |
Output is correct |
23 |
Correct |
4 ms |
2680 KB |
Output is correct |
24 |
Correct |
4 ms |
2680 KB |
Output is correct |
25 |
Correct |
8 ms |
3192 KB |
Output is correct |
26 |
Correct |
39 ms |
9464 KB |
Output is correct |
27 |
Correct |
9 ms |
3320 KB |
Output is correct |
28 |
Correct |
46 ms |
10588 KB |
Output is correct |
29 |
Correct |
78 ms |
9336 KB |
Output is correct |
30 |
Correct |
71 ms |
9336 KB |
Output is correct |
31 |
Correct |
8 ms |
3448 KB |
Output is correct |
32 |
Correct |
8 ms |
3448 KB |
Output is correct |
33 |
Correct |
9 ms |
3448 KB |
Output is correct |
34 |
Correct |
53 ms |
11612 KB |
Output is correct |
35 |
Correct |
10 ms |
3576 KB |
Output is correct |
36 |
Correct |
113 ms |
12236 KB |
Output is correct |
37 |
Correct |
121 ms |
11988 KB |
Output is correct |
38 |
Correct |
67 ms |
13180 KB |
Output is correct |
39 |
Correct |
11 ms |
3704 KB |
Output is correct |
40 |
Correct |
5 ms |
2808 KB |
Output is correct |
41 |
Correct |
73 ms |
14328 KB |
Output is correct |
42 |
Correct |
10 ms |
4088 KB |
Output is correct |
43 |
Correct |
79 ms |
15864 KB |
Output is correct |
44 |
Correct |
118 ms |
14836 KB |
Output is correct |
45 |
Correct |
134 ms |
14704 KB |
Output is correct |
46 |
Correct |
99 ms |
17556 KB |
Output is correct |
47 |
Correct |
112 ms |
20604 KB |
Output is correct |
48 |
Correct |
219 ms |
17912 KB |
Output is correct |
49 |
Correct |
212 ms |
17680 KB |
Output is correct |
50 |
Correct |
14 ms |
4548 KB |
Output is correct |
51 |
Correct |
17 ms |
4344 KB |
Output is correct |
52 |
Correct |
17 ms |
4344 KB |
Output is correct |
53 |
Correct |
121 ms |
21368 KB |
Output is correct |