답안 #300609

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
300609 2020-09-17T10:26:16 Z b00n0rp 슈퍼트리 잇기 (IOI20_supertrees) C++17
100 / 100
291 ms 22264 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for(int i = 0; i < n; i ++)
#define FOR(i,a,b) for(int i = a; i < b; i ++)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second

const int MX = 1005;

int n;
int par[MX];
int sz[MX];

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

void merge(int x,int y){
	x = find(x);
	y = find(y);
	if(x == y) return;
	if(sz[x] < sz[y]) swap(x,y);
	par[y] = x;
	sz[x] += sz[y];
}

bitset<MX> vis;

int construct(vvi p) {
	n = p.size();
	vvi ans(n,vi(n,0));
	REP(i,n){
		par[i] = i;
		sz[i] = 1;
	}
	REP(i,n){
		REP(j,n){
			if(p[i][j] == 3) return 0;
			if(p[i][j]) merge(i,j);
		}
	}
	REP(i,n){
		REP(j,n){
			if(!p[i][j]){
				if(find(i) == find(j)) return 0;
			}
		}
	}
	REP(i,n) par[i] = find(i);
	REP(i,n){
		if(vis[i]) continue;
		vi cc;
		REP(j,n){
			if((!vis[j]) and par[i] == par[j]){
				vis[j] = 1;
				cc.pb(j);
			}
		}
		for(auto x:cc){
			vis[x] = 0;
			par[x] = x;
			sz[x] = 1;
		}
		vi corners;
		for(auto x:cc){
			for(auto y:cc){
				if(p[x][y] == 1){
					merge(x,y);
				}
			}
		}
		for(auto x:cc) par[x] = find(x);
		for(auto x:cc){
			if(vis[x]) continue;
			vi cc2;
			corners.pb(x);
			for(auto y:cc){
				if((!vis[y]) and par[x] == par[y]){
					vis[y] = 1;
					cc2.pb(y);
				}
			}
			REP(j,(int)cc2.size()-1){
				ans[cc2[j]][cc2[j+1]] = 1;
				ans[cc2[j+1]][cc2[j]] = 1;
			}
		}
		REP(j,(int)corners.size()-1){
			ans[corners[j]][corners[j+1]] = 1;
			ans[corners[j+1]][corners[j]] = 1;
		}
		if(corners.size() == 1) continue;
		if(corners.size() == 2) return 0;
		ans[corners[0]][corners.back()] = 1;
		ans[corners.back()][corners[0]] = 1;
	}
	build(ans);
	return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 11 ms 1152 KB Output is correct
7 Correct 291 ms 22240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 11 ms 1152 KB Output is correct
7 Correct 291 ms 22240 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 11 ms 1152 KB Output is correct
13 Correct 247 ms 22264 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 5 ms 896 KB Output is correct
17 Correct 121 ms 12152 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 63 ms 5756 KB Output is correct
21 Correct 251 ms 22136 KB Output is correct
22 Correct 246 ms 22140 KB Output is correct
23 Correct 288 ms 22136 KB Output is correct
24 Correct 259 ms 22136 KB Output is correct
25 Correct 114 ms 12152 KB Output is correct
26 Correct 105 ms 12192 KB Output is correct
27 Correct 277 ms 22136 KB Output is correct
28 Correct 270 ms 22140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 11 ms 1280 KB Output is correct
9 Correct 250 ms 22136 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 11 ms 1152 KB Output is correct
13 Correct 275 ms 22136 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 5 ms 768 KB Output is correct
17 Correct 125 ms 12152 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 66 ms 5752 KB Output is correct
22 Correct 249 ms 22136 KB Output is correct
23 Correct 249 ms 22136 KB Output is correct
24 Correct 268 ms 22136 KB Output is correct
25 Correct 111 ms 12236 KB Output is correct
26 Correct 107 ms 12152 KB Output is correct
27 Correct 250 ms 22136 KB Output is correct
28 Correct 277 ms 22136 KB Output is correct
29 Correct 108 ms 12152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 63 ms 5880 KB Output is correct
5 Correct 254 ms 22136 KB Output is correct
6 Correct 256 ms 22136 KB Output is correct
7 Correct 282 ms 22136 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 74 ms 5752 KB Output is correct
10 Correct 251 ms 22136 KB Output is correct
11 Correct 251 ms 22136 KB Output is correct
12 Correct 268 ms 22136 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 63 ms 5752 KB Output is correct
17 Correct 258 ms 22136 KB Output is correct
18 Correct 251 ms 22240 KB Output is correct
19 Correct 259 ms 22100 KB Output is correct
20 Correct 259 ms 22136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 11 ms 1152 KB Output is correct
7 Correct 291 ms 22240 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 11 ms 1152 KB Output is correct
13 Correct 247 ms 22264 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 5 ms 896 KB Output is correct
17 Correct 121 ms 12152 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 63 ms 5756 KB Output is correct
21 Correct 251 ms 22136 KB Output is correct
22 Correct 246 ms 22140 KB Output is correct
23 Correct 288 ms 22136 KB Output is correct
24 Correct 259 ms 22136 KB Output is correct
25 Correct 114 ms 12152 KB Output is correct
26 Correct 105 ms 12192 KB Output is correct
27 Correct 277 ms 22136 KB Output is correct
28 Correct 270 ms 22140 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 256 KB Output is correct
31 Correct 1 ms 256 KB Output is correct
32 Correct 1 ms 256 KB Output is correct
33 Correct 1 ms 256 KB Output is correct
34 Correct 1 ms 256 KB Output is correct
35 Correct 1 ms 256 KB Output is correct
36 Correct 11 ms 1280 KB Output is correct
37 Correct 250 ms 22136 KB Output is correct
38 Correct 1 ms 256 KB Output is correct
39 Correct 1 ms 256 KB Output is correct
40 Correct 11 ms 1152 KB Output is correct
41 Correct 275 ms 22136 KB Output is correct
42 Correct 1 ms 256 KB Output is correct
43 Correct 1 ms 256 KB Output is correct
44 Correct 5 ms 768 KB Output is correct
45 Correct 125 ms 12152 KB Output is correct
46 Correct 1 ms 256 KB Output is correct
47 Correct 1 ms 256 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 66 ms 5752 KB Output is correct
50 Correct 249 ms 22136 KB Output is correct
51 Correct 249 ms 22136 KB Output is correct
52 Correct 268 ms 22136 KB Output is correct
53 Correct 111 ms 12236 KB Output is correct
54 Correct 107 ms 12152 KB Output is correct
55 Correct 250 ms 22136 KB Output is correct
56 Correct 277 ms 22136 KB Output is correct
57 Correct 108 ms 12152 KB Output is correct
58 Correct 1 ms 256 KB Output is correct
59 Correct 1 ms 256 KB Output is correct
60 Correct 5 ms 768 KB Output is correct
61 Correct 121 ms 12152 KB Output is correct
62 Correct 1 ms 256 KB Output is correct
63 Correct 1 ms 256 KB Output is correct
64 Correct 1 ms 256 KB Output is correct
65 Correct 64 ms 5756 KB Output is correct
66 Correct 115 ms 12152 KB Output is correct
67 Correct 110 ms 12128 KB Output is correct
68 Correct 117 ms 12152 KB Output is correct
69 Correct 109 ms 12152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 11 ms 1152 KB Output is correct
7 Correct 291 ms 22240 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 11 ms 1152 KB Output is correct
13 Correct 247 ms 22264 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 5 ms 896 KB Output is correct
17 Correct 121 ms 12152 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 63 ms 5756 KB Output is correct
21 Correct 251 ms 22136 KB Output is correct
22 Correct 246 ms 22140 KB Output is correct
23 Correct 288 ms 22136 KB Output is correct
24 Correct 259 ms 22136 KB Output is correct
25 Correct 114 ms 12152 KB Output is correct
26 Correct 105 ms 12192 KB Output is correct
27 Correct 277 ms 22136 KB Output is correct
28 Correct 270 ms 22140 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 256 KB Output is correct
31 Correct 1 ms 256 KB Output is correct
32 Correct 1 ms 256 KB Output is correct
33 Correct 1 ms 256 KB Output is correct
34 Correct 1 ms 256 KB Output is correct
35 Correct 1 ms 256 KB Output is correct
36 Correct 11 ms 1280 KB Output is correct
37 Correct 250 ms 22136 KB Output is correct
38 Correct 1 ms 256 KB Output is correct
39 Correct 1 ms 256 KB Output is correct
40 Correct 11 ms 1152 KB Output is correct
41 Correct 275 ms 22136 KB Output is correct
42 Correct 1 ms 256 KB Output is correct
43 Correct 1 ms 256 KB Output is correct
44 Correct 5 ms 768 KB Output is correct
45 Correct 125 ms 12152 KB Output is correct
46 Correct 1 ms 256 KB Output is correct
47 Correct 1 ms 256 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 66 ms 5752 KB Output is correct
50 Correct 249 ms 22136 KB Output is correct
51 Correct 249 ms 22136 KB Output is correct
52 Correct 268 ms 22136 KB Output is correct
53 Correct 111 ms 12236 KB Output is correct
54 Correct 107 ms 12152 KB Output is correct
55 Correct 250 ms 22136 KB Output is correct
56 Correct 277 ms 22136 KB Output is correct
57 Correct 108 ms 12152 KB Output is correct
58 Correct 1 ms 256 KB Output is correct
59 Correct 1 ms 256 KB Output is correct
60 Correct 1 ms 384 KB Output is correct
61 Correct 63 ms 5880 KB Output is correct
62 Correct 254 ms 22136 KB Output is correct
63 Correct 256 ms 22136 KB Output is correct
64 Correct 282 ms 22136 KB Output is correct
65 Correct 1 ms 384 KB Output is correct
66 Correct 74 ms 5752 KB Output is correct
67 Correct 251 ms 22136 KB Output is correct
68 Correct 251 ms 22136 KB Output is correct
69 Correct 268 ms 22136 KB Output is correct
70 Correct 1 ms 256 KB Output is correct
71 Correct 1 ms 384 KB Output is correct
72 Correct 1 ms 256 KB Output is correct
73 Correct 63 ms 5752 KB Output is correct
74 Correct 258 ms 22136 KB Output is correct
75 Correct 251 ms 22240 KB Output is correct
76 Correct 259 ms 22100 KB Output is correct
77 Correct 259 ms 22136 KB Output is correct
78 Correct 1 ms 256 KB Output is correct
79 Correct 1 ms 256 KB Output is correct
80 Correct 5 ms 768 KB Output is correct
81 Correct 121 ms 12152 KB Output is correct
82 Correct 1 ms 256 KB Output is correct
83 Correct 1 ms 256 KB Output is correct
84 Correct 1 ms 256 KB Output is correct
85 Correct 64 ms 5756 KB Output is correct
86 Correct 115 ms 12152 KB Output is correct
87 Correct 110 ms 12128 KB Output is correct
88 Correct 117 ms 12152 KB Output is correct
89 Correct 109 ms 12152 KB Output is correct
90 Correct 1 ms 256 KB Output is correct
91 Correct 1 ms 256 KB Output is correct
92 Correct 7 ms 1024 KB Output is correct
93 Correct 111 ms 12152 KB Output is correct
94 Correct 0 ms 256 KB Output is correct
95 Correct 1 ms 256 KB Output is correct
96 Correct 1 ms 256 KB Output is correct
97 Correct 28 ms 3328 KB Output is correct
98 Correct 108 ms 12152 KB Output is correct
99 Correct 104 ms 12152 KB Output is correct
100 Correct 117 ms 12284 KB Output is correct
101 Correct 102 ms 12152 KB Output is correct
102 Correct 115 ms 12152 KB Output is correct
103 Correct 112 ms 12152 KB Output is correct
104 Correct 114 ms 12152 KB Output is correct
105 Correct 124 ms 12152 KB Output is correct