Submission #292793

# Submission time Handle Problem Language Result Execution time Memory
292793 2020-09-07T13:31:51 Z 반딧불(#5810) ROI16_sending (ROI16_sending) C++17
29 / 100
5000 ms 77304 KB
#include <bits/stdc++.h>
#define LIM 18

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;

int n, k;
int par[200002], depth[200002];
vector<int> link[200002];
set<int> st[200002];

int ans = -1, ansX, ansY;
void dfs(int x){
    for(auto &y: link[x]){
        if(y == par[x]) continue;
        depth[y] = depth[x]+1;
        dfs(y);
    }
}

int main(){
    scanf("%d %d", &n, &k);
    for(int i=2; i<=n; i++){
        scanf("%d", &par[i]);
        link[i].push_back(par[i]);
        link[par[i]].push_back(i);
    }
    dfs(1);

    for(int i=1; i<=k; i++){
        int x, y;
        scanf("%d %d", &x, &y);

        if(depth[x] > depth[y]) swap(x, y);
        while(depth[x] < depth[y]) st[i].insert(y), y = par[y];

        while(x != y) st[i].insert(x), st[i].insert(y), x = par[x], y = par[y];
    }

    for(int i=1; i<=k; i++){
        for(int j=i+1; j<=k; j++){
            int cnt = 0;
            for(auto it = st[i].begin(), it2 = st[j].begin(); it != st[i].end() && it2 != st[j].end(); ){
                if(*it == *it2) cnt++, ++it, ++it2;
                else if(*it < *it2) ++it;
                else ++it2;
            }
            if(ans < cnt){
                ans = cnt, ansX = i, ansY = j;
            }
        }
    }

    printf("%d\n%d %d", ans, ansX, ansY);
}

Compilation message

sending.cpp: In function 'int main()':
sending.cpp:24:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   24 |     scanf("%d %d", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~
sending.cpp:26:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   26 |         scanf("%d", &par[i]);
      |         ~~~~~^~~~~~~~~~~~~~~
sending.cpp:34:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   34 |         scanf("%d %d", &x, &y);
      |         ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 10 ms 14464 KB Output is correct
2 Correct 10 ms 14464 KB Output is correct
3 Correct 11 ms 14464 KB Output is correct
4 Correct 10 ms 14464 KB Output is correct
5 Correct 10 ms 14464 KB Output is correct
6 Correct 11 ms 14464 KB Output is correct
7 Correct 13 ms 14464 KB Output is correct
8 Correct 12 ms 14592 KB Output is correct
9 Correct 13 ms 14592 KB Output is correct
10 Correct 11 ms 14444 KB Output is correct
11 Correct 10 ms 14464 KB Output is correct
12 Correct 13 ms 14592 KB Output is correct
13 Correct 10 ms 14464 KB Output is correct
14 Correct 11 ms 14464 KB Output is correct
15 Correct 15 ms 14976 KB Output is correct
16 Correct 11 ms 14464 KB Output is correct
17 Correct 11 ms 14524 KB Output is correct
18 Correct 12 ms 14592 KB Output is correct
19 Correct 11 ms 14464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 14464 KB Output is correct
2 Correct 10 ms 14464 KB Output is correct
3 Correct 11 ms 14464 KB Output is correct
4 Correct 10 ms 14464 KB Output is correct
5 Correct 10 ms 14464 KB Output is correct
6 Correct 11 ms 14464 KB Output is correct
7 Correct 13 ms 14464 KB Output is correct
8 Correct 12 ms 14592 KB Output is correct
9 Correct 13 ms 14592 KB Output is correct
10 Correct 11 ms 14444 KB Output is correct
11 Correct 10 ms 14464 KB Output is correct
12 Correct 13 ms 14592 KB Output is correct
13 Correct 10 ms 14464 KB Output is correct
14 Correct 11 ms 14464 KB Output is correct
15 Correct 15 ms 14976 KB Output is correct
16 Correct 11 ms 14464 KB Output is correct
17 Correct 11 ms 14524 KB Output is correct
18 Correct 12 ms 14592 KB Output is correct
19 Correct 11 ms 14464 KB Output is correct
20 Correct 183 ms 15232 KB Output is correct
21 Correct 391 ms 15992 KB Output is correct
22 Execution timed out 5042 ms 77304 KB Time limit exceeded
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 14464 KB Output is correct
2 Correct 10 ms 14464 KB Output is correct
3 Correct 11 ms 14464 KB Output is correct
4 Correct 10 ms 14464 KB Output is correct
5 Correct 10 ms 14464 KB Output is correct
6 Correct 11 ms 14464 KB Output is correct
7 Correct 13 ms 14464 KB Output is correct
8 Correct 12 ms 14592 KB Output is correct
9 Correct 13 ms 14592 KB Output is correct
10 Correct 11 ms 14444 KB Output is correct
11 Correct 10 ms 14464 KB Output is correct
12 Correct 13 ms 14592 KB Output is correct
13 Correct 10 ms 14464 KB Output is correct
14 Correct 11 ms 14464 KB Output is correct
15 Correct 15 ms 14976 KB Output is correct
16 Correct 11 ms 14464 KB Output is correct
17 Correct 11 ms 14524 KB Output is correct
18 Correct 12 ms 14592 KB Output is correct
19 Correct 11 ms 14464 KB Output is correct
20 Correct 183 ms 15232 KB Output is correct
21 Correct 391 ms 15992 KB Output is correct
22 Execution timed out 5042 ms 77304 KB Time limit exceeded
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 14464 KB Output is correct
2 Correct 10 ms 14464 KB Output is correct
3 Correct 11 ms 14464 KB Output is correct
4 Correct 10 ms 14464 KB Output is correct
5 Correct 10 ms 14464 KB Output is correct
6 Correct 11 ms 14464 KB Output is correct
7 Correct 13 ms 14464 KB Output is correct
8 Correct 12 ms 14592 KB Output is correct
9 Correct 13 ms 14592 KB Output is correct
10 Correct 11 ms 14444 KB Output is correct
11 Correct 10 ms 14464 KB Output is correct
12 Correct 13 ms 14592 KB Output is correct
13 Correct 10 ms 14464 KB Output is correct
14 Correct 11 ms 14464 KB Output is correct
15 Correct 15 ms 14976 KB Output is correct
16 Correct 11 ms 14464 KB Output is correct
17 Correct 11 ms 14524 KB Output is correct
18 Correct 12 ms 14592 KB Output is correct
19 Correct 11 ms 14464 KB Output is correct
20 Correct 183 ms 15232 KB Output is correct
21 Correct 391 ms 15992 KB Output is correct
22 Execution timed out 5042 ms 77304 KB Time limit exceeded
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5056 ms 65264 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5070 ms 33300 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 14464 KB Output is correct
2 Correct 10 ms 14464 KB Output is correct
3 Correct 11 ms 14464 KB Output is correct
4 Correct 10 ms 14464 KB Output is correct
5 Correct 10 ms 14464 KB Output is correct
6 Correct 11 ms 14464 KB Output is correct
7 Correct 13 ms 14464 KB Output is correct
8 Correct 12 ms 14592 KB Output is correct
9 Correct 13 ms 14592 KB Output is correct
10 Correct 11 ms 14444 KB Output is correct
11 Correct 10 ms 14464 KB Output is correct
12 Correct 13 ms 14592 KB Output is correct
13 Correct 10 ms 14464 KB Output is correct
14 Correct 11 ms 14464 KB Output is correct
15 Correct 15 ms 14976 KB Output is correct
16 Correct 11 ms 14464 KB Output is correct
17 Correct 11 ms 14524 KB Output is correct
18 Correct 12 ms 14592 KB Output is correct
19 Correct 11 ms 14464 KB Output is correct
20 Correct 183 ms 15232 KB Output is correct
21 Correct 391 ms 15992 KB Output is correct
22 Execution timed out 5042 ms 77304 KB Time limit exceeded
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 14464 KB Output is correct
2 Correct 10 ms 14464 KB Output is correct
3 Correct 11 ms 14464 KB Output is correct
4 Correct 10 ms 14464 KB Output is correct
5 Correct 10 ms 14464 KB Output is correct
6 Correct 11 ms 14464 KB Output is correct
7 Correct 13 ms 14464 KB Output is correct
8 Correct 12 ms 14592 KB Output is correct
9 Correct 13 ms 14592 KB Output is correct
10 Correct 11 ms 14444 KB Output is correct
11 Correct 10 ms 14464 KB Output is correct
12 Correct 13 ms 14592 KB Output is correct
13 Correct 10 ms 14464 KB Output is correct
14 Correct 11 ms 14464 KB Output is correct
15 Correct 15 ms 14976 KB Output is correct
16 Correct 11 ms 14464 KB Output is correct
17 Correct 11 ms 14524 KB Output is correct
18 Correct 12 ms 14592 KB Output is correct
19 Correct 11 ms 14464 KB Output is correct
20 Correct 183 ms 15232 KB Output is correct
21 Correct 391 ms 15992 KB Output is correct
22 Execution timed out 5042 ms 77304 KB Time limit exceeded
23 Halted 0 ms 0 KB -