# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
292992 |
2020-09-07T15:22:57 Z |
송준혁(#5803) |
ROI16_sending (ROI16_sending) |
C++17 |
|
5000 ms |
13692 KB |
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
int N, M;
int ans, ansu=1, ansv=2;
int D[202020], P[202020][20];
int U[202020], V[202020];
vector<int> adj[202020];
int LCA(int u, int v){
if (D[u] > D[v]) swap(u, v);
for (int i=18; i>=0; i--) if (D[u] <= D[v]-(1<<i)) v=P[v][i];
if (u == v) return u;
for (int i=18; i>=0; i--) if (P[u][i] != P[v][i]) u=P[u][i], v=P[v][i];
return P[u][0];
}
int inter(int u1, int v1, int u2, int v2){
vector<int> t;
t.pb(D[LCA(u1, u2)]), t.pb(D[LCA(u1, v2)]);
t.pb(D[LCA(v1, u2)]), t.pb(D[LCA(v1, v2)]);
sort(t.begin(), t.end());
return t[2]+t[3]-2*max(D[LCA(u1, v1)], D[LCA(u2, v2)]);
}
int main(){
scanf("%d %d", &N, &M);
for (int i=2; i<=N; i++){
int p;
scanf("%d", &p);
P[i][0] = p, D[i] = D[p]+1;
for (int j=1; j<=18; j++) P[i][j] = P[P[i][j-1]][j-1];
}
for (int i=1; i<=M; i++) scanf("%d %d", &U[i], &V[i]);
for (int i=1; i<M; i++) for (int j=i+1; j<=M; j++){
int r = inter(U[i], V[i], U[j], V[j]);
if (ans < r) ans=r, ansu=i, ansv=j;
}
printf("%d\n%d %d\n", ans, ansu, ansv);
return 0;
}
Compilation message
sending.cpp: In function 'int main()':
sending.cpp:30:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
30 | scanf("%d %d", &N, &M);
| ~~~~~^~~~~~~~~~~~~~~~~
sending.cpp:33:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
33 | scanf("%d", &p);
| ~~~~~^~~~~~~~~~
sending.cpp:37:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
37 | for (int i=1; i<=M; i++) scanf("%d %d", &U[i], &V[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5120 KB |
Output is correct |
2 |
Correct |
4 ms |
5120 KB |
Output is correct |
3 |
Correct |
4 ms |
5120 KB |
Output is correct |
4 |
Correct |
4 ms |
5120 KB |
Output is correct |
5 |
Correct |
4 ms |
5120 KB |
Output is correct |
6 |
Correct |
8 ms |
5120 KB |
Output is correct |
7 |
Correct |
8 ms |
5120 KB |
Output is correct |
8 |
Correct |
7 ms |
5120 KB |
Output is correct |
9 |
Correct |
7 ms |
5120 KB |
Output is correct |
10 |
Correct |
7 ms |
5120 KB |
Output is correct |
11 |
Correct |
8 ms |
5120 KB |
Output is correct |
12 |
Correct |
7 ms |
5120 KB |
Output is correct |
13 |
Correct |
6 ms |
5120 KB |
Output is correct |
14 |
Correct |
7 ms |
5120 KB |
Output is correct |
15 |
Correct |
5 ms |
5120 KB |
Output is correct |
16 |
Correct |
4 ms |
5120 KB |
Output is correct |
17 |
Correct |
4 ms |
5120 KB |
Output is correct |
18 |
Correct |
8 ms |
5120 KB |
Output is correct |
19 |
Correct |
7 ms |
5120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5120 KB |
Output is correct |
2 |
Correct |
4 ms |
5120 KB |
Output is correct |
3 |
Correct |
4 ms |
5120 KB |
Output is correct |
4 |
Correct |
4 ms |
5120 KB |
Output is correct |
5 |
Correct |
4 ms |
5120 KB |
Output is correct |
6 |
Correct |
8 ms |
5120 KB |
Output is correct |
7 |
Correct |
8 ms |
5120 KB |
Output is correct |
8 |
Correct |
7 ms |
5120 KB |
Output is correct |
9 |
Correct |
7 ms |
5120 KB |
Output is correct |
10 |
Correct |
7 ms |
5120 KB |
Output is correct |
11 |
Correct |
8 ms |
5120 KB |
Output is correct |
12 |
Correct |
7 ms |
5120 KB |
Output is correct |
13 |
Correct |
6 ms |
5120 KB |
Output is correct |
14 |
Correct |
7 ms |
5120 KB |
Output is correct |
15 |
Correct |
5 ms |
5120 KB |
Output is correct |
16 |
Correct |
4 ms |
5120 KB |
Output is correct |
17 |
Correct |
4 ms |
5120 KB |
Output is correct |
18 |
Correct |
8 ms |
5120 KB |
Output is correct |
19 |
Correct |
7 ms |
5120 KB |
Output is correct |
20 |
Correct |
367 ms |
5468 KB |
Output is correct |
21 |
Correct |
437 ms |
5472 KB |
Output is correct |
22 |
Correct |
425 ms |
5468 KB |
Output is correct |
23 |
Correct |
554 ms |
5468 KB |
Output is correct |
24 |
Correct |
453 ms |
5496 KB |
Output is correct |
25 |
Correct |
308 ms |
5468 KB |
Output is correct |
26 |
Correct |
442 ms |
5376 KB |
Output is correct |
27 |
Correct |
320 ms |
5376 KB |
Output is correct |
28 |
Correct |
347 ms |
5376 KB |
Output is correct |
29 |
Correct |
187 ms |
5376 KB |
Output is correct |
30 |
Correct |
82 ms |
5376 KB |
Output is correct |
31 |
Correct |
85 ms |
5468 KB |
Output is correct |
32 |
Correct |
434 ms |
5468 KB |
Output is correct |
33 |
Correct |
470 ms |
5376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5120 KB |
Output is correct |
2 |
Correct |
4 ms |
5120 KB |
Output is correct |
3 |
Correct |
4 ms |
5120 KB |
Output is correct |
4 |
Correct |
4 ms |
5120 KB |
Output is correct |
5 |
Correct |
4 ms |
5120 KB |
Output is correct |
6 |
Correct |
8 ms |
5120 KB |
Output is correct |
7 |
Correct |
8 ms |
5120 KB |
Output is correct |
8 |
Correct |
7 ms |
5120 KB |
Output is correct |
9 |
Correct |
7 ms |
5120 KB |
Output is correct |
10 |
Correct |
7 ms |
5120 KB |
Output is correct |
11 |
Correct |
8 ms |
5120 KB |
Output is correct |
12 |
Correct |
7 ms |
5120 KB |
Output is correct |
13 |
Correct |
6 ms |
5120 KB |
Output is correct |
14 |
Correct |
7 ms |
5120 KB |
Output is correct |
15 |
Correct |
5 ms |
5120 KB |
Output is correct |
16 |
Correct |
4 ms |
5120 KB |
Output is correct |
17 |
Correct |
4 ms |
5120 KB |
Output is correct |
18 |
Correct |
8 ms |
5120 KB |
Output is correct |
19 |
Correct |
7 ms |
5120 KB |
Output is correct |
20 |
Correct |
367 ms |
5468 KB |
Output is correct |
21 |
Correct |
437 ms |
5472 KB |
Output is correct |
22 |
Correct |
425 ms |
5468 KB |
Output is correct |
23 |
Correct |
554 ms |
5468 KB |
Output is correct |
24 |
Correct |
453 ms |
5496 KB |
Output is correct |
25 |
Correct |
308 ms |
5468 KB |
Output is correct |
26 |
Correct |
442 ms |
5376 KB |
Output is correct |
27 |
Correct |
320 ms |
5376 KB |
Output is correct |
28 |
Correct |
347 ms |
5376 KB |
Output is correct |
29 |
Correct |
187 ms |
5376 KB |
Output is correct |
30 |
Correct |
82 ms |
5376 KB |
Output is correct |
31 |
Correct |
85 ms |
5468 KB |
Output is correct |
32 |
Correct |
434 ms |
5468 KB |
Output is correct |
33 |
Correct |
470 ms |
5376 KB |
Output is correct |
34 |
Correct |
496 ms |
13352 KB |
Output is correct |
35 |
Correct |
528 ms |
13352 KB |
Output is correct |
36 |
Correct |
963 ms |
13360 KB |
Output is correct |
37 |
Correct |
1220 ms |
13356 KB |
Output is correct |
38 |
Correct |
963 ms |
13312 KB |
Output is correct |
39 |
Correct |
351 ms |
13432 KB |
Output is correct |
40 |
Correct |
1018 ms |
13432 KB |
Output is correct |
41 |
Correct |
341 ms |
13304 KB |
Output is correct |
42 |
Correct |
481 ms |
13348 KB |
Output is correct |
43 |
Correct |
249 ms |
13264 KB |
Output is correct |
44 |
Correct |
177 ms |
13304 KB |
Output is correct |
45 |
Correct |
117 ms |
13252 KB |
Output is correct |
46 |
Correct |
904 ms |
13304 KB |
Output is correct |
47 |
Correct |
841 ms |
13360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5120 KB |
Output is correct |
2 |
Correct |
4 ms |
5120 KB |
Output is correct |
3 |
Correct |
4 ms |
5120 KB |
Output is correct |
4 |
Correct |
4 ms |
5120 KB |
Output is correct |
5 |
Correct |
4 ms |
5120 KB |
Output is correct |
6 |
Correct |
8 ms |
5120 KB |
Output is correct |
7 |
Correct |
8 ms |
5120 KB |
Output is correct |
8 |
Correct |
7 ms |
5120 KB |
Output is correct |
9 |
Correct |
7 ms |
5120 KB |
Output is correct |
10 |
Correct |
7 ms |
5120 KB |
Output is correct |
11 |
Correct |
8 ms |
5120 KB |
Output is correct |
12 |
Correct |
7 ms |
5120 KB |
Output is correct |
13 |
Correct |
6 ms |
5120 KB |
Output is correct |
14 |
Correct |
7 ms |
5120 KB |
Output is correct |
15 |
Correct |
5 ms |
5120 KB |
Output is correct |
16 |
Correct |
4 ms |
5120 KB |
Output is correct |
17 |
Correct |
4 ms |
5120 KB |
Output is correct |
18 |
Correct |
8 ms |
5120 KB |
Output is correct |
19 |
Correct |
7 ms |
5120 KB |
Output is correct |
20 |
Correct |
367 ms |
5468 KB |
Output is correct |
21 |
Correct |
437 ms |
5472 KB |
Output is correct |
22 |
Correct |
425 ms |
5468 KB |
Output is correct |
23 |
Correct |
554 ms |
5468 KB |
Output is correct |
24 |
Correct |
453 ms |
5496 KB |
Output is correct |
25 |
Correct |
308 ms |
5468 KB |
Output is correct |
26 |
Correct |
442 ms |
5376 KB |
Output is correct |
27 |
Correct |
320 ms |
5376 KB |
Output is correct |
28 |
Correct |
347 ms |
5376 KB |
Output is correct |
29 |
Correct |
187 ms |
5376 KB |
Output is correct |
30 |
Correct |
82 ms |
5376 KB |
Output is correct |
31 |
Correct |
85 ms |
5468 KB |
Output is correct |
32 |
Correct |
434 ms |
5468 KB |
Output is correct |
33 |
Correct |
470 ms |
5376 KB |
Output is correct |
34 |
Correct |
496 ms |
13352 KB |
Output is correct |
35 |
Correct |
528 ms |
13352 KB |
Output is correct |
36 |
Correct |
963 ms |
13360 KB |
Output is correct |
37 |
Correct |
1220 ms |
13356 KB |
Output is correct |
38 |
Correct |
963 ms |
13312 KB |
Output is correct |
39 |
Correct |
351 ms |
13432 KB |
Output is correct |
40 |
Correct |
1018 ms |
13432 KB |
Output is correct |
41 |
Correct |
341 ms |
13304 KB |
Output is correct |
42 |
Correct |
481 ms |
13348 KB |
Output is correct |
43 |
Correct |
249 ms |
13264 KB |
Output is correct |
44 |
Correct |
177 ms |
13304 KB |
Output is correct |
45 |
Correct |
117 ms |
13252 KB |
Output is correct |
46 |
Correct |
904 ms |
13304 KB |
Output is correct |
47 |
Correct |
841 ms |
13360 KB |
Output is correct |
48 |
Execution timed out |
5016 ms |
13304 KB |
Time limit exceeded |
49 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5034 ms |
13692 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5056 ms |
13692 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5120 KB |
Output is correct |
2 |
Correct |
4 ms |
5120 KB |
Output is correct |
3 |
Correct |
4 ms |
5120 KB |
Output is correct |
4 |
Correct |
4 ms |
5120 KB |
Output is correct |
5 |
Correct |
4 ms |
5120 KB |
Output is correct |
6 |
Correct |
8 ms |
5120 KB |
Output is correct |
7 |
Correct |
8 ms |
5120 KB |
Output is correct |
8 |
Correct |
7 ms |
5120 KB |
Output is correct |
9 |
Correct |
7 ms |
5120 KB |
Output is correct |
10 |
Correct |
7 ms |
5120 KB |
Output is correct |
11 |
Correct |
8 ms |
5120 KB |
Output is correct |
12 |
Correct |
7 ms |
5120 KB |
Output is correct |
13 |
Correct |
6 ms |
5120 KB |
Output is correct |
14 |
Correct |
7 ms |
5120 KB |
Output is correct |
15 |
Correct |
5 ms |
5120 KB |
Output is correct |
16 |
Correct |
4 ms |
5120 KB |
Output is correct |
17 |
Correct |
4 ms |
5120 KB |
Output is correct |
18 |
Correct |
8 ms |
5120 KB |
Output is correct |
19 |
Correct |
7 ms |
5120 KB |
Output is correct |
20 |
Correct |
367 ms |
5468 KB |
Output is correct |
21 |
Correct |
437 ms |
5472 KB |
Output is correct |
22 |
Correct |
425 ms |
5468 KB |
Output is correct |
23 |
Correct |
554 ms |
5468 KB |
Output is correct |
24 |
Correct |
453 ms |
5496 KB |
Output is correct |
25 |
Correct |
308 ms |
5468 KB |
Output is correct |
26 |
Correct |
442 ms |
5376 KB |
Output is correct |
27 |
Correct |
320 ms |
5376 KB |
Output is correct |
28 |
Correct |
347 ms |
5376 KB |
Output is correct |
29 |
Correct |
187 ms |
5376 KB |
Output is correct |
30 |
Correct |
82 ms |
5376 KB |
Output is correct |
31 |
Correct |
85 ms |
5468 KB |
Output is correct |
32 |
Correct |
434 ms |
5468 KB |
Output is correct |
33 |
Correct |
470 ms |
5376 KB |
Output is correct |
34 |
Correct |
496 ms |
13352 KB |
Output is correct |
35 |
Correct |
528 ms |
13352 KB |
Output is correct |
36 |
Correct |
963 ms |
13360 KB |
Output is correct |
37 |
Correct |
1220 ms |
13356 KB |
Output is correct |
38 |
Correct |
963 ms |
13312 KB |
Output is correct |
39 |
Correct |
351 ms |
13432 KB |
Output is correct |
40 |
Correct |
1018 ms |
13432 KB |
Output is correct |
41 |
Correct |
341 ms |
13304 KB |
Output is correct |
42 |
Correct |
481 ms |
13348 KB |
Output is correct |
43 |
Correct |
249 ms |
13264 KB |
Output is correct |
44 |
Correct |
177 ms |
13304 KB |
Output is correct |
45 |
Correct |
117 ms |
13252 KB |
Output is correct |
46 |
Correct |
904 ms |
13304 KB |
Output is correct |
47 |
Correct |
841 ms |
13360 KB |
Output is correct |
48 |
Execution timed out |
5016 ms |
13304 KB |
Time limit exceeded |
49 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5120 KB |
Output is correct |
2 |
Correct |
4 ms |
5120 KB |
Output is correct |
3 |
Correct |
4 ms |
5120 KB |
Output is correct |
4 |
Correct |
4 ms |
5120 KB |
Output is correct |
5 |
Correct |
4 ms |
5120 KB |
Output is correct |
6 |
Correct |
8 ms |
5120 KB |
Output is correct |
7 |
Correct |
8 ms |
5120 KB |
Output is correct |
8 |
Correct |
7 ms |
5120 KB |
Output is correct |
9 |
Correct |
7 ms |
5120 KB |
Output is correct |
10 |
Correct |
7 ms |
5120 KB |
Output is correct |
11 |
Correct |
8 ms |
5120 KB |
Output is correct |
12 |
Correct |
7 ms |
5120 KB |
Output is correct |
13 |
Correct |
6 ms |
5120 KB |
Output is correct |
14 |
Correct |
7 ms |
5120 KB |
Output is correct |
15 |
Correct |
5 ms |
5120 KB |
Output is correct |
16 |
Correct |
4 ms |
5120 KB |
Output is correct |
17 |
Correct |
4 ms |
5120 KB |
Output is correct |
18 |
Correct |
8 ms |
5120 KB |
Output is correct |
19 |
Correct |
7 ms |
5120 KB |
Output is correct |
20 |
Correct |
367 ms |
5468 KB |
Output is correct |
21 |
Correct |
437 ms |
5472 KB |
Output is correct |
22 |
Correct |
425 ms |
5468 KB |
Output is correct |
23 |
Correct |
554 ms |
5468 KB |
Output is correct |
24 |
Correct |
453 ms |
5496 KB |
Output is correct |
25 |
Correct |
308 ms |
5468 KB |
Output is correct |
26 |
Correct |
442 ms |
5376 KB |
Output is correct |
27 |
Correct |
320 ms |
5376 KB |
Output is correct |
28 |
Correct |
347 ms |
5376 KB |
Output is correct |
29 |
Correct |
187 ms |
5376 KB |
Output is correct |
30 |
Correct |
82 ms |
5376 KB |
Output is correct |
31 |
Correct |
85 ms |
5468 KB |
Output is correct |
32 |
Correct |
434 ms |
5468 KB |
Output is correct |
33 |
Correct |
470 ms |
5376 KB |
Output is correct |
34 |
Correct |
496 ms |
13352 KB |
Output is correct |
35 |
Correct |
528 ms |
13352 KB |
Output is correct |
36 |
Correct |
963 ms |
13360 KB |
Output is correct |
37 |
Correct |
1220 ms |
13356 KB |
Output is correct |
38 |
Correct |
963 ms |
13312 KB |
Output is correct |
39 |
Correct |
351 ms |
13432 KB |
Output is correct |
40 |
Correct |
1018 ms |
13432 KB |
Output is correct |
41 |
Correct |
341 ms |
13304 KB |
Output is correct |
42 |
Correct |
481 ms |
13348 KB |
Output is correct |
43 |
Correct |
249 ms |
13264 KB |
Output is correct |
44 |
Correct |
177 ms |
13304 KB |
Output is correct |
45 |
Correct |
117 ms |
13252 KB |
Output is correct |
46 |
Correct |
904 ms |
13304 KB |
Output is correct |
47 |
Correct |
841 ms |
13360 KB |
Output is correct |
48 |
Execution timed out |
5016 ms |
13304 KB |
Time limit exceeded |
49 |
Halted |
0 ms |
0 KB |
- |