# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
292682 |
2020-09-07T11:43:47 Z |
임성재(#5807) |
ROI16_sending (ROI16_sending) |
C++17 |
|
5000 ms |
9336 KB |
#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(false); cin.tie(0);
#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf = 1e9;
const ll INF = 1e18;
int n, k;
int sp[200010][21];
int d[200010];
int a[200010];
int b[200010];
int lca(int a, int b) {
if(d[a] > d[b]) swap(a, b);
for(int i=20; i>=0; i--) {
if(d[b] - d[a] >= (1<<i)) b = sp[b][i];
}
if(a == b) return a;
for(int i=20; i>=0; i--) {
if(sp[a][i] != sp[b][i]) {
a = sp[a][i], b = sp[b][i];
}
}
return sp[a][0];
}
int dist(int a, int b) {
return d[a] + d[b] - 2 * d[lca(a, b)];
}
int main() {
fast;
cin >> n >> k;
for(int i=2; i<=n; i++) {
cin >> sp[i][0];
d[i] = d[sp[i][0]] + 1;
}
for(int j=1; j<=20; j++) {
for(int i=1; i<=n; i++) {
sp[i][j] = sp[sp[i][j-1]][j-1];
}
}
for(int i=1; i<=k; i++) {
cin >> a[i] >> b[i];
}
int ans = 0;
pii mxi = mp(1, 2);
for(int i=1; i<=k; i++) {
for(int j = i+1; j<=k; j++) {
int x = dist(a[i], b[i]) + dist(a[j], b[j]);
x -= min(dist(a[i], a[j]) + dist(b[i], b[j]), dist(a[i], b[j]) + dist(a[j], b[i]));
if(x > ans) {
ans = x;
mxi = mp(i, j);
}
}
}
cout << ans / 2 << "\n";
cout << mxi.fi << " " << mxi.se;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
4 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
3 ms |
384 KB |
Output is correct |
19 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
4 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
3 ms |
384 KB |
Output is correct |
19 |
Correct |
3 ms |
384 KB |
Output is correct |
20 |
Correct |
278 ms |
760 KB |
Output is correct |
21 |
Correct |
299 ms |
760 KB |
Output is correct |
22 |
Correct |
320 ms |
760 KB |
Output is correct |
23 |
Correct |
423 ms |
764 KB |
Output is correct |
24 |
Correct |
352 ms |
760 KB |
Output is correct |
25 |
Correct |
194 ms |
760 KB |
Output is correct |
26 |
Correct |
310 ms |
640 KB |
Output is correct |
27 |
Correct |
250 ms |
760 KB |
Output is correct |
28 |
Correct |
249 ms |
888 KB |
Output is correct |
29 |
Correct |
93 ms |
760 KB |
Output is correct |
30 |
Correct |
59 ms |
640 KB |
Output is correct |
31 |
Correct |
49 ms |
640 KB |
Output is correct |
32 |
Correct |
306 ms |
888 KB |
Output is correct |
33 |
Correct |
343 ms |
760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
4 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
3 ms |
384 KB |
Output is correct |
19 |
Correct |
3 ms |
384 KB |
Output is correct |
20 |
Correct |
278 ms |
760 KB |
Output is correct |
21 |
Correct |
299 ms |
760 KB |
Output is correct |
22 |
Correct |
320 ms |
760 KB |
Output is correct |
23 |
Correct |
423 ms |
764 KB |
Output is correct |
24 |
Correct |
352 ms |
760 KB |
Output is correct |
25 |
Correct |
194 ms |
760 KB |
Output is correct |
26 |
Correct |
310 ms |
640 KB |
Output is correct |
27 |
Correct |
250 ms |
760 KB |
Output is correct |
28 |
Correct |
249 ms |
888 KB |
Output is correct |
29 |
Correct |
93 ms |
760 KB |
Output is correct |
30 |
Correct |
59 ms |
640 KB |
Output is correct |
31 |
Correct |
49 ms |
640 KB |
Output is correct |
32 |
Correct |
306 ms |
888 KB |
Output is correct |
33 |
Correct |
343 ms |
760 KB |
Output is correct |
34 |
Correct |
363 ms |
8960 KB |
Output is correct |
35 |
Correct |
426 ms |
8960 KB |
Output is correct |
36 |
Correct |
745 ms |
8960 KB |
Output is correct |
37 |
Correct |
920 ms |
9024 KB |
Output is correct |
38 |
Correct |
787 ms |
9028 KB |
Output is correct |
39 |
Correct |
234 ms |
9028 KB |
Output is correct |
40 |
Correct |
765 ms |
8960 KB |
Output is correct |
41 |
Correct |
273 ms |
9024 KB |
Output is correct |
42 |
Correct |
329 ms |
8960 KB |
Output is correct |
43 |
Correct |
148 ms |
9080 KB |
Output is correct |
44 |
Correct |
142 ms |
8960 KB |
Output is correct |
45 |
Correct |
76 ms |
8960 KB |
Output is correct |
46 |
Correct |
724 ms |
9220 KB |
Output is correct |
47 |
Correct |
662 ms |
9156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
4 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
3 ms |
384 KB |
Output is correct |
19 |
Correct |
3 ms |
384 KB |
Output is correct |
20 |
Correct |
278 ms |
760 KB |
Output is correct |
21 |
Correct |
299 ms |
760 KB |
Output is correct |
22 |
Correct |
320 ms |
760 KB |
Output is correct |
23 |
Correct |
423 ms |
764 KB |
Output is correct |
24 |
Correct |
352 ms |
760 KB |
Output is correct |
25 |
Correct |
194 ms |
760 KB |
Output is correct |
26 |
Correct |
310 ms |
640 KB |
Output is correct |
27 |
Correct |
250 ms |
760 KB |
Output is correct |
28 |
Correct |
249 ms |
888 KB |
Output is correct |
29 |
Correct |
93 ms |
760 KB |
Output is correct |
30 |
Correct |
59 ms |
640 KB |
Output is correct |
31 |
Correct |
49 ms |
640 KB |
Output is correct |
32 |
Correct |
306 ms |
888 KB |
Output is correct |
33 |
Correct |
343 ms |
760 KB |
Output is correct |
34 |
Correct |
363 ms |
8960 KB |
Output is correct |
35 |
Correct |
426 ms |
8960 KB |
Output is correct |
36 |
Correct |
745 ms |
8960 KB |
Output is correct |
37 |
Correct |
920 ms |
9024 KB |
Output is correct |
38 |
Correct |
787 ms |
9028 KB |
Output is correct |
39 |
Correct |
234 ms |
9028 KB |
Output is correct |
40 |
Correct |
765 ms |
8960 KB |
Output is correct |
41 |
Correct |
273 ms |
9024 KB |
Output is correct |
42 |
Correct |
329 ms |
8960 KB |
Output is correct |
43 |
Correct |
148 ms |
9080 KB |
Output is correct |
44 |
Correct |
142 ms |
8960 KB |
Output is correct |
45 |
Correct |
76 ms |
8960 KB |
Output is correct |
46 |
Correct |
724 ms |
9220 KB |
Output is correct |
47 |
Correct |
662 ms |
9156 KB |
Output is correct |
48 |
Execution timed out |
5057 ms |
8960 KB |
Time limit exceeded |
49 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5067 ms |
9336 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5071 ms |
9336 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
4 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
3 ms |
384 KB |
Output is correct |
19 |
Correct |
3 ms |
384 KB |
Output is correct |
20 |
Correct |
278 ms |
760 KB |
Output is correct |
21 |
Correct |
299 ms |
760 KB |
Output is correct |
22 |
Correct |
320 ms |
760 KB |
Output is correct |
23 |
Correct |
423 ms |
764 KB |
Output is correct |
24 |
Correct |
352 ms |
760 KB |
Output is correct |
25 |
Correct |
194 ms |
760 KB |
Output is correct |
26 |
Correct |
310 ms |
640 KB |
Output is correct |
27 |
Correct |
250 ms |
760 KB |
Output is correct |
28 |
Correct |
249 ms |
888 KB |
Output is correct |
29 |
Correct |
93 ms |
760 KB |
Output is correct |
30 |
Correct |
59 ms |
640 KB |
Output is correct |
31 |
Correct |
49 ms |
640 KB |
Output is correct |
32 |
Correct |
306 ms |
888 KB |
Output is correct |
33 |
Correct |
343 ms |
760 KB |
Output is correct |
34 |
Correct |
363 ms |
8960 KB |
Output is correct |
35 |
Correct |
426 ms |
8960 KB |
Output is correct |
36 |
Correct |
745 ms |
8960 KB |
Output is correct |
37 |
Correct |
920 ms |
9024 KB |
Output is correct |
38 |
Correct |
787 ms |
9028 KB |
Output is correct |
39 |
Correct |
234 ms |
9028 KB |
Output is correct |
40 |
Correct |
765 ms |
8960 KB |
Output is correct |
41 |
Correct |
273 ms |
9024 KB |
Output is correct |
42 |
Correct |
329 ms |
8960 KB |
Output is correct |
43 |
Correct |
148 ms |
9080 KB |
Output is correct |
44 |
Correct |
142 ms |
8960 KB |
Output is correct |
45 |
Correct |
76 ms |
8960 KB |
Output is correct |
46 |
Correct |
724 ms |
9220 KB |
Output is correct |
47 |
Correct |
662 ms |
9156 KB |
Output is correct |
48 |
Execution timed out |
5057 ms |
8960 KB |
Time limit exceeded |
49 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
4 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
3 ms |
384 KB |
Output is correct |
19 |
Correct |
3 ms |
384 KB |
Output is correct |
20 |
Correct |
278 ms |
760 KB |
Output is correct |
21 |
Correct |
299 ms |
760 KB |
Output is correct |
22 |
Correct |
320 ms |
760 KB |
Output is correct |
23 |
Correct |
423 ms |
764 KB |
Output is correct |
24 |
Correct |
352 ms |
760 KB |
Output is correct |
25 |
Correct |
194 ms |
760 KB |
Output is correct |
26 |
Correct |
310 ms |
640 KB |
Output is correct |
27 |
Correct |
250 ms |
760 KB |
Output is correct |
28 |
Correct |
249 ms |
888 KB |
Output is correct |
29 |
Correct |
93 ms |
760 KB |
Output is correct |
30 |
Correct |
59 ms |
640 KB |
Output is correct |
31 |
Correct |
49 ms |
640 KB |
Output is correct |
32 |
Correct |
306 ms |
888 KB |
Output is correct |
33 |
Correct |
343 ms |
760 KB |
Output is correct |
34 |
Correct |
363 ms |
8960 KB |
Output is correct |
35 |
Correct |
426 ms |
8960 KB |
Output is correct |
36 |
Correct |
745 ms |
8960 KB |
Output is correct |
37 |
Correct |
920 ms |
9024 KB |
Output is correct |
38 |
Correct |
787 ms |
9028 KB |
Output is correct |
39 |
Correct |
234 ms |
9028 KB |
Output is correct |
40 |
Correct |
765 ms |
8960 KB |
Output is correct |
41 |
Correct |
273 ms |
9024 KB |
Output is correct |
42 |
Correct |
329 ms |
8960 KB |
Output is correct |
43 |
Correct |
148 ms |
9080 KB |
Output is correct |
44 |
Correct |
142 ms |
8960 KB |
Output is correct |
45 |
Correct |
76 ms |
8960 KB |
Output is correct |
46 |
Correct |
724 ms |
9220 KB |
Output is correct |
47 |
Correct |
662 ms |
9156 KB |
Output is correct |
48 |
Execution timed out |
5057 ms |
8960 KB |
Time limit exceeded |
49 |
Halted |
0 ms |
0 KB |
- |