답안 #130372

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
130372 2019-07-15T05:01:30 Z red1108 족보 (KOI18_family) C++17
100 / 100
584 ms 74512 KB
#include <bits/stdc++.h>
using namespace std;
vector<int> tree[2][300010];
int par[300010], n1, n2, p, root1, root2;
int tsize[2][300010], sth[2][300010], siz[300010], depth[2][300010];
struct A{
    int siz, t, x, depth;
    bool operator <(const A c) const{
        if(c.siz==siz) return depth>c.depth;
        return siz<c.siz;
    }
};
vector<A> q;
void dfs(int t, int x){
    if(x<=p) tsize[t][x]=1;
    if(x<=p) sth[t][x]=x;
    for(auto i:tree[t][x]){
        depth[t][i]=depth[t][x]+1;
        dfs(t, i);
        tsize[t][x]+=tsize[t][i];
        if(sth[t][i]<=p) sth[t][x]=sth[t][i];
    }
}
int findpar(int x){
    if(x==par[x]) return x;
    return par[x]=findpar(par[x]);
}
void hap(int x, int y){
    if(findpar(x)==findpar(y)) return ;
    siz[findpar(y)]+=siz[findpar(x)];
    par[findpar(x)]=findpar(y);
}
int main(){
    int i;
    scanf("%d %d %d", &n1, &n2, &p);
    for(i=1;i<=n1;i++){
        int a;
        scanf("%d", &a);
        tree[0][a].push_back(i);
        if(a==0) root1=i;
    }
    for(i=1;i<=n2;i++){
        int a;
        scanf("%d", &a);
        tree[1][a].push_back(i);
        if(a==0) root2=i;
    }
    for(i=1;i<=p;i++) {
        par[i]=i;
        siz[i]=1;
    }
    dfs(0,root1);
    dfs(1,root2);
    for(i=p+1;i<=n1;i++) q.push_back({tsize[0][i],0,i,depth[0][i]});
    for(i=p+1;i<=n2;i++) q.push_back({tsize[1][i],1,i,depth[1][i]});
    sort(q.begin(), q.end());
    for(auto j:q){
        int x = j.x;
        int t = j.t;
        int fi=sth[t][tree[t][x][0]];
        for(auto i:tree[t][x])
            hap(fi,sth[t][i]);
        if(siz[findpar(fi)]!=tsize[t][x]){
            printf("NO");
            return 0;
        }
    }
    printf("YES");
}

Compilation message

family.cpp: In function 'int main()':
family.cpp:35:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d", &n1, &n2, &p);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
family.cpp:38:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &a);
         ~~~~~^~~~~~~~~~
family.cpp:44:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &a);
         ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 14460 KB Output is correct
2 Correct 15 ms 14456 KB Output is correct
3 Correct 15 ms 14456 KB Output is correct
4 Correct 15 ms 14456 KB Output is correct
5 Correct 15 ms 14456 KB Output is correct
6 Correct 22 ms 14456 KB Output is correct
7 Correct 15 ms 14456 KB Output is correct
8 Correct 15 ms 14456 KB Output is correct
9 Correct 15 ms 14584 KB Output is correct
10 Correct 15 ms 14456 KB Output is correct
11 Correct 15 ms 14456 KB Output is correct
12 Correct 15 ms 14456 KB Output is correct
13 Correct 15 ms 14456 KB Output is correct
14 Correct 15 ms 14584 KB Output is correct
15 Correct 16 ms 14456 KB Output is correct
16 Correct 15 ms 14584 KB Output is correct
17 Correct 15 ms 14456 KB Output is correct
18 Correct 15 ms 14456 KB Output is correct
19 Correct 16 ms 14456 KB Output is correct
20 Correct 15 ms 14456 KB Output is correct
21 Correct 15 ms 14460 KB Output is correct
22 Correct 16 ms 14456 KB Output is correct
23 Correct 15 ms 14456 KB Output is correct
24 Correct 15 ms 14584 KB Output is correct
25 Correct 15 ms 14456 KB Output is correct
26 Correct 15 ms 14428 KB Output is correct
27 Correct 15 ms 14404 KB Output is correct
28 Correct 15 ms 14456 KB Output is correct
29 Correct 19 ms 14456 KB Output is correct
30 Correct 15 ms 14456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 14460 KB Output is correct
2 Correct 15 ms 14456 KB Output is correct
3 Correct 15 ms 14456 KB Output is correct
4 Correct 15 ms 14456 KB Output is correct
5 Correct 15 ms 14456 KB Output is correct
6 Correct 22 ms 14456 KB Output is correct
7 Correct 15 ms 14456 KB Output is correct
8 Correct 15 ms 14456 KB Output is correct
9 Correct 15 ms 14584 KB Output is correct
10 Correct 15 ms 14456 KB Output is correct
11 Correct 15 ms 14456 KB Output is correct
12 Correct 15 ms 14456 KB Output is correct
13 Correct 15 ms 14456 KB Output is correct
14 Correct 15 ms 14584 KB Output is correct
15 Correct 16 ms 14456 KB Output is correct
16 Correct 15 ms 14584 KB Output is correct
17 Correct 15 ms 14456 KB Output is correct
18 Correct 15 ms 14456 KB Output is correct
19 Correct 16 ms 14456 KB Output is correct
20 Correct 15 ms 14456 KB Output is correct
21 Correct 15 ms 14460 KB Output is correct
22 Correct 16 ms 14456 KB Output is correct
23 Correct 15 ms 14456 KB Output is correct
24 Correct 15 ms 14584 KB Output is correct
25 Correct 15 ms 14456 KB Output is correct
26 Correct 15 ms 14428 KB Output is correct
27 Correct 15 ms 14404 KB Output is correct
28 Correct 15 ms 14456 KB Output is correct
29 Correct 19 ms 14456 KB Output is correct
30 Correct 15 ms 14456 KB Output is correct
31 Correct 16 ms 14584 KB Output is correct
32 Correct 18 ms 14456 KB Output is correct
33 Correct 18 ms 14456 KB Output is correct
34 Correct 15 ms 14456 KB Output is correct
35 Correct 16 ms 14456 KB Output is correct
36 Correct 32 ms 14456 KB Output is correct
37 Correct 15 ms 14456 KB Output is correct
38 Correct 15 ms 14456 KB Output is correct
39 Correct 15 ms 14584 KB Output is correct
40 Correct 15 ms 14584 KB Output is correct
41 Correct 15 ms 14460 KB Output is correct
42 Correct 15 ms 14456 KB Output is correct
43 Correct 18 ms 14456 KB Output is correct
44 Correct 23 ms 14456 KB Output is correct
45 Correct 16 ms 14456 KB Output is correct
46 Correct 15 ms 14456 KB Output is correct
47 Correct 15 ms 14456 KB Output is correct
48 Correct 16 ms 14456 KB Output is correct
49 Correct 15 ms 14584 KB Output is correct
50 Correct 15 ms 14456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 14460 KB Output is correct
2 Correct 15 ms 14456 KB Output is correct
3 Correct 15 ms 14456 KB Output is correct
4 Correct 15 ms 14456 KB Output is correct
5 Correct 15 ms 14456 KB Output is correct
6 Correct 22 ms 14456 KB Output is correct
7 Correct 15 ms 14456 KB Output is correct
8 Correct 15 ms 14456 KB Output is correct
9 Correct 15 ms 14584 KB Output is correct
10 Correct 15 ms 14456 KB Output is correct
11 Correct 15 ms 14456 KB Output is correct
12 Correct 15 ms 14456 KB Output is correct
13 Correct 15 ms 14456 KB Output is correct
14 Correct 15 ms 14584 KB Output is correct
15 Correct 16 ms 14456 KB Output is correct
16 Correct 15 ms 14584 KB Output is correct
17 Correct 15 ms 14456 KB Output is correct
18 Correct 15 ms 14456 KB Output is correct
19 Correct 16 ms 14456 KB Output is correct
20 Correct 15 ms 14456 KB Output is correct
21 Correct 15 ms 14460 KB Output is correct
22 Correct 16 ms 14456 KB Output is correct
23 Correct 15 ms 14456 KB Output is correct
24 Correct 15 ms 14584 KB Output is correct
25 Correct 15 ms 14456 KB Output is correct
26 Correct 15 ms 14428 KB Output is correct
27 Correct 15 ms 14404 KB Output is correct
28 Correct 15 ms 14456 KB Output is correct
29 Correct 19 ms 14456 KB Output is correct
30 Correct 15 ms 14456 KB Output is correct
31 Correct 16 ms 14584 KB Output is correct
32 Correct 18 ms 14456 KB Output is correct
33 Correct 18 ms 14456 KB Output is correct
34 Correct 15 ms 14456 KB Output is correct
35 Correct 16 ms 14456 KB Output is correct
36 Correct 32 ms 14456 KB Output is correct
37 Correct 15 ms 14456 KB Output is correct
38 Correct 15 ms 14456 KB Output is correct
39 Correct 15 ms 14584 KB Output is correct
40 Correct 15 ms 14584 KB Output is correct
41 Correct 15 ms 14460 KB Output is correct
42 Correct 15 ms 14456 KB Output is correct
43 Correct 18 ms 14456 KB Output is correct
44 Correct 23 ms 14456 KB Output is correct
45 Correct 16 ms 14456 KB Output is correct
46 Correct 15 ms 14456 KB Output is correct
47 Correct 15 ms 14456 KB Output is correct
48 Correct 16 ms 14456 KB Output is correct
49 Correct 15 ms 14584 KB Output is correct
50 Correct 15 ms 14456 KB Output is correct
51 Correct 17 ms 14840 KB Output is correct
52 Correct 18 ms 14840 KB Output is correct
53 Correct 18 ms 14968 KB Output is correct
54 Correct 18 ms 14840 KB Output is correct
55 Correct 17 ms 14712 KB Output is correct
56 Correct 17 ms 14712 KB Output is correct
57 Correct 17 ms 14712 KB Output is correct
58 Correct 18 ms 14816 KB Output is correct
59 Correct 17 ms 14840 KB Output is correct
60 Correct 17 ms 14712 KB Output is correct
61 Correct 19 ms 15224 KB Output is correct
62 Correct 19 ms 15224 KB Output is correct
63 Correct 17 ms 14712 KB Output is correct
64 Correct 17 ms 14796 KB Output is correct
65 Correct 16 ms 14584 KB Output is correct
66 Correct 18 ms 14840 KB Output is correct
67 Correct 18 ms 14712 KB Output is correct
68 Correct 18 ms 14924 KB Output is correct
69 Correct 18 ms 14844 KB Output is correct
70 Correct 19 ms 14840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 14460 KB Output is correct
2 Correct 15 ms 14456 KB Output is correct
3 Correct 15 ms 14456 KB Output is correct
4 Correct 15 ms 14456 KB Output is correct
5 Correct 15 ms 14456 KB Output is correct
6 Correct 22 ms 14456 KB Output is correct
7 Correct 15 ms 14456 KB Output is correct
8 Correct 15 ms 14456 KB Output is correct
9 Correct 15 ms 14584 KB Output is correct
10 Correct 15 ms 14456 KB Output is correct
11 Correct 15 ms 14456 KB Output is correct
12 Correct 15 ms 14456 KB Output is correct
13 Correct 15 ms 14456 KB Output is correct
14 Correct 15 ms 14584 KB Output is correct
15 Correct 16 ms 14456 KB Output is correct
16 Correct 15 ms 14584 KB Output is correct
17 Correct 15 ms 14456 KB Output is correct
18 Correct 15 ms 14456 KB Output is correct
19 Correct 16 ms 14456 KB Output is correct
20 Correct 15 ms 14456 KB Output is correct
21 Correct 15 ms 14460 KB Output is correct
22 Correct 16 ms 14456 KB Output is correct
23 Correct 15 ms 14456 KB Output is correct
24 Correct 15 ms 14584 KB Output is correct
25 Correct 15 ms 14456 KB Output is correct
26 Correct 15 ms 14428 KB Output is correct
27 Correct 15 ms 14404 KB Output is correct
28 Correct 15 ms 14456 KB Output is correct
29 Correct 19 ms 14456 KB Output is correct
30 Correct 15 ms 14456 KB Output is correct
31 Correct 16 ms 14584 KB Output is correct
32 Correct 18 ms 14456 KB Output is correct
33 Correct 18 ms 14456 KB Output is correct
34 Correct 15 ms 14456 KB Output is correct
35 Correct 16 ms 14456 KB Output is correct
36 Correct 32 ms 14456 KB Output is correct
37 Correct 15 ms 14456 KB Output is correct
38 Correct 15 ms 14456 KB Output is correct
39 Correct 15 ms 14584 KB Output is correct
40 Correct 15 ms 14584 KB Output is correct
41 Correct 15 ms 14460 KB Output is correct
42 Correct 15 ms 14456 KB Output is correct
43 Correct 18 ms 14456 KB Output is correct
44 Correct 23 ms 14456 KB Output is correct
45 Correct 16 ms 14456 KB Output is correct
46 Correct 15 ms 14456 KB Output is correct
47 Correct 15 ms 14456 KB Output is correct
48 Correct 16 ms 14456 KB Output is correct
49 Correct 15 ms 14584 KB Output is correct
50 Correct 15 ms 14456 KB Output is correct
51 Correct 17 ms 14840 KB Output is correct
52 Correct 18 ms 14840 KB Output is correct
53 Correct 18 ms 14968 KB Output is correct
54 Correct 18 ms 14840 KB Output is correct
55 Correct 17 ms 14712 KB Output is correct
56 Correct 17 ms 14712 KB Output is correct
57 Correct 17 ms 14712 KB Output is correct
58 Correct 18 ms 14816 KB Output is correct
59 Correct 17 ms 14840 KB Output is correct
60 Correct 17 ms 14712 KB Output is correct
61 Correct 19 ms 15224 KB Output is correct
62 Correct 19 ms 15224 KB Output is correct
63 Correct 17 ms 14712 KB Output is correct
64 Correct 17 ms 14796 KB Output is correct
65 Correct 16 ms 14584 KB Output is correct
66 Correct 18 ms 14840 KB Output is correct
67 Correct 18 ms 14712 KB Output is correct
68 Correct 18 ms 14924 KB Output is correct
69 Correct 18 ms 14844 KB Output is correct
70 Correct 19 ms 14840 KB Output is correct
71 Correct 66 ms 20572 KB Output is correct
72 Correct 59 ms 18932 KB Output is correct
73 Correct 47 ms 18424 KB Output is correct
74 Correct 83 ms 23404 KB Output is correct
75 Correct 87 ms 22408 KB Output is correct
76 Correct 577 ms 74512 KB Output is correct
77 Correct 584 ms 61652 KB Output is correct
78 Correct 293 ms 36068 KB Output is correct
79 Correct 478 ms 56288 KB Output is correct
80 Correct 523 ms 59344 KB Output is correct
81 Correct 62 ms 20588 KB Output is correct
82 Correct 56 ms 18932 KB Output is correct
83 Correct 42 ms 18416 KB Output is correct
84 Correct 78 ms 23148 KB Output is correct
85 Correct 85 ms 22584 KB Output is correct
86 Correct 366 ms 56412 KB Output is correct
87 Correct 366 ms 56256 KB Output is correct
88 Correct 258 ms 36068 KB Output is correct
89 Correct 464 ms 55520 KB Output is correct
90 Correct 491 ms 59528 KB Output is correct