답안 #251221

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
251221 2020-07-20T15:45:21 Z teee 족보 (KOI18_family) C++14
100 / 100
551 ms 81996 KB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int par[300'010];
int sz[300'010];
int kk;
int find(int n){
    return par[n]?par[n]=find(par[n]):n;
}
void merge(int a,int b){
    a=find(a);
    b=find(b);
    if(a^b){
        sz[a]+=sz[b];
        par[b]=a;
    }
}
vector<int> v[2][300'010];
vector<pair<int,pair<int,vector<int>>>> check;
pair<int,int> dfs(int n,int idx){
    if(n&&n<=kk){
        sz[n]=1;
        return {1,n};
    }
    int cnt=0;
    vector<int> t;
    int c=0;
    for(auto i:v[idx][n]){
        pair<int,int> k=dfs(i,idx);
        if(k.first>0) {
            cnt += k.first;
            t.push_back(k.second);
            c = k.second;
        }
    }
    if(cnt>1)check.push_back({cnt,{-t.size(),t}});
    return {cnt,c};
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n1,n2,a;
    cin>>n1>>n2>>kk;
    for(int i=1;i<=n1;i++){
        cin>>a;
        v[0][a].push_back(i);
    }
    for(int i=1;i<=n2;i++){
        cin>>a;
        v[1][a].push_back(i);
    }
    dfs(0,0);
    dfs(0,1);
    sort(check.begin(),check.end());
    for(const auto& i:check){
        vector<int> t=i.second.second;
        int cnt=i.first;
        int p=find(t[0]);
        for(auto j:t){
            merge(p,j);
        }
        if(sz[find(p)]!=cnt){
            cout<<"NO";return 0;
        }
    }
    cout<<"YES";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 14464 KB Output is correct
2 Correct 9 ms 14464 KB Output is correct
3 Correct 10 ms 14464 KB Output is correct
4 Correct 11 ms 14440 KB Output is correct
5 Correct 10 ms 14464 KB Output is correct
6 Correct 8 ms 14464 KB Output is correct
7 Correct 11 ms 14464 KB Output is correct
8 Correct 10 ms 14464 KB Output is correct
9 Correct 12 ms 14464 KB Output is correct
10 Correct 9 ms 14464 KB Output is correct
11 Correct 9 ms 14464 KB Output is correct
12 Correct 14 ms 14440 KB Output is correct
13 Correct 12 ms 14464 KB Output is correct
14 Correct 11 ms 14464 KB Output is correct
15 Correct 12 ms 14464 KB Output is correct
16 Correct 13 ms 14464 KB Output is correct
17 Correct 9 ms 14464 KB Output is correct
18 Correct 11 ms 14464 KB Output is correct
19 Correct 12 ms 14464 KB Output is correct
20 Correct 12 ms 14464 KB Output is correct
21 Correct 10 ms 14464 KB Output is correct
22 Correct 9 ms 14464 KB Output is correct
23 Correct 8 ms 14464 KB Output is correct
24 Correct 11 ms 14464 KB Output is correct
25 Correct 8 ms 14464 KB Output is correct
26 Correct 11 ms 14464 KB Output is correct
27 Correct 9 ms 14464 KB Output is correct
28 Correct 9 ms 14464 KB Output is correct
29 Correct 9 ms 14464 KB Output is correct
30 Correct 9 ms 14464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 14464 KB Output is correct
2 Correct 9 ms 14464 KB Output is correct
3 Correct 10 ms 14464 KB Output is correct
4 Correct 11 ms 14440 KB Output is correct
5 Correct 10 ms 14464 KB Output is correct
6 Correct 8 ms 14464 KB Output is correct
7 Correct 11 ms 14464 KB Output is correct
8 Correct 10 ms 14464 KB Output is correct
9 Correct 12 ms 14464 KB Output is correct
10 Correct 9 ms 14464 KB Output is correct
11 Correct 9 ms 14464 KB Output is correct
12 Correct 14 ms 14440 KB Output is correct
13 Correct 12 ms 14464 KB Output is correct
14 Correct 11 ms 14464 KB Output is correct
15 Correct 12 ms 14464 KB Output is correct
16 Correct 13 ms 14464 KB Output is correct
17 Correct 9 ms 14464 KB Output is correct
18 Correct 11 ms 14464 KB Output is correct
19 Correct 12 ms 14464 KB Output is correct
20 Correct 12 ms 14464 KB Output is correct
21 Correct 10 ms 14464 KB Output is correct
22 Correct 9 ms 14464 KB Output is correct
23 Correct 8 ms 14464 KB Output is correct
24 Correct 11 ms 14464 KB Output is correct
25 Correct 8 ms 14464 KB Output is correct
26 Correct 11 ms 14464 KB Output is correct
27 Correct 9 ms 14464 KB Output is correct
28 Correct 9 ms 14464 KB Output is correct
29 Correct 9 ms 14464 KB Output is correct
30 Correct 9 ms 14464 KB Output is correct
31 Correct 9 ms 14368 KB Output is correct
32 Correct 9 ms 14464 KB Output is correct
33 Correct 9 ms 14464 KB Output is correct
34 Correct 9 ms 14464 KB Output is correct
35 Correct 9 ms 14464 KB Output is correct
36 Correct 10 ms 14504 KB Output is correct
37 Correct 9 ms 14464 KB Output is correct
38 Correct 9 ms 14464 KB Output is correct
39 Correct 9 ms 14464 KB Output is correct
40 Correct 9 ms 14464 KB Output is correct
41 Correct 9 ms 14464 KB Output is correct
42 Correct 9 ms 14464 KB Output is correct
43 Correct 9 ms 14464 KB Output is correct
44 Correct 9 ms 14464 KB Output is correct
45 Correct 9 ms 14464 KB Output is correct
46 Correct 9 ms 14464 KB Output is correct
47 Correct 9 ms 14464 KB Output is correct
48 Correct 9 ms 14464 KB Output is correct
49 Correct 9 ms 14464 KB Output is correct
50 Correct 9 ms 14464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 14464 KB Output is correct
2 Correct 9 ms 14464 KB Output is correct
3 Correct 10 ms 14464 KB Output is correct
4 Correct 11 ms 14440 KB Output is correct
5 Correct 10 ms 14464 KB Output is correct
6 Correct 8 ms 14464 KB Output is correct
7 Correct 11 ms 14464 KB Output is correct
8 Correct 10 ms 14464 KB Output is correct
9 Correct 12 ms 14464 KB Output is correct
10 Correct 9 ms 14464 KB Output is correct
11 Correct 9 ms 14464 KB Output is correct
12 Correct 14 ms 14440 KB Output is correct
13 Correct 12 ms 14464 KB Output is correct
14 Correct 11 ms 14464 KB Output is correct
15 Correct 12 ms 14464 KB Output is correct
16 Correct 13 ms 14464 KB Output is correct
17 Correct 9 ms 14464 KB Output is correct
18 Correct 11 ms 14464 KB Output is correct
19 Correct 12 ms 14464 KB Output is correct
20 Correct 12 ms 14464 KB Output is correct
21 Correct 10 ms 14464 KB Output is correct
22 Correct 9 ms 14464 KB Output is correct
23 Correct 8 ms 14464 KB Output is correct
24 Correct 11 ms 14464 KB Output is correct
25 Correct 8 ms 14464 KB Output is correct
26 Correct 11 ms 14464 KB Output is correct
27 Correct 9 ms 14464 KB Output is correct
28 Correct 9 ms 14464 KB Output is correct
29 Correct 9 ms 14464 KB Output is correct
30 Correct 9 ms 14464 KB Output is correct
31 Correct 9 ms 14368 KB Output is correct
32 Correct 9 ms 14464 KB Output is correct
33 Correct 9 ms 14464 KB Output is correct
34 Correct 9 ms 14464 KB Output is correct
35 Correct 9 ms 14464 KB Output is correct
36 Correct 10 ms 14504 KB Output is correct
37 Correct 9 ms 14464 KB Output is correct
38 Correct 9 ms 14464 KB Output is correct
39 Correct 9 ms 14464 KB Output is correct
40 Correct 9 ms 14464 KB Output is correct
41 Correct 9 ms 14464 KB Output is correct
42 Correct 9 ms 14464 KB Output is correct
43 Correct 9 ms 14464 KB Output is correct
44 Correct 9 ms 14464 KB Output is correct
45 Correct 9 ms 14464 KB Output is correct
46 Correct 9 ms 14464 KB Output is correct
47 Correct 9 ms 14464 KB Output is correct
48 Correct 9 ms 14464 KB Output is correct
49 Correct 9 ms 14464 KB Output is correct
50 Correct 9 ms 14464 KB Output is correct
51 Correct 11 ms 14720 KB Output is correct
52 Correct 13 ms 14848 KB Output is correct
53 Correct 15 ms 14976 KB Output is correct
54 Correct 11 ms 14720 KB Output is correct
55 Correct 12 ms 14592 KB Output is correct
56 Correct 10 ms 14720 KB Output is correct
57 Correct 13 ms 14720 KB Output is correct
58 Correct 12 ms 14720 KB Output is correct
59 Correct 12 ms 14720 KB Output is correct
60 Correct 10 ms 14592 KB Output is correct
61 Correct 14 ms 15584 KB Output is correct
62 Correct 13 ms 15584 KB Output is correct
63 Correct 11 ms 14704 KB Output is correct
64 Correct 11 ms 14720 KB Output is correct
65 Correct 10 ms 14464 KB Output is correct
66 Correct 12 ms 14848 KB Output is correct
67 Correct 12 ms 14696 KB Output is correct
68 Correct 13 ms 14848 KB Output is correct
69 Correct 14 ms 14976 KB Output is correct
70 Correct 10 ms 14592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 14464 KB Output is correct
2 Correct 9 ms 14464 KB Output is correct
3 Correct 10 ms 14464 KB Output is correct
4 Correct 11 ms 14440 KB Output is correct
5 Correct 10 ms 14464 KB Output is correct
6 Correct 8 ms 14464 KB Output is correct
7 Correct 11 ms 14464 KB Output is correct
8 Correct 10 ms 14464 KB Output is correct
9 Correct 12 ms 14464 KB Output is correct
10 Correct 9 ms 14464 KB Output is correct
11 Correct 9 ms 14464 KB Output is correct
12 Correct 14 ms 14440 KB Output is correct
13 Correct 12 ms 14464 KB Output is correct
14 Correct 11 ms 14464 KB Output is correct
15 Correct 12 ms 14464 KB Output is correct
16 Correct 13 ms 14464 KB Output is correct
17 Correct 9 ms 14464 KB Output is correct
18 Correct 11 ms 14464 KB Output is correct
19 Correct 12 ms 14464 KB Output is correct
20 Correct 12 ms 14464 KB Output is correct
21 Correct 10 ms 14464 KB Output is correct
22 Correct 9 ms 14464 KB Output is correct
23 Correct 8 ms 14464 KB Output is correct
24 Correct 11 ms 14464 KB Output is correct
25 Correct 8 ms 14464 KB Output is correct
26 Correct 11 ms 14464 KB Output is correct
27 Correct 9 ms 14464 KB Output is correct
28 Correct 9 ms 14464 KB Output is correct
29 Correct 9 ms 14464 KB Output is correct
30 Correct 9 ms 14464 KB Output is correct
31 Correct 9 ms 14368 KB Output is correct
32 Correct 9 ms 14464 KB Output is correct
33 Correct 9 ms 14464 KB Output is correct
34 Correct 9 ms 14464 KB Output is correct
35 Correct 9 ms 14464 KB Output is correct
36 Correct 10 ms 14504 KB Output is correct
37 Correct 9 ms 14464 KB Output is correct
38 Correct 9 ms 14464 KB Output is correct
39 Correct 9 ms 14464 KB Output is correct
40 Correct 9 ms 14464 KB Output is correct
41 Correct 9 ms 14464 KB Output is correct
42 Correct 9 ms 14464 KB Output is correct
43 Correct 9 ms 14464 KB Output is correct
44 Correct 9 ms 14464 KB Output is correct
45 Correct 9 ms 14464 KB Output is correct
46 Correct 9 ms 14464 KB Output is correct
47 Correct 9 ms 14464 KB Output is correct
48 Correct 9 ms 14464 KB Output is correct
49 Correct 9 ms 14464 KB Output is correct
50 Correct 9 ms 14464 KB Output is correct
51 Correct 11 ms 14720 KB Output is correct
52 Correct 13 ms 14848 KB Output is correct
53 Correct 15 ms 14976 KB Output is correct
54 Correct 11 ms 14720 KB Output is correct
55 Correct 12 ms 14592 KB Output is correct
56 Correct 10 ms 14720 KB Output is correct
57 Correct 13 ms 14720 KB Output is correct
58 Correct 12 ms 14720 KB Output is correct
59 Correct 12 ms 14720 KB Output is correct
60 Correct 10 ms 14592 KB Output is correct
61 Correct 14 ms 15584 KB Output is correct
62 Correct 13 ms 15584 KB Output is correct
63 Correct 11 ms 14704 KB Output is correct
64 Correct 11 ms 14720 KB Output is correct
65 Correct 10 ms 14464 KB Output is correct
66 Correct 12 ms 14848 KB Output is correct
67 Correct 12 ms 14696 KB Output is correct
68 Correct 13 ms 14848 KB Output is correct
69 Correct 14 ms 14976 KB Output is correct
70 Correct 10 ms 14592 KB Output is correct
71 Correct 65 ms 21004 KB Output is correct
72 Correct 57 ms 20200 KB Output is correct
73 Correct 38 ms 18700 KB Output is correct
74 Correct 57 ms 22136 KB Output is correct
75 Correct 62 ms 23692 KB Output is correct
76 Correct 391 ms 64648 KB Output is correct
77 Correct 551 ms 68272 KB Output is correct
78 Correct 261 ms 39260 KB Output is correct
79 Correct 393 ms 66032 KB Output is correct
80 Correct 424 ms 66416 KB Output is correct
81 Correct 62 ms 21004 KB Output is correct
82 Correct 52 ms 20108 KB Output is correct
83 Correct 36 ms 18828 KB Output is correct
84 Correct 53 ms 21368 KB Output is correct
85 Correct 58 ms 23564 KB Output is correct
86 Correct 422 ms 81996 KB Output is correct
87 Correct 360 ms 81996 KB Output is correct
88 Correct 232 ms 39264 KB Output is correct
89 Correct 351 ms 64624 KB Output is correct
90 Correct 368 ms 66864 KB Output is correct