답안 #251225

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
251225 2020-07-20T15:49:48 Z teee 족보 (KOI18_family) C++14
100 / 100
368 ms 64340 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,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&&t.size()>1)check.emplace_back(cnt,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;
        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 9 ms 14464 KB Output is correct
2 Correct 9 ms 14464 KB Output is correct
3 Correct 9 ms 14464 KB Output is correct
4 Correct 9 ms 14464 KB Output is correct
5 Correct 8 ms 14464 KB Output is correct
6 Correct 9 ms 14412 KB Output is correct
7 Correct 9 ms 14464 KB Output is correct
8 Correct 9 ms 14464 KB Output is correct
9 Correct 9 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 9 ms 14464 KB Output is correct
13 Correct 9 ms 14464 KB Output is correct
14 Correct 9 ms 14464 KB Output is correct
15 Correct 10 ms 14464 KB Output is correct
16 Correct 10 ms 14464 KB Output is correct
17 Correct 9 ms 14464 KB Output is correct
18 Correct 9 ms 14464 KB Output is correct
19 Correct 9 ms 14464 KB Output is correct
20 Correct 9 ms 14464 KB Output is correct
21 Correct 9 ms 14464 KB Output is correct
22 Correct 9 ms 14464 KB Output is correct
23 Correct 9 ms 14464 KB Output is correct
24 Correct 8 ms 14464 KB Output is correct
25 Correct 9 ms 14464 KB Output is correct
26 Correct 8 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 9 ms 14464 KB Output is correct
2 Correct 9 ms 14464 KB Output is correct
3 Correct 9 ms 14464 KB Output is correct
4 Correct 9 ms 14464 KB Output is correct
5 Correct 8 ms 14464 KB Output is correct
6 Correct 9 ms 14412 KB Output is correct
7 Correct 9 ms 14464 KB Output is correct
8 Correct 9 ms 14464 KB Output is correct
9 Correct 9 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 9 ms 14464 KB Output is correct
13 Correct 9 ms 14464 KB Output is correct
14 Correct 9 ms 14464 KB Output is correct
15 Correct 10 ms 14464 KB Output is correct
16 Correct 10 ms 14464 KB Output is correct
17 Correct 9 ms 14464 KB Output is correct
18 Correct 9 ms 14464 KB Output is correct
19 Correct 9 ms 14464 KB Output is correct
20 Correct 9 ms 14464 KB Output is correct
21 Correct 9 ms 14464 KB Output is correct
22 Correct 9 ms 14464 KB Output is correct
23 Correct 9 ms 14464 KB Output is correct
24 Correct 8 ms 14464 KB Output is correct
25 Correct 9 ms 14464 KB Output is correct
26 Correct 8 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 8 ms 14464 KB Output is correct
32 Correct 8 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 8 ms 14464 KB Output is correct
36 Correct 9 ms 14464 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 8 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 13 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 10 ms 14464 KB Output is correct
49 Correct 12 ms 14464 KB Output is correct
50 Correct 9 ms 14464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14464 KB Output is correct
2 Correct 9 ms 14464 KB Output is correct
3 Correct 9 ms 14464 KB Output is correct
4 Correct 9 ms 14464 KB Output is correct
5 Correct 8 ms 14464 KB Output is correct
6 Correct 9 ms 14412 KB Output is correct
7 Correct 9 ms 14464 KB Output is correct
8 Correct 9 ms 14464 KB Output is correct
9 Correct 9 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 9 ms 14464 KB Output is correct
13 Correct 9 ms 14464 KB Output is correct
14 Correct 9 ms 14464 KB Output is correct
15 Correct 10 ms 14464 KB Output is correct
16 Correct 10 ms 14464 KB Output is correct
17 Correct 9 ms 14464 KB Output is correct
18 Correct 9 ms 14464 KB Output is correct
19 Correct 9 ms 14464 KB Output is correct
20 Correct 9 ms 14464 KB Output is correct
21 Correct 9 ms 14464 KB Output is correct
22 Correct 9 ms 14464 KB Output is correct
23 Correct 9 ms 14464 KB Output is correct
24 Correct 8 ms 14464 KB Output is correct
25 Correct 9 ms 14464 KB Output is correct
26 Correct 8 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 8 ms 14464 KB Output is correct
32 Correct 8 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 8 ms 14464 KB Output is correct
36 Correct 9 ms 14464 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 8 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 13 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 10 ms 14464 KB Output is correct
49 Correct 12 ms 14464 KB Output is correct
50 Correct 9 ms 14464 KB Output is correct
51 Correct 10 ms 14592 KB Output is correct
52 Correct 16 ms 14720 KB Output is correct
53 Correct 12 ms 14848 KB Output is correct
54 Correct 10 ms 14720 KB Output is correct
55 Correct 10 ms 14592 KB Output is correct
56 Correct 11 ms 14592 KB Output is correct
57 Correct 10 ms 14592 KB Output is correct
58 Correct 11 ms 14720 KB Output is correct
59 Correct 11 ms 14592 KB Output is correct
60 Correct 11 ms 14592 KB Output is correct
61 Correct 12 ms 15360 KB Output is correct
62 Correct 12 ms 15360 KB Output is correct
63 Correct 10 ms 14592 KB Output is correct
64 Correct 10 ms 14592 KB Output is correct
65 Correct 9 ms 14464 KB Output is correct
66 Correct 12 ms 14720 KB Output is correct
67 Correct 10 ms 14592 KB Output is correct
68 Correct 11 ms 14720 KB Output is correct
69 Correct 12 ms 14848 KB Output is correct
70 Correct 10 ms 14652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14464 KB Output is correct
2 Correct 9 ms 14464 KB Output is correct
3 Correct 9 ms 14464 KB Output is correct
4 Correct 9 ms 14464 KB Output is correct
5 Correct 8 ms 14464 KB Output is correct
6 Correct 9 ms 14412 KB Output is correct
7 Correct 9 ms 14464 KB Output is correct
8 Correct 9 ms 14464 KB Output is correct
9 Correct 9 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 9 ms 14464 KB Output is correct
13 Correct 9 ms 14464 KB Output is correct
14 Correct 9 ms 14464 KB Output is correct
15 Correct 10 ms 14464 KB Output is correct
16 Correct 10 ms 14464 KB Output is correct
17 Correct 9 ms 14464 KB Output is correct
18 Correct 9 ms 14464 KB Output is correct
19 Correct 9 ms 14464 KB Output is correct
20 Correct 9 ms 14464 KB Output is correct
21 Correct 9 ms 14464 KB Output is correct
22 Correct 9 ms 14464 KB Output is correct
23 Correct 9 ms 14464 KB Output is correct
24 Correct 8 ms 14464 KB Output is correct
25 Correct 9 ms 14464 KB Output is correct
26 Correct 8 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 8 ms 14464 KB Output is correct
32 Correct 8 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 8 ms 14464 KB Output is correct
36 Correct 9 ms 14464 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 8 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 13 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 10 ms 14464 KB Output is correct
49 Correct 12 ms 14464 KB Output is correct
50 Correct 9 ms 14464 KB Output is correct
51 Correct 10 ms 14592 KB Output is correct
52 Correct 16 ms 14720 KB Output is correct
53 Correct 12 ms 14848 KB Output is correct
54 Correct 10 ms 14720 KB Output is correct
55 Correct 10 ms 14592 KB Output is correct
56 Correct 11 ms 14592 KB Output is correct
57 Correct 10 ms 14592 KB Output is correct
58 Correct 11 ms 14720 KB Output is correct
59 Correct 11 ms 14592 KB Output is correct
60 Correct 11 ms 14592 KB Output is correct
61 Correct 12 ms 15360 KB Output is correct
62 Correct 12 ms 15360 KB Output is correct
63 Correct 10 ms 14592 KB Output is correct
64 Correct 10 ms 14592 KB Output is correct
65 Correct 9 ms 14464 KB Output is correct
66 Correct 12 ms 14720 KB Output is correct
67 Correct 10 ms 14592 KB Output is correct
68 Correct 11 ms 14720 KB Output is correct
69 Correct 12 ms 14848 KB Output is correct
70 Correct 10 ms 14652 KB Output is correct
71 Correct 41 ms 18288 KB Output is correct
72 Correct 52 ms 18032 KB Output is correct
73 Correct 24 ms 16384 KB Output is correct
74 Correct 42 ms 19832 KB Output is correct
75 Correct 41 ms 18680 KB Output is correct
76 Correct 368 ms 49784 KB Output is correct
77 Correct 330 ms 34680 KB Output is correct
78 Correct 222 ms 29812 KB Output is correct
79 Correct 306 ms 40752 KB Output is correct
80 Correct 312 ms 33016 KB Output is correct
81 Correct 40 ms 18292 KB Output is correct
82 Correct 52 ms 18032 KB Output is correct
83 Correct 24 ms 16508 KB Output is correct
84 Correct 43 ms 19456 KB Output is correct
85 Correct 41 ms 18680 KB Output is correct
86 Correct 339 ms 64340 KB Output is correct
87 Correct 328 ms 64336 KB Output is correct
88 Correct 205 ms 29816 KB Output is correct
89 Correct 302 ms 39544 KB Output is correct
90 Correct 343 ms 33272 KB Output is correct