답안 #97624

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
97624 2019-02-17T13:59:19 Z fefe 족보 (KOI18_family) C++17
100 / 100
644 ms 68168 KB
#include<bits/stdc++.h>
#define MAX_N 300005
#define MAX_M 100005
#define pb push_back
#define mp make_pair
#define all(V) (V).begin(),(V).end()
#define reset(V) (V).clear();(V).resize(0);
#define sq(x) ((x)*(x))
#define abs(x) ((x)>0?(x):(-(x)))
#define fi first
#define se second
#define LL_inf (1LL<<60)
#define full_inf 0x7fffffff
#define half_inf 0x3fffffff
#define inf 0x3fffffff
#define MOD 1000000007LL
#define cpx_mod(x) (((LD)(((LL)x.real())%MOD)),((LD)(((LL)x.imag())%MOD)))
using namespace std;
typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
typedef pair<LL,LL> pil;
typedef pair<LL,string> pls;
typedef complex<LD> Complex;
typedef long double LD;
int n,m,k;
int rep[3][MAX_N],num[3][MAX_N];
int pa[MAX_N],cnt[MAX_N];
vector<int> E[3][MAX_N];
vector<pii> lst;
int find_pa(int x){return (pa[x]==x)?(x):(pa[x]=find_pa(pa[x]));}
int dfs(int c,int x){
	if(x<=k){num[c][x]=1;rep[c][x]=x;return x;}
	for(int y:E[c][x]){
		rep[c][x]=dfs(c,y);
		num[c][x]+=num[c][y];
	}
	if(E[c][x].size()!=1)	lst.pb({c,x});
	return rep[c][x];
}
int main(){
	int i,x,y;
	scanf("%d %d %d",&n,&m,&k);
	for(i=1;i<=n;i++){
		scanf("%d",&x);
		E[0][x].pb(i);
	}
	for(i=1;i<=m;i++){
		scanf("%d",&x);
		E[1][x].pb(i);
	}
	dfs(0,E[0][0][0]);
	dfs(1,E[1][0][0]);
	for(i=1;i<=k;i++){pa[i]=i;cnt[i]=1;}
	sort(all(lst),[&](const pii x,const pii y){return num[x.fi][x.se]<num[y.fi][y.se];});
	
	for(pii p:lst){
		for(int z:E[p.fi][p.se]){
			x=find_pa(rep[p.fi][p.se]);
			y=find_pa(rep[p.fi][z]);
			if(x==y)	continue;
			pa[y]=pa[x];
			cnt[x]+=cnt[y];
		}
		if(cnt[find_pa(rep[p.fi][p.se])]!=num[p.fi][p.se])	return !printf("NO\n");
	}
	printf("YES\n");
	return 0;
}

Compilation message

family.cpp: In function 'int main()':
family.cpp:43:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d",&n,&m,&k);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~
family.cpp:45:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&x);
   ~~~~~^~~~~~~~~
family.cpp:49:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&x);
   ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 21504 KB Output is correct
2 Correct 25 ms 21476 KB Output is correct
3 Correct 25 ms 21480 KB Output is correct
4 Correct 22 ms 21520 KB Output is correct
5 Correct 30 ms 21468 KB Output is correct
6 Correct 28 ms 21512 KB Output is correct
7 Correct 25 ms 21496 KB Output is correct
8 Correct 22 ms 21504 KB Output is correct
9 Correct 22 ms 21540 KB Output is correct
10 Correct 24 ms 21504 KB Output is correct
11 Correct 29 ms 21496 KB Output is correct
12 Correct 25 ms 21504 KB Output is correct
13 Correct 23 ms 21416 KB Output is correct
14 Correct 27 ms 21500 KB Output is correct
15 Correct 26 ms 21504 KB Output is correct
16 Correct 25 ms 21504 KB Output is correct
17 Correct 28 ms 21496 KB Output is correct
18 Correct 24 ms 21448 KB Output is correct
19 Correct 23 ms 21552 KB Output is correct
20 Correct 24 ms 21632 KB Output is correct
21 Correct 23 ms 21552 KB Output is correct
22 Correct 21 ms 21560 KB Output is correct
23 Correct 22 ms 21496 KB Output is correct
24 Correct 26 ms 21564 KB Output is correct
25 Correct 24 ms 21532 KB Output is correct
26 Correct 25 ms 21476 KB Output is correct
27 Correct 13 ms 21460 KB Output is correct
28 Correct 26 ms 21496 KB Output is correct
29 Correct 23 ms 21504 KB Output is correct
30 Correct 27 ms 21496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 21504 KB Output is correct
2 Correct 25 ms 21476 KB Output is correct
3 Correct 25 ms 21480 KB Output is correct
4 Correct 22 ms 21520 KB Output is correct
5 Correct 30 ms 21468 KB Output is correct
6 Correct 28 ms 21512 KB Output is correct
7 Correct 25 ms 21496 KB Output is correct
8 Correct 22 ms 21504 KB Output is correct
9 Correct 22 ms 21540 KB Output is correct
10 Correct 24 ms 21504 KB Output is correct
11 Correct 29 ms 21496 KB Output is correct
12 Correct 25 ms 21504 KB Output is correct
13 Correct 23 ms 21416 KB Output is correct
14 Correct 27 ms 21500 KB Output is correct
15 Correct 26 ms 21504 KB Output is correct
16 Correct 25 ms 21504 KB Output is correct
17 Correct 28 ms 21496 KB Output is correct
18 Correct 24 ms 21448 KB Output is correct
19 Correct 23 ms 21552 KB Output is correct
20 Correct 24 ms 21632 KB Output is correct
21 Correct 23 ms 21552 KB Output is correct
22 Correct 21 ms 21560 KB Output is correct
23 Correct 22 ms 21496 KB Output is correct
24 Correct 26 ms 21564 KB Output is correct
25 Correct 24 ms 21532 KB Output is correct
26 Correct 25 ms 21476 KB Output is correct
27 Correct 13 ms 21460 KB Output is correct
28 Correct 26 ms 21496 KB Output is correct
29 Correct 23 ms 21504 KB Output is correct
30 Correct 27 ms 21496 KB Output is correct
31 Correct 27 ms 21544 KB Output is correct
32 Correct 23 ms 21504 KB Output is correct
33 Correct 24 ms 21504 KB Output is correct
34 Correct 24 ms 21496 KB Output is correct
35 Correct 23 ms 21632 KB Output is correct
36 Correct 23 ms 21536 KB Output is correct
37 Correct 26 ms 21528 KB Output is correct
38 Correct 23 ms 21532 KB Output is correct
39 Correct 23 ms 21556 KB Output is correct
40 Correct 25 ms 21504 KB Output is correct
41 Correct 24 ms 21504 KB Output is correct
42 Correct 22 ms 21504 KB Output is correct
43 Correct 25 ms 21500 KB Output is correct
44 Correct 23 ms 21504 KB Output is correct
45 Correct 24 ms 21504 KB Output is correct
46 Correct 22 ms 21496 KB Output is correct
47 Correct 28 ms 21496 KB Output is correct
48 Correct 26 ms 21496 KB Output is correct
49 Correct 26 ms 21504 KB Output is correct
50 Correct 25 ms 21504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 21504 KB Output is correct
2 Correct 25 ms 21476 KB Output is correct
3 Correct 25 ms 21480 KB Output is correct
4 Correct 22 ms 21520 KB Output is correct
5 Correct 30 ms 21468 KB Output is correct
6 Correct 28 ms 21512 KB Output is correct
7 Correct 25 ms 21496 KB Output is correct
8 Correct 22 ms 21504 KB Output is correct
9 Correct 22 ms 21540 KB Output is correct
10 Correct 24 ms 21504 KB Output is correct
11 Correct 29 ms 21496 KB Output is correct
12 Correct 25 ms 21504 KB Output is correct
13 Correct 23 ms 21416 KB Output is correct
14 Correct 27 ms 21500 KB Output is correct
15 Correct 26 ms 21504 KB Output is correct
16 Correct 25 ms 21504 KB Output is correct
17 Correct 28 ms 21496 KB Output is correct
18 Correct 24 ms 21448 KB Output is correct
19 Correct 23 ms 21552 KB Output is correct
20 Correct 24 ms 21632 KB Output is correct
21 Correct 23 ms 21552 KB Output is correct
22 Correct 21 ms 21560 KB Output is correct
23 Correct 22 ms 21496 KB Output is correct
24 Correct 26 ms 21564 KB Output is correct
25 Correct 24 ms 21532 KB Output is correct
26 Correct 25 ms 21476 KB Output is correct
27 Correct 13 ms 21460 KB Output is correct
28 Correct 26 ms 21496 KB Output is correct
29 Correct 23 ms 21504 KB Output is correct
30 Correct 27 ms 21496 KB Output is correct
31 Correct 27 ms 21544 KB Output is correct
32 Correct 23 ms 21504 KB Output is correct
33 Correct 24 ms 21504 KB Output is correct
34 Correct 24 ms 21496 KB Output is correct
35 Correct 23 ms 21632 KB Output is correct
36 Correct 23 ms 21536 KB Output is correct
37 Correct 26 ms 21528 KB Output is correct
38 Correct 23 ms 21532 KB Output is correct
39 Correct 23 ms 21556 KB Output is correct
40 Correct 25 ms 21504 KB Output is correct
41 Correct 24 ms 21504 KB Output is correct
42 Correct 22 ms 21504 KB Output is correct
43 Correct 25 ms 21500 KB Output is correct
44 Correct 23 ms 21504 KB Output is correct
45 Correct 24 ms 21504 KB Output is correct
46 Correct 22 ms 21496 KB Output is correct
47 Correct 28 ms 21496 KB Output is correct
48 Correct 26 ms 21496 KB Output is correct
49 Correct 26 ms 21504 KB Output is correct
50 Correct 25 ms 21504 KB Output is correct
51 Correct 25 ms 21760 KB Output is correct
52 Correct 28 ms 21888 KB Output is correct
53 Correct 33 ms 21796 KB Output is correct
54 Correct 24 ms 21680 KB Output is correct
55 Correct 24 ms 21760 KB Output is correct
56 Correct 27 ms 21760 KB Output is correct
57 Correct 25 ms 21760 KB Output is correct
58 Correct 30 ms 21772 KB Output is correct
59 Correct 30 ms 21760 KB Output is correct
60 Correct 23 ms 21696 KB Output is correct
61 Correct 25 ms 22144 KB Output is correct
62 Correct 26 ms 22148 KB Output is correct
63 Correct 22 ms 21632 KB Output is correct
64 Correct 22 ms 21632 KB Output is correct
65 Correct 23 ms 21632 KB Output is correct
66 Correct 24 ms 21760 KB Output is correct
67 Correct 27 ms 21760 KB Output is correct
68 Correct 24 ms 21800 KB Output is correct
69 Correct 24 ms 21760 KB Output is correct
70 Correct 24 ms 21724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 21504 KB Output is correct
2 Correct 25 ms 21476 KB Output is correct
3 Correct 25 ms 21480 KB Output is correct
4 Correct 22 ms 21520 KB Output is correct
5 Correct 30 ms 21468 KB Output is correct
6 Correct 28 ms 21512 KB Output is correct
7 Correct 25 ms 21496 KB Output is correct
8 Correct 22 ms 21504 KB Output is correct
9 Correct 22 ms 21540 KB Output is correct
10 Correct 24 ms 21504 KB Output is correct
11 Correct 29 ms 21496 KB Output is correct
12 Correct 25 ms 21504 KB Output is correct
13 Correct 23 ms 21416 KB Output is correct
14 Correct 27 ms 21500 KB Output is correct
15 Correct 26 ms 21504 KB Output is correct
16 Correct 25 ms 21504 KB Output is correct
17 Correct 28 ms 21496 KB Output is correct
18 Correct 24 ms 21448 KB Output is correct
19 Correct 23 ms 21552 KB Output is correct
20 Correct 24 ms 21632 KB Output is correct
21 Correct 23 ms 21552 KB Output is correct
22 Correct 21 ms 21560 KB Output is correct
23 Correct 22 ms 21496 KB Output is correct
24 Correct 26 ms 21564 KB Output is correct
25 Correct 24 ms 21532 KB Output is correct
26 Correct 25 ms 21476 KB Output is correct
27 Correct 13 ms 21460 KB Output is correct
28 Correct 26 ms 21496 KB Output is correct
29 Correct 23 ms 21504 KB Output is correct
30 Correct 27 ms 21496 KB Output is correct
31 Correct 27 ms 21544 KB Output is correct
32 Correct 23 ms 21504 KB Output is correct
33 Correct 24 ms 21504 KB Output is correct
34 Correct 24 ms 21496 KB Output is correct
35 Correct 23 ms 21632 KB Output is correct
36 Correct 23 ms 21536 KB Output is correct
37 Correct 26 ms 21528 KB Output is correct
38 Correct 23 ms 21532 KB Output is correct
39 Correct 23 ms 21556 KB Output is correct
40 Correct 25 ms 21504 KB Output is correct
41 Correct 24 ms 21504 KB Output is correct
42 Correct 22 ms 21504 KB Output is correct
43 Correct 25 ms 21500 KB Output is correct
44 Correct 23 ms 21504 KB Output is correct
45 Correct 24 ms 21504 KB Output is correct
46 Correct 22 ms 21496 KB Output is correct
47 Correct 28 ms 21496 KB Output is correct
48 Correct 26 ms 21496 KB Output is correct
49 Correct 26 ms 21504 KB Output is correct
50 Correct 25 ms 21504 KB Output is correct
51 Correct 25 ms 21760 KB Output is correct
52 Correct 28 ms 21888 KB Output is correct
53 Correct 33 ms 21796 KB Output is correct
54 Correct 24 ms 21680 KB Output is correct
55 Correct 24 ms 21760 KB Output is correct
56 Correct 27 ms 21760 KB Output is correct
57 Correct 25 ms 21760 KB Output is correct
58 Correct 30 ms 21772 KB Output is correct
59 Correct 30 ms 21760 KB Output is correct
60 Correct 23 ms 21696 KB Output is correct
61 Correct 25 ms 22144 KB Output is correct
62 Correct 26 ms 22148 KB Output is correct
63 Correct 22 ms 21632 KB Output is correct
64 Correct 22 ms 21632 KB Output is correct
65 Correct 23 ms 21632 KB Output is correct
66 Correct 24 ms 21760 KB Output is correct
67 Correct 27 ms 21760 KB Output is correct
68 Correct 24 ms 21800 KB Output is correct
69 Correct 24 ms 21760 KB Output is correct
70 Correct 24 ms 21724 KB Output is correct
71 Correct 90 ms 25564 KB Output is correct
72 Correct 68 ms 24832 KB Output is correct
73 Correct 66 ms 24188 KB Output is correct
74 Correct 85 ms 28664 KB Output is correct
75 Correct 105 ms 27256 KB Output is correct
76 Correct 644 ms 68168 KB Output is correct
77 Correct 555 ms 50424 KB Output is correct
78 Correct 402 ms 37896 KB Output is correct
79 Correct 552 ms 56828 KB Output is correct
80 Correct 477 ms 48284 KB Output is correct
81 Correct 70 ms 25336 KB Output is correct
82 Correct 60 ms 24944 KB Output is correct
83 Correct 55 ms 24184 KB Output is correct
84 Correct 84 ms 28280 KB Output is correct
85 Correct 92 ms 27256 KB Output is correct
86 Correct 580 ms 60352 KB Output is correct
87 Correct 634 ms 60360 KB Output is correct
88 Correct 375 ms 37920 KB Output is correct
89 Correct 457 ms 55416 KB Output is correct
90 Correct 466 ms 48440 KB Output is correct