답안 #738037

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
738037 2023-05-08T05:51:39 Z bobthebuilder 슈퍼트리 잇기 (IOI20_supertrees) C++17
100 / 100
277 ms 24124 KB
#include "supertrees.h"
#include<bits/stdc++.h>
using namespace std;
#define sz(x) (int)x.size()
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define pb push_back
#define lowb(x) (x&(-x))
#define ALL(_x) _x.begin(),_x.end()
#define pii pair<int,int>
#define f first
#define s second
#define SORT_UNIQUE(x) sort(ALL(x)),x.erase(unique(ALL(x)),x.end())
#define MNTO(x,y) x=min(x,y)
const int maxn=1e3+5;
namespace {
struct uf{
	int par[maxn];
	void init(int n){
		REP(i,n) par[i]=i;
	}
	int find(int u){
		if(par[u]==u) return u;
		return par[u]=find(par[u]);
	}
	void merge(int a,int b){
		a=find(a),b=find(b);
		if(a==b) return;
		par[a]=b;
	}
}a,b;

vector<int> cmp[maxn],ln[maxn];
}
int construct(std::vector<std::vector<int>> p) {
	int n = p.size();
	vector<vector<int>> ans(n,vector<int>(n));
	REP(i,n){
		REP(j,n){
			if(p[i][j]==3){
				return 0;
			}
		}
		if(p[i][i]!=1){
			return 0;
		}
	}
	a.init(n),b.init(n);
	REP(i,n){
		REP(j,n){
			if(p[i][j]){
				a.merge(i,j);
			}
		}
	}
	REP(i,n){
		cmp[a.find(i)].pb(i);
	}
	REP(i,n){
		if(!sz(cmp[i])) continue;
		for(int x:cmp[i]){
			for(int y:cmp[i]){
				if(p[x][y]==0){
					return 0;
				}
				if(p[x][y]==1){
					b.merge(x,y);
				}
			}
		}
		for(int x:cmp[i]){
			for(int y:cmp[i]){
				if(p[x][y]==2 and b.find(x)==b.find(y)){
					return 0;
				}
			}
		}
		vector<int> cyc;
		for(int x:cmp[i]){
			cyc.pb(b.find(x));
			ln[b.find(x)].pb(x);
		}
		SORT_UNIQUE(cyc);
		if(sz(cyc)==2){
			return 0;
		}
		if(sz(cyc)>1){
			int k=sz(cyc);
			REP(j,k){
				ans[cyc[j]][cyc[(j+1)%k]]=ans[cyc[(j+1)%k]][cyc[j]]=1;
			}
		}
		for(int x:cmp[i]){
			for(int a:ln[x]){
				for(int b:ln[x]){
					if(p[a][b]!=1){
						return 0;
					}
				}
			}
			int pv=-1;
			for(int y:ln[x]){
				if(pv!=-1) ans[pv][y]=ans[y][pv]=1; 
				pv=y;
			}
		}
	}
	build(ans);
	return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 7 ms 1152 KB Output is correct
7 Correct 179 ms 22080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 7 ms 1152 KB Output is correct
7 Correct 179 ms 22080 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 12 ms 1236 KB Output is correct
13 Correct 161 ms 22076 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 4 ms 768 KB Output is correct
17 Correct 84 ms 12096 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 42 ms 5812 KB Output is correct
21 Correct 171 ms 22076 KB Output is correct
22 Correct 204 ms 22196 KB Output is correct
23 Correct 177 ms 22032 KB Output is correct
24 Correct 174 ms 22092 KB Output is correct
25 Correct 75 ms 12096 KB Output is correct
26 Correct 68 ms 12100 KB Output is correct
27 Correct 177 ms 22072 KB Output is correct
28 Correct 277 ms 22064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 13 ms 1232 KB Output is correct
9 Correct 170 ms 24124 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 8 ms 1236 KB Output is correct
13 Correct 173 ms 23996 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 90 ms 14044 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 352 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 43 ms 6316 KB Output is correct
22 Correct 172 ms 24116 KB Output is correct
23 Correct 172 ms 24012 KB Output is correct
24 Correct 185 ms 23992 KB Output is correct
25 Correct 67 ms 14116 KB Output is correct
26 Correct 70 ms 14120 KB Output is correct
27 Correct 168 ms 24064 KB Output is correct
28 Correct 177 ms 24012 KB Output is correct
29 Correct 68 ms 14124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 42 ms 5768 KB Output is correct
5 Correct 164 ms 22088 KB Output is correct
6 Correct 183 ms 22088 KB Output is correct
7 Correct 184 ms 22072 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 70 ms 5828 KB Output is correct
10 Correct 172 ms 22092 KB Output is correct
11 Correct 179 ms 22108 KB Output is correct
12 Correct 187 ms 22080 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 43 ms 5812 KB Output is correct
17 Correct 164 ms 22112 KB Output is correct
18 Correct 165 ms 22092 KB Output is correct
19 Correct 174 ms 22008 KB Output is correct
20 Correct 205 ms 22072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 7 ms 1152 KB Output is correct
7 Correct 179 ms 22080 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 12 ms 1236 KB Output is correct
13 Correct 161 ms 22076 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 4 ms 768 KB Output is correct
17 Correct 84 ms 12096 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 42 ms 5812 KB Output is correct
21 Correct 171 ms 22076 KB Output is correct
22 Correct 204 ms 22196 KB Output is correct
23 Correct 177 ms 22032 KB Output is correct
24 Correct 174 ms 22092 KB Output is correct
25 Correct 75 ms 12096 KB Output is correct
26 Correct 68 ms 12100 KB Output is correct
27 Correct 177 ms 22072 KB Output is correct
28 Correct 277 ms 22064 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 13 ms 1232 KB Output is correct
37 Correct 170 ms 24124 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 8 ms 1236 KB Output is correct
41 Correct 173 ms 23996 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 4 ms 852 KB Output is correct
45 Correct 90 ms 14044 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 352 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 43 ms 6316 KB Output is correct
50 Correct 172 ms 24116 KB Output is correct
51 Correct 172 ms 24012 KB Output is correct
52 Correct 185 ms 23992 KB Output is correct
53 Correct 67 ms 14116 KB Output is correct
54 Correct 70 ms 14120 KB Output is correct
55 Correct 168 ms 24064 KB Output is correct
56 Correct 177 ms 24012 KB Output is correct
57 Correct 68 ms 14124 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 4 ms 876 KB Output is correct
61 Correct 87 ms 14048 KB Output is correct
62 Correct 1 ms 340 KB Output is correct
63 Correct 1 ms 340 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
65 Correct 45 ms 6312 KB Output is correct
66 Correct 75 ms 14028 KB Output is correct
67 Correct 79 ms 14116 KB Output is correct
68 Correct 75 ms 14156 KB Output is correct
69 Correct 83 ms 14120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 7 ms 1152 KB Output is correct
7 Correct 179 ms 22080 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 12 ms 1236 KB Output is correct
13 Correct 161 ms 22076 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 4 ms 768 KB Output is correct
17 Correct 84 ms 12096 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 42 ms 5812 KB Output is correct
21 Correct 171 ms 22076 KB Output is correct
22 Correct 204 ms 22196 KB Output is correct
23 Correct 177 ms 22032 KB Output is correct
24 Correct 174 ms 22092 KB Output is correct
25 Correct 75 ms 12096 KB Output is correct
26 Correct 68 ms 12100 KB Output is correct
27 Correct 177 ms 22072 KB Output is correct
28 Correct 277 ms 22064 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 13 ms 1232 KB Output is correct
37 Correct 170 ms 24124 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 8 ms 1236 KB Output is correct
41 Correct 173 ms 23996 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 4 ms 852 KB Output is correct
45 Correct 90 ms 14044 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 352 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 43 ms 6316 KB Output is correct
50 Correct 172 ms 24116 KB Output is correct
51 Correct 172 ms 24012 KB Output is correct
52 Correct 185 ms 23992 KB Output is correct
53 Correct 67 ms 14116 KB Output is correct
54 Correct 70 ms 14120 KB Output is correct
55 Correct 168 ms 24064 KB Output is correct
56 Correct 177 ms 24012 KB Output is correct
57 Correct 68 ms 14124 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 0 ms 340 KB Output is correct
60 Correct 0 ms 340 KB Output is correct
61 Correct 42 ms 5768 KB Output is correct
62 Correct 164 ms 22088 KB Output is correct
63 Correct 183 ms 22088 KB Output is correct
64 Correct 184 ms 22072 KB Output is correct
65 Correct 1 ms 340 KB Output is correct
66 Correct 70 ms 5828 KB Output is correct
67 Correct 172 ms 22092 KB Output is correct
68 Correct 179 ms 22108 KB Output is correct
69 Correct 187 ms 22080 KB Output is correct
70 Correct 0 ms 340 KB Output is correct
71 Correct 1 ms 340 KB Output is correct
72 Correct 0 ms 340 KB Output is correct
73 Correct 43 ms 5812 KB Output is correct
74 Correct 164 ms 22112 KB Output is correct
75 Correct 165 ms 22092 KB Output is correct
76 Correct 174 ms 22008 KB Output is correct
77 Correct 205 ms 22072 KB Output is correct
78 Correct 1 ms 340 KB Output is correct
79 Correct 1 ms 340 KB Output is correct
80 Correct 4 ms 876 KB Output is correct
81 Correct 87 ms 14048 KB Output is correct
82 Correct 1 ms 340 KB Output is correct
83 Correct 1 ms 340 KB Output is correct
84 Correct 1 ms 340 KB Output is correct
85 Correct 45 ms 6312 KB Output is correct
86 Correct 75 ms 14028 KB Output is correct
87 Correct 79 ms 14116 KB Output is correct
88 Correct 75 ms 14156 KB Output is correct
89 Correct 83 ms 14120 KB Output is correct
90 Correct 0 ms 352 KB Output is correct
91 Correct 1 ms 340 KB Output is correct
92 Correct 3 ms 880 KB Output is correct
93 Correct 79 ms 14116 KB Output is correct
94 Correct 1 ms 352 KB Output is correct
95 Correct 1 ms 340 KB Output is correct
96 Correct 1 ms 340 KB Output is correct
97 Correct 21 ms 3752 KB Output is correct
98 Correct 76 ms 14124 KB Output is correct
99 Correct 95 ms 14124 KB Output is correct
100 Correct 67 ms 14124 KB Output is correct
101 Correct 69 ms 14120 KB Output is correct
102 Correct 106 ms 14136 KB Output is correct
103 Correct 71 ms 14124 KB Output is correct
104 Correct 67 ms 14124 KB Output is correct
105 Correct 79 ms 14044 KB Output is correct