답안 #475204

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
475204 2021-09-21T12:41:57 Z cs71107 슈퍼트리 잇기 (IOI20_supertrees) C++14
100 / 100
288 ms 24152 KB
#include "supertrees.h"
#include <bits/stdc++.h>

using namespace std;

const int MAXM = 1e3+10;

struct UF{

	int par[MAXM];

	void init(int n){
		for(int i=0;i<n;i++){
			par[i] = i;
		}
		return;
	}

	int root(int x){
		if(par[x]==x)return x;
		else return par[x] = root(par[x]);
	}

	void mymerge(int a,int b){
		a = root(a);
		b = root(b);
		par[b] = a;
		return;
	}

	int getdiff(int a,int b){
		if(root(a)^root(b))return 1;
		else return 0;
	}

}uf0,uf1;

vector<int> id[MAXM];

int construct(std::vector<std::vector<int>> p) {

	
	int res = 1;
	int n = p.size();

	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			if(p[i][j]==3){
				res = 0;
				break;
			}
		}
		if(!res)break;
	}

	if(!res)return 0;

	uf0.init(n);	

	int a,b;

	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			if(p[i][j]==1){
				uf0.mymerge(i,j);
			}
		}
	}

	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			if(p[i][j]^1){
				res&=uf0.getdiff(i,j);
			}
		}
	}

	if(!res)return 0;

	uf1.init(n);

	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			if(p[i][j]==2){
				a = uf0.root(i);
				b = uf0.root(j);

				uf1.mymerge(a,b);
			}			
		}
	}

	for(int i=0;i<n;i++){
	
		for(int j=i+1;j<n;j++){
			if(p[i][j]==0){
				res&=uf1.getdiff(uf0.root(i),uf0.root(j));
			}
		}
	}

	if(!res)return 0;

	for(int i=0;i<n;i++){
		a = uf0.root(i);
		if(a^i)continue;
		b = uf1.root(i);

		id[b].push_back(i);
	}

	for(int i=0;i<n;i++){
		if((int)id[i].size()==2){
			res = 0;
			break;
		}
	}

	if(!res)return 0;

	vector<vector<int> > answer(n);

	for(int i=0;i<n;i++){
		answer[i] = vector<int> (n,0);
	}

	for(int i=0;i<n;i++){
		a = uf0.root(i);
		if(a^i){
			answer[i][a] = 1;
			answer[a][i] = 1;
		}
	}

	int cursz = 0;

	for(int i=0;i<n;i++){
		cursz = (int)id[i].size();

		if(cursz>=3){
			for(int j=0;j<cursz;j++){
				answer[id[i][j]][id[i][(j+1)%cursz]] = 1;
				answer[id[i][(j+1)%cursz]][id[i][j]] = 1;
			}
		}
	}

	build(answer);
	
	return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 10 ms 1280 KB Output is correct
7 Correct 237 ms 23964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 10 ms 1280 KB Output is correct
7 Correct 237 ms 23964 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 10 ms 1228 KB Output is correct
13 Correct 227 ms 24084 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 5 ms 716 KB Output is correct
17 Correct 109 ms 10136 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 208 KB Output is correct
20 Correct 59 ms 6216 KB Output is correct
21 Correct 231 ms 24004 KB Output is correct
22 Correct 236 ms 24008 KB Output is correct
23 Correct 241 ms 24004 KB Output is correct
24 Correct 231 ms 24056 KB Output is correct
25 Correct 98 ms 10136 KB Output is correct
26 Correct 99 ms 10124 KB Output is correct
27 Correct 288 ms 24012 KB Output is correct
28 Correct 230 ms 24152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 10 ms 1228 KB Output is correct
9 Correct 231 ms 24076 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 11 ms 1200 KB Output is correct
13 Correct 238 ms 24000 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 5 ms 716 KB Output is correct
17 Correct 109 ms 10052 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 58 ms 6284 KB Output is correct
22 Correct 233 ms 24088 KB Output is correct
23 Correct 235 ms 24004 KB Output is correct
24 Correct 237 ms 24016 KB Output is correct
25 Correct 99 ms 10184 KB Output is correct
26 Correct 98 ms 10120 KB Output is correct
27 Correct 231 ms 24040 KB Output is correct
28 Correct 241 ms 24008 KB Output is correct
29 Correct 98 ms 10136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 59 ms 6280 KB Output is correct
5 Correct 228 ms 24008 KB Output is correct
6 Correct 234 ms 23924 KB Output is correct
7 Correct 243 ms 23928 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 59 ms 6280 KB Output is correct
10 Correct 236 ms 24076 KB Output is correct
11 Correct 230 ms 24072 KB Output is correct
12 Correct 240 ms 24004 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 58 ms 6284 KB Output is correct
17 Correct 228 ms 24004 KB Output is correct
18 Correct 233 ms 24004 KB Output is correct
19 Correct 241 ms 23944 KB Output is correct
20 Correct 229 ms 24004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 10 ms 1280 KB Output is correct
7 Correct 237 ms 23964 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 10 ms 1228 KB Output is correct
13 Correct 227 ms 24084 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 5 ms 716 KB Output is correct
17 Correct 109 ms 10136 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 208 KB Output is correct
20 Correct 59 ms 6216 KB Output is correct
21 Correct 231 ms 24004 KB Output is correct
22 Correct 236 ms 24008 KB Output is correct
23 Correct 241 ms 24004 KB Output is correct
24 Correct 231 ms 24056 KB Output is correct
25 Correct 98 ms 10136 KB Output is correct
26 Correct 99 ms 10124 KB Output is correct
27 Correct 288 ms 24012 KB Output is correct
28 Correct 230 ms 24152 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Correct 0 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 10 ms 1228 KB Output is correct
37 Correct 231 ms 24076 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 11 ms 1200 KB Output is correct
41 Correct 238 ms 24000 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 5 ms 716 KB Output is correct
45 Correct 109 ms 10052 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 1 ms 204 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 58 ms 6284 KB Output is correct
50 Correct 233 ms 24088 KB Output is correct
51 Correct 235 ms 24004 KB Output is correct
52 Correct 237 ms 24016 KB Output is correct
53 Correct 99 ms 10184 KB Output is correct
54 Correct 98 ms 10120 KB Output is correct
55 Correct 231 ms 24040 KB Output is correct
56 Correct 241 ms 24008 KB Output is correct
57 Correct 98 ms 10136 KB Output is correct
58 Correct 1 ms 204 KB Output is correct
59 Correct 0 ms 204 KB Output is correct
60 Correct 5 ms 716 KB Output is correct
61 Correct 106 ms 10120 KB Output is correct
62 Correct 0 ms 320 KB Output is correct
63 Correct 1 ms 332 KB Output is correct
64 Correct 1 ms 204 KB Output is correct
65 Correct 60 ms 6280 KB Output is correct
66 Correct 102 ms 10136 KB Output is correct
67 Correct 100 ms 10132 KB Output is correct
68 Correct 105 ms 10124 KB Output is correct
69 Correct 96 ms 10120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 10 ms 1280 KB Output is correct
7 Correct 237 ms 23964 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 10 ms 1228 KB Output is correct
13 Correct 227 ms 24084 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 5 ms 716 KB Output is correct
17 Correct 109 ms 10136 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 208 KB Output is correct
20 Correct 59 ms 6216 KB Output is correct
21 Correct 231 ms 24004 KB Output is correct
22 Correct 236 ms 24008 KB Output is correct
23 Correct 241 ms 24004 KB Output is correct
24 Correct 231 ms 24056 KB Output is correct
25 Correct 98 ms 10136 KB Output is correct
26 Correct 99 ms 10124 KB Output is correct
27 Correct 288 ms 24012 KB Output is correct
28 Correct 230 ms 24152 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Correct 0 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 10 ms 1228 KB Output is correct
37 Correct 231 ms 24076 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 11 ms 1200 KB Output is correct
41 Correct 238 ms 24000 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 5 ms 716 KB Output is correct
45 Correct 109 ms 10052 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 1 ms 204 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 58 ms 6284 KB Output is correct
50 Correct 233 ms 24088 KB Output is correct
51 Correct 235 ms 24004 KB Output is correct
52 Correct 237 ms 24016 KB Output is correct
53 Correct 99 ms 10184 KB Output is correct
54 Correct 98 ms 10120 KB Output is correct
55 Correct 231 ms 24040 KB Output is correct
56 Correct 241 ms 24008 KB Output is correct
57 Correct 98 ms 10136 KB Output is correct
58 Correct 1 ms 204 KB Output is correct
59 Correct 1 ms 204 KB Output is correct
60 Correct 1 ms 204 KB Output is correct
61 Correct 59 ms 6280 KB Output is correct
62 Correct 228 ms 24008 KB Output is correct
63 Correct 234 ms 23924 KB Output is correct
64 Correct 243 ms 23928 KB Output is correct
65 Correct 1 ms 204 KB Output is correct
66 Correct 59 ms 6280 KB Output is correct
67 Correct 236 ms 24076 KB Output is correct
68 Correct 230 ms 24072 KB Output is correct
69 Correct 240 ms 24004 KB Output is correct
70 Correct 0 ms 204 KB Output is correct
71 Correct 1 ms 204 KB Output is correct
72 Correct 1 ms 204 KB Output is correct
73 Correct 58 ms 6284 KB Output is correct
74 Correct 228 ms 24004 KB Output is correct
75 Correct 233 ms 24004 KB Output is correct
76 Correct 241 ms 23944 KB Output is correct
77 Correct 229 ms 24004 KB Output is correct
78 Correct 1 ms 204 KB Output is correct
79 Correct 0 ms 204 KB Output is correct
80 Correct 5 ms 716 KB Output is correct
81 Correct 106 ms 10120 KB Output is correct
82 Correct 0 ms 320 KB Output is correct
83 Correct 1 ms 332 KB Output is correct
84 Correct 1 ms 204 KB Output is correct
85 Correct 60 ms 6280 KB Output is correct
86 Correct 102 ms 10136 KB Output is correct
87 Correct 100 ms 10132 KB Output is correct
88 Correct 105 ms 10124 KB Output is correct
89 Correct 96 ms 10120 KB Output is correct
90 Correct 0 ms 204 KB Output is correct
91 Correct 1 ms 204 KB Output is correct
92 Correct 5 ms 692 KB Output is correct
93 Correct 97 ms 10120 KB Output is correct
94 Correct 1 ms 204 KB Output is correct
95 Correct 1 ms 204 KB Output is correct
96 Correct 1 ms 204 KB Output is correct
97 Correct 23 ms 2704 KB Output is correct
98 Correct 93 ms 10124 KB Output is correct
99 Correct 92 ms 10052 KB Output is correct
100 Correct 91 ms 10056 KB Output is correct
101 Correct 95 ms 10128 KB Output is correct
102 Correct 95 ms 10120 KB Output is correct
103 Correct 91 ms 10052 KB Output is correct
104 Correct 91 ms 10124 KB Output is correct
105 Correct 99 ms 10124 KB Output is correct