답안 #292723

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
292723 2020-09-07T12:19:58 Z 문홍윤(#5817) 서류 전달 (ROI16_sending) C++17
56 / 100
5000 ms 22520 KB
#include <bits/stdc++.h>
#define mp make_pair
#define eb emplace_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define svec(x) sort(all(x))
#define press(x) x.erase(unique(all(x)), x.end);
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<int, LL> pil;
typedef pair<LL, int> pli;
typedef pair<LL, LL> pll;
const int INF=1e9;
const LL LLINF=1e18;

int n, k;
vector<int> link[200010];

int sz[200010], p[200010], col[200010], tp[200010], c;
int eul[200010], re;

void dfs1(int num){
    sz[num]=1;
    for(auto i:link[num]){
        dfs1(i);
        sz[num]+=sz[i];
    }
}
bool cmp(int a, int b){return sz[a]>sz[b];}
void dfs2(int num, int cl){
    sort(all(link[num]), cmp);
    col[num]=cl;
    eul[num]=++re;
    bool flg=false;
    for(auto i:link[num]){
        if(flg){
            tp[++c]=i;
            dfs2(i, c);
        }
        else dfs2(i, cl);
        flg=true;
    }
}

int lca(int a, int b){
    if(col[a]==col[b]){
        if(eul[a]<=eul[b])return a;
        return b;
    }
    if(col[a]>col[b])swap(a, b);
    return lca(a, p[tp[col[b]]]);
}
vector<pii> query(int a, int b){
    vector<pii> vc;
    int l=lca(a, b);
    while(1){
        if(col[a]==col[l]){
            if(a!=l)vc.eb(eul[l]+1, eul[a]);
            break;
        }
        vc.eb(eul[tp[col[a]]], eul[a]);
        a=p[tp[col[a]]];
    }
    while(1){
        if(col[b]==col[l]){
            if(b!=l)vc.eb(eul[l]+1, eul[b]);
            break;
        }
        vc.eb(eul[tp[col[b]]], eul[b]);
        b=p[tp[col[b]]];
    }
    svec(vc);
    return vc;
}
int find_cross(vector<pii> a, vector<pii> b){
    int pa=0, pb=0, ret=0;
    while(pa<a.size()&&pb<b.size()){
        ret+=max(0, min(a[pa].S, b[pb].S)-max(a[pa].F, b[pb].F)+1);
        if(a[pa].S<b[pb].S)pa++;
        else pb++;
    }
    return ret;
}

vector<pii> pth[200010];
int ans, ans1, ans2;

int main(){
    scanf("%d %d", &n, &k);
    for(int i=2; i<=n; i++){
        scanf("%d", &p[i]);
        link[p[i]].eb(i);
    }
    dfs1(1);
    tp[++c]=1;
    dfs2(1, c);
    for(int i=1; i<=k; i++){
        int a, b;
        scanf("%d %d", &a, &b);
        pth[i]=query(a, b);
    }
    for(int i=1; i<=k; i++){
        for(int j=i+1; j<=k; j++){
            int tmp=find_cross(pth[i], pth[j]);
            if(ans<=tmp)ans=tmp, ans1=i, ans2=j;
        }
    }
    printf("%d\n%d %d", ans, ans1, ans2);
}

Compilation message

sending.cpp: In function 'int find_cross(std::vector<std::pair<int, int> >, std::vector<std::pair<int, int> >)':
sending.cpp:79:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |     while(pa<a.size()&&pb<b.size()){
      |           ~~^~~~~~~~~
sending.cpp:79:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |     while(pa<a.size()&&pb<b.size()){
      |                        ~~^~~~~~~~~
sending.cpp: In function 'int main()':
sending.cpp:91:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   91 |     scanf("%d %d", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~
sending.cpp:93:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   93 |         scanf("%d", &p[i]);
      |         ~~~~~^~~~~~~~~~~~~
sending.cpp:101:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  101 |         scanf("%d %d", &a, &b);
      |         ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9728 KB Output is correct
2 Correct 7 ms 9728 KB Output is correct
3 Correct 7 ms 9728 KB Output is correct
4 Correct 7 ms 9728 KB Output is correct
5 Correct 7 ms 9728 KB Output is correct
6 Correct 7 ms 9728 KB Output is correct
7 Correct 7 ms 9728 KB Output is correct
8 Correct 7 ms 9728 KB Output is correct
9 Correct 7 ms 9728 KB Output is correct
10 Correct 9 ms 9728 KB Output is correct
11 Correct 7 ms 9728 KB Output is correct
12 Correct 8 ms 9728 KB Output is correct
13 Correct 7 ms 9728 KB Output is correct
14 Correct 9 ms 9728 KB Output is correct
15 Correct 7 ms 9728 KB Output is correct
16 Correct 7 ms 9728 KB Output is correct
17 Correct 7 ms 9728 KB Output is correct
18 Correct 7 ms 9728 KB Output is correct
19 Correct 8 ms 9728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9728 KB Output is correct
2 Correct 7 ms 9728 KB Output is correct
3 Correct 7 ms 9728 KB Output is correct
4 Correct 7 ms 9728 KB Output is correct
5 Correct 7 ms 9728 KB Output is correct
6 Correct 7 ms 9728 KB Output is correct
7 Correct 7 ms 9728 KB Output is correct
8 Correct 7 ms 9728 KB Output is correct
9 Correct 7 ms 9728 KB Output is correct
10 Correct 9 ms 9728 KB Output is correct
11 Correct 7 ms 9728 KB Output is correct
12 Correct 8 ms 9728 KB Output is correct
13 Correct 7 ms 9728 KB Output is correct
14 Correct 9 ms 9728 KB Output is correct
15 Correct 7 ms 9728 KB Output is correct
16 Correct 7 ms 9728 KB Output is correct
17 Correct 7 ms 9728 KB Output is correct
18 Correct 7 ms 9728 KB Output is correct
19 Correct 8 ms 9728 KB Output is correct
20 Correct 72 ms 9984 KB Output is correct
21 Correct 74 ms 10104 KB Output is correct
22 Correct 54 ms 10240 KB Output is correct
23 Correct 53 ms 10112 KB Output is correct
24 Correct 53 ms 10104 KB Output is correct
25 Correct 53 ms 9856 KB Output is correct
26 Correct 49 ms 10240 KB Output is correct
27 Correct 64 ms 9856 KB Output is correct
28 Correct 89 ms 9984 KB Output is correct
29 Correct 50 ms 10240 KB Output is correct
30 Correct 17 ms 10240 KB Output is correct
31 Correct 18 ms 10240 KB Output is correct
32 Correct 48 ms 10240 KB Output is correct
33 Correct 63 ms 10232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9728 KB Output is correct
2 Correct 7 ms 9728 KB Output is correct
3 Correct 7 ms 9728 KB Output is correct
4 Correct 7 ms 9728 KB Output is correct
5 Correct 7 ms 9728 KB Output is correct
6 Correct 7 ms 9728 KB Output is correct
7 Correct 7 ms 9728 KB Output is correct
8 Correct 7 ms 9728 KB Output is correct
9 Correct 7 ms 9728 KB Output is correct
10 Correct 9 ms 9728 KB Output is correct
11 Correct 7 ms 9728 KB Output is correct
12 Correct 8 ms 9728 KB Output is correct
13 Correct 7 ms 9728 KB Output is correct
14 Correct 9 ms 9728 KB Output is correct
15 Correct 7 ms 9728 KB Output is correct
16 Correct 7 ms 9728 KB Output is correct
17 Correct 7 ms 9728 KB Output is correct
18 Correct 7 ms 9728 KB Output is correct
19 Correct 8 ms 9728 KB Output is correct
20 Correct 72 ms 9984 KB Output is correct
21 Correct 74 ms 10104 KB Output is correct
22 Correct 54 ms 10240 KB Output is correct
23 Correct 53 ms 10112 KB Output is correct
24 Correct 53 ms 10104 KB Output is correct
25 Correct 53 ms 9856 KB Output is correct
26 Correct 49 ms 10240 KB Output is correct
27 Correct 64 ms 9856 KB Output is correct
28 Correct 89 ms 9984 KB Output is correct
29 Correct 50 ms 10240 KB Output is correct
30 Correct 17 ms 10240 KB Output is correct
31 Correct 18 ms 10240 KB Output is correct
32 Correct 48 ms 10240 KB Output is correct
33 Correct 63 ms 10232 KB Output is correct
34 Correct 126 ms 13176 KB Output is correct
35 Correct 130 ms 13432 KB Output is correct
36 Correct 79 ms 22264 KB Output is correct
37 Correct 86 ms 18408 KB Output is correct
38 Correct 80 ms 17016 KB Output is correct
39 Correct 70 ms 12144 KB Output is correct
40 Correct 79 ms 22264 KB Output is correct
41 Correct 87 ms 12288 KB Output is correct
42 Correct 139 ms 13276 KB Output is correct
43 Correct 85 ms 21240 KB Output is correct
44 Correct 54 ms 21240 KB Output is correct
45 Correct 53 ms 21240 KB Output is correct
46 Correct 85 ms 21240 KB Output is correct
47 Correct 91 ms 14464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9728 KB Output is correct
2 Correct 7 ms 9728 KB Output is correct
3 Correct 7 ms 9728 KB Output is correct
4 Correct 7 ms 9728 KB Output is correct
5 Correct 7 ms 9728 KB Output is correct
6 Correct 7 ms 9728 KB Output is correct
7 Correct 7 ms 9728 KB Output is correct
8 Correct 7 ms 9728 KB Output is correct
9 Correct 7 ms 9728 KB Output is correct
10 Correct 9 ms 9728 KB Output is correct
11 Correct 7 ms 9728 KB Output is correct
12 Correct 8 ms 9728 KB Output is correct
13 Correct 7 ms 9728 KB Output is correct
14 Correct 9 ms 9728 KB Output is correct
15 Correct 7 ms 9728 KB Output is correct
16 Correct 7 ms 9728 KB Output is correct
17 Correct 7 ms 9728 KB Output is correct
18 Correct 7 ms 9728 KB Output is correct
19 Correct 8 ms 9728 KB Output is correct
20 Correct 72 ms 9984 KB Output is correct
21 Correct 74 ms 10104 KB Output is correct
22 Correct 54 ms 10240 KB Output is correct
23 Correct 53 ms 10112 KB Output is correct
24 Correct 53 ms 10104 KB Output is correct
25 Correct 53 ms 9856 KB Output is correct
26 Correct 49 ms 10240 KB Output is correct
27 Correct 64 ms 9856 KB Output is correct
28 Correct 89 ms 9984 KB Output is correct
29 Correct 50 ms 10240 KB Output is correct
30 Correct 17 ms 10240 KB Output is correct
31 Correct 18 ms 10240 KB Output is correct
32 Correct 48 ms 10240 KB Output is correct
33 Correct 63 ms 10232 KB Output is correct
34 Correct 126 ms 13176 KB Output is correct
35 Correct 130 ms 13432 KB Output is correct
36 Correct 79 ms 22264 KB Output is correct
37 Correct 86 ms 18408 KB Output is correct
38 Correct 80 ms 17016 KB Output is correct
39 Correct 70 ms 12144 KB Output is correct
40 Correct 79 ms 22264 KB Output is correct
41 Correct 87 ms 12288 KB Output is correct
42 Correct 139 ms 13276 KB Output is correct
43 Correct 85 ms 21240 KB Output is correct
44 Correct 54 ms 21240 KB Output is correct
45 Correct 53 ms 21240 KB Output is correct
46 Correct 85 ms 21240 KB Output is correct
47 Correct 91 ms 14464 KB Output is correct
48 Correct 1783 ms 13692 KB Output is correct
49 Correct 1919 ms 13944 KB Output is correct
50 Correct 1045 ms 22392 KB Output is correct
51 Correct 1143 ms 18536 KB Output is correct
52 Correct 1168 ms 17192 KB Output is correct
53 Correct 1200 ms 12420 KB Output is correct
54 Correct 1044 ms 22520 KB Output is correct
55 Correct 1482 ms 12792 KB Output is correct
56 Correct 2563 ms 13948 KB Output is correct
57 Correct 1099 ms 21448 KB Output is correct
58 Correct 319 ms 21240 KB Output is correct
59 Correct 293 ms 21368 KB Output is correct
60 Correct 1078 ms 21496 KB Output is correct
61 Correct 1392 ms 20816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5055 ms 19704 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5048 ms 15480 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9728 KB Output is correct
2 Correct 7 ms 9728 KB Output is correct
3 Correct 7 ms 9728 KB Output is correct
4 Correct 7 ms 9728 KB Output is correct
5 Correct 7 ms 9728 KB Output is correct
6 Correct 7 ms 9728 KB Output is correct
7 Correct 7 ms 9728 KB Output is correct
8 Correct 7 ms 9728 KB Output is correct
9 Correct 7 ms 9728 KB Output is correct
10 Correct 9 ms 9728 KB Output is correct
11 Correct 7 ms 9728 KB Output is correct
12 Correct 8 ms 9728 KB Output is correct
13 Correct 7 ms 9728 KB Output is correct
14 Correct 9 ms 9728 KB Output is correct
15 Correct 7 ms 9728 KB Output is correct
16 Correct 7 ms 9728 KB Output is correct
17 Correct 7 ms 9728 KB Output is correct
18 Correct 7 ms 9728 KB Output is correct
19 Correct 8 ms 9728 KB Output is correct
20 Correct 72 ms 9984 KB Output is correct
21 Correct 74 ms 10104 KB Output is correct
22 Correct 54 ms 10240 KB Output is correct
23 Correct 53 ms 10112 KB Output is correct
24 Correct 53 ms 10104 KB Output is correct
25 Correct 53 ms 9856 KB Output is correct
26 Correct 49 ms 10240 KB Output is correct
27 Correct 64 ms 9856 KB Output is correct
28 Correct 89 ms 9984 KB Output is correct
29 Correct 50 ms 10240 KB Output is correct
30 Correct 17 ms 10240 KB Output is correct
31 Correct 18 ms 10240 KB Output is correct
32 Correct 48 ms 10240 KB Output is correct
33 Correct 63 ms 10232 KB Output is correct
34 Correct 126 ms 13176 KB Output is correct
35 Correct 130 ms 13432 KB Output is correct
36 Correct 79 ms 22264 KB Output is correct
37 Correct 86 ms 18408 KB Output is correct
38 Correct 80 ms 17016 KB Output is correct
39 Correct 70 ms 12144 KB Output is correct
40 Correct 79 ms 22264 KB Output is correct
41 Correct 87 ms 12288 KB Output is correct
42 Correct 139 ms 13276 KB Output is correct
43 Correct 85 ms 21240 KB Output is correct
44 Correct 54 ms 21240 KB Output is correct
45 Correct 53 ms 21240 KB Output is correct
46 Correct 85 ms 21240 KB Output is correct
47 Correct 91 ms 14464 KB Output is correct
48 Correct 1783 ms 13692 KB Output is correct
49 Correct 1919 ms 13944 KB Output is correct
50 Correct 1045 ms 22392 KB Output is correct
51 Correct 1143 ms 18536 KB Output is correct
52 Correct 1168 ms 17192 KB Output is correct
53 Correct 1200 ms 12420 KB Output is correct
54 Correct 1044 ms 22520 KB Output is correct
55 Correct 1482 ms 12792 KB Output is correct
56 Correct 2563 ms 13948 KB Output is correct
57 Correct 1099 ms 21448 KB Output is correct
58 Correct 319 ms 21240 KB Output is correct
59 Correct 293 ms 21368 KB Output is correct
60 Correct 1078 ms 21496 KB Output is correct
61 Correct 1392 ms 20816 KB Output is correct
62 Execution timed out 5055 ms 19704 KB Time limit exceeded
63 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9728 KB Output is correct
2 Correct 7 ms 9728 KB Output is correct
3 Correct 7 ms 9728 KB Output is correct
4 Correct 7 ms 9728 KB Output is correct
5 Correct 7 ms 9728 KB Output is correct
6 Correct 7 ms 9728 KB Output is correct
7 Correct 7 ms 9728 KB Output is correct
8 Correct 7 ms 9728 KB Output is correct
9 Correct 7 ms 9728 KB Output is correct
10 Correct 9 ms 9728 KB Output is correct
11 Correct 7 ms 9728 KB Output is correct
12 Correct 8 ms 9728 KB Output is correct
13 Correct 7 ms 9728 KB Output is correct
14 Correct 9 ms 9728 KB Output is correct
15 Correct 7 ms 9728 KB Output is correct
16 Correct 7 ms 9728 KB Output is correct
17 Correct 7 ms 9728 KB Output is correct
18 Correct 7 ms 9728 KB Output is correct
19 Correct 8 ms 9728 KB Output is correct
20 Correct 72 ms 9984 KB Output is correct
21 Correct 74 ms 10104 KB Output is correct
22 Correct 54 ms 10240 KB Output is correct
23 Correct 53 ms 10112 KB Output is correct
24 Correct 53 ms 10104 KB Output is correct
25 Correct 53 ms 9856 KB Output is correct
26 Correct 49 ms 10240 KB Output is correct
27 Correct 64 ms 9856 KB Output is correct
28 Correct 89 ms 9984 KB Output is correct
29 Correct 50 ms 10240 KB Output is correct
30 Correct 17 ms 10240 KB Output is correct
31 Correct 18 ms 10240 KB Output is correct
32 Correct 48 ms 10240 KB Output is correct
33 Correct 63 ms 10232 KB Output is correct
34 Correct 126 ms 13176 KB Output is correct
35 Correct 130 ms 13432 KB Output is correct
36 Correct 79 ms 22264 KB Output is correct
37 Correct 86 ms 18408 KB Output is correct
38 Correct 80 ms 17016 KB Output is correct
39 Correct 70 ms 12144 KB Output is correct
40 Correct 79 ms 22264 KB Output is correct
41 Correct 87 ms 12288 KB Output is correct
42 Correct 139 ms 13276 KB Output is correct
43 Correct 85 ms 21240 KB Output is correct
44 Correct 54 ms 21240 KB Output is correct
45 Correct 53 ms 21240 KB Output is correct
46 Correct 85 ms 21240 KB Output is correct
47 Correct 91 ms 14464 KB Output is correct
48 Correct 1783 ms 13692 KB Output is correct
49 Correct 1919 ms 13944 KB Output is correct
50 Correct 1045 ms 22392 KB Output is correct
51 Correct 1143 ms 18536 KB Output is correct
52 Correct 1168 ms 17192 KB Output is correct
53 Correct 1200 ms 12420 KB Output is correct
54 Correct 1044 ms 22520 KB Output is correct
55 Correct 1482 ms 12792 KB Output is correct
56 Correct 2563 ms 13948 KB Output is correct
57 Correct 1099 ms 21448 KB Output is correct
58 Correct 319 ms 21240 KB Output is correct
59 Correct 293 ms 21368 KB Output is correct
60 Correct 1078 ms 21496 KB Output is correct
61 Correct 1392 ms 20816 KB Output is correct
62 Execution timed out 5055 ms 19704 KB Time limit exceeded
63 Halted 0 ms 0 KB -