Submission #292791

# Submission time Handle Problem Language Result Execution time Memory
292791 2020-09-07T13:30:50 Z 반딧불(#5810) ROI16_sending (ROI16_sending) C++17
29 / 100
55 ms 18168 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[102];

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 3 ms 4992 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Correct 3 ms 4992 KB Output is correct
4 Correct 3 ms 4992 KB Output is correct
5 Correct 4 ms 4992 KB Output is correct
6 Correct 5 ms 5120 KB Output is correct
7 Correct 6 ms 5120 KB Output is correct
8 Correct 6 ms 5248 KB Output is correct
9 Correct 7 ms 5248 KB Output is correct
10 Correct 5 ms 5120 KB Output is correct
11 Correct 4 ms 4992 KB Output is correct
12 Correct 6 ms 5248 KB Output is correct
13 Correct 4 ms 4992 KB Output is correct
14 Correct 4 ms 4992 KB Output is correct
15 Correct 10 ms 5376 KB Output is correct
16 Correct 5 ms 5120 KB Output is correct
17 Correct 4 ms 5152 KB Output is correct
18 Correct 6 ms 5120 KB Output is correct
19 Correct 5 ms 5120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4992 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Correct 3 ms 4992 KB Output is correct
4 Correct 3 ms 4992 KB Output is correct
5 Correct 4 ms 4992 KB Output is correct
6 Correct 5 ms 5120 KB Output is correct
7 Correct 6 ms 5120 KB Output is correct
8 Correct 6 ms 5248 KB Output is correct
9 Correct 7 ms 5248 KB Output is correct
10 Correct 5 ms 5120 KB Output is correct
11 Correct 4 ms 4992 KB Output is correct
12 Correct 6 ms 5248 KB Output is correct
13 Correct 4 ms 4992 KB Output is correct
14 Correct 4 ms 4992 KB Output is correct
15 Correct 10 ms 5376 KB Output is correct
16 Correct 5 ms 5120 KB Output is correct
17 Correct 4 ms 5152 KB Output is correct
18 Correct 6 ms 5120 KB Output is correct
19 Correct 5 ms 5120 KB Output is correct
20 Runtime error 12 ms 10368 KB Execution killed with signal 11
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4992 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Correct 3 ms 4992 KB Output is correct
4 Correct 3 ms 4992 KB Output is correct
5 Correct 4 ms 4992 KB Output is correct
6 Correct 5 ms 5120 KB Output is correct
7 Correct 6 ms 5120 KB Output is correct
8 Correct 6 ms 5248 KB Output is correct
9 Correct 7 ms 5248 KB Output is correct
10 Correct 5 ms 5120 KB Output is correct
11 Correct 4 ms 4992 KB Output is correct
12 Correct 6 ms 5248 KB Output is correct
13 Correct 4 ms 4992 KB Output is correct
14 Correct 4 ms 4992 KB Output is correct
15 Correct 10 ms 5376 KB Output is correct
16 Correct 5 ms 5120 KB Output is correct
17 Correct 4 ms 5152 KB Output is correct
18 Correct 6 ms 5120 KB Output is correct
19 Correct 5 ms 5120 KB Output is correct
20 Runtime error 12 ms 10368 KB Execution killed with signal 11
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4992 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Correct 3 ms 4992 KB Output is correct
4 Correct 3 ms 4992 KB Output is correct
5 Correct 4 ms 4992 KB Output is correct
6 Correct 5 ms 5120 KB Output is correct
7 Correct 6 ms 5120 KB Output is correct
8 Correct 6 ms 5248 KB Output is correct
9 Correct 7 ms 5248 KB Output is correct
10 Correct 5 ms 5120 KB Output is correct
11 Correct 4 ms 4992 KB Output is correct
12 Correct 6 ms 5248 KB Output is correct
13 Correct 4 ms 4992 KB Output is correct
14 Correct 4 ms 4992 KB Output is correct
15 Correct 10 ms 5376 KB Output is correct
16 Correct 5 ms 5120 KB Output is correct
17 Correct 4 ms 5152 KB Output is correct
18 Correct 6 ms 5120 KB Output is correct
19 Correct 5 ms 5120 KB Output is correct
20 Runtime error 12 ms 10368 KB Execution killed with signal 11
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 42 ms 18040 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 55 ms 18168 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4992 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Correct 3 ms 4992 KB Output is correct
4 Correct 3 ms 4992 KB Output is correct
5 Correct 4 ms 4992 KB Output is correct
6 Correct 5 ms 5120 KB Output is correct
7 Correct 6 ms 5120 KB Output is correct
8 Correct 6 ms 5248 KB Output is correct
9 Correct 7 ms 5248 KB Output is correct
10 Correct 5 ms 5120 KB Output is correct
11 Correct 4 ms 4992 KB Output is correct
12 Correct 6 ms 5248 KB Output is correct
13 Correct 4 ms 4992 KB Output is correct
14 Correct 4 ms 4992 KB Output is correct
15 Correct 10 ms 5376 KB Output is correct
16 Correct 5 ms 5120 KB Output is correct
17 Correct 4 ms 5152 KB Output is correct
18 Correct 6 ms 5120 KB Output is correct
19 Correct 5 ms 5120 KB Output is correct
20 Runtime error 12 ms 10368 KB Execution killed with signal 11
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4992 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Correct 3 ms 4992 KB Output is correct
4 Correct 3 ms 4992 KB Output is correct
5 Correct 4 ms 4992 KB Output is correct
6 Correct 5 ms 5120 KB Output is correct
7 Correct 6 ms 5120 KB Output is correct
8 Correct 6 ms 5248 KB Output is correct
9 Correct 7 ms 5248 KB Output is correct
10 Correct 5 ms 5120 KB Output is correct
11 Correct 4 ms 4992 KB Output is correct
12 Correct 6 ms 5248 KB Output is correct
13 Correct 4 ms 4992 KB Output is correct
14 Correct 4 ms 4992 KB Output is correct
15 Correct 10 ms 5376 KB Output is correct
16 Correct 5 ms 5120 KB Output is correct
17 Correct 4 ms 5152 KB Output is correct
18 Correct 6 ms 5120 KB Output is correct
19 Correct 5 ms 5120 KB Output is correct
20 Runtime error 12 ms 10368 KB Execution killed with signal 11
21 Halted 0 ms 0 KB -