답안 #428630

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
428630 2021-06-15T13:17:09 Z alishahali1382 슈퍼트리 잇기 (IOI20_supertrees) C++14
100 / 100
264 ms 28112 KB
#include "supertrees.h"
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
#define debug(x) {cerr<<#x<<"="<<x<<"\n";}
#define debug2(x, y) {cerr<<"{"<<#x<<", "<<#y<<"}={"<<x<<", "<<y<<"}\n";}
#define debugp(p) {cerr<<#p<<"={"<<p.first<<", "<<p.second<<"}\n";}
#define debugv(abcd) {cerr<<#abcd<<": "; for (auto dcba:abcd) cerr<<dcba<<", ";cerr<<"\n";}
#define pb push_back
#define all(x) x.begin(), x.end()
#define SZ(x) ((int)x.size())

const int inf=1000000100; // 1e9
const ll INF=10000000001000000; // 1e16
const int mod=1000000007;
const int MAXN=1010, LOG=20;

struct DSU{
	int par[MAXN];
	DSU(){
		iota(par, par+MAXN, 0);
	}
	int getpar(int x){ return (par[x]==x?x:par[x]=getpar(par[x]));}
	int joined(int x, int y){ return getpar(x)==getpar(y);}
	int join(int x, int y){
		x=getpar(x);
		y=getpar(y);
		par[x]=y;
		return x!=y;
	}
} dsu12, dsu1, dsu2;

int n, m, k, x, y, u, v, t, a, b, ans;
int A[MAXN][MAXN];
vector<vi> out;
vi vec1[MAXN], vec2[MAXN];

void add_edge(int u, int v){
	out[u][v]=out[v][u]=1;
}

int construct(vector<vi> _A){
	n=SZ(_A);
	for (int i=0; i<n; i++) for (int j=0; j<n; j++) A[i][j]=_A[i][j];
	for (int i=0; i<n; i++) for (int j=0; j<n; j++){
		if (A[i][j]==3) return 0;
		if (A[i][j]) dsu12.join(i, j);
		if (A[i][j]==1) dsu1.join(i, j);
	}
	for (int i=0; i<n; i++) for (int j=0; j<n; j++){
		if (!A[i][j] && dsu12.joined(i, j)) return 0;
		if (A[i][j]==2 && dsu1.joined(i, j)) return 0;
	}
	for (int i=0; i<n; i++){
		vec1[dsu1.getpar(i)].pb(i);
		if (dsu1.par[i]==i) vec2[dsu12.getpar(i)].pb(i);	
	}
	out.resize(n, vi(n, 0));
	for (int i=0; i<n; i++){
		// debugv(vec1[i])
		// debugv(vec2[i])
		// cerr<<"\n";
		for (int j=1; j<SZ(vec1[i]); j++) add_edge(vec1[i][j-1], vec1[i][j]);
		// debug("shit")
		if (SZ(vec2[i])==2) return 0;
		if (SZ(vec2[i])>2){
			for (int j=1; j<SZ(vec2[i]); j++) add_edge(vec2[i][j], vec2[i][j-1]);
			add_edge(vec2[i].back(), vec2[i][0]);
		}
	}
	build(out);
	return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 11 ms 1996 KB Output is correct
7 Correct 247 ms 26128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 11 ms 1996 KB Output is correct
7 Correct 247 ms 26128 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 11 ms 1928 KB Output is correct
13 Correct 238 ms 26080 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 6 ms 1356 KB Output is correct
17 Correct 121 ms 12096 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 59 ms 7748 KB Output is correct
21 Correct 243 ms 26060 KB Output is correct
22 Correct 240 ms 26048 KB Output is correct
23 Correct 255 ms 26048 KB Output is correct
24 Correct 234 ms 25992 KB Output is correct
25 Correct 102 ms 12104 KB Output is correct
26 Correct 95 ms 12108 KB Output is correct
27 Correct 251 ms 25988 KB Output is correct
28 Correct 234 ms 26064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 11 ms 2124 KB Output is correct
9 Correct 236 ms 27988 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 11 ms 2124 KB Output is correct
13 Correct 243 ms 27972 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 6 ms 1484 KB Output is correct
17 Correct 112 ms 14052 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 360 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 66 ms 8240 KB Output is correct
22 Correct 236 ms 27972 KB Output is correct
23 Correct 241 ms 27960 KB Output is correct
24 Correct 264 ms 28012 KB Output is correct
25 Correct 107 ms 18116 KB Output is correct
26 Correct 103 ms 14124 KB Output is correct
27 Correct 236 ms 27964 KB Output is correct
28 Correct 257 ms 27984 KB Output is correct
29 Correct 101 ms 18116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 64 ms 7740 KB Output is correct
5 Correct 239 ms 26020 KB Output is correct
6 Correct 257 ms 26048 KB Output is correct
7 Correct 250 ms 26052 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 62 ms 8280 KB Output is correct
10 Correct 236 ms 28008 KB Output is correct
11 Correct 246 ms 28112 KB Output is correct
12 Correct 248 ms 27972 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 61 ms 8296 KB Output is correct
17 Correct 237 ms 27948 KB Output is correct
18 Correct 246 ms 27972 KB Output is correct
19 Correct 242 ms 27824 KB Output is correct
20 Correct 236 ms 27972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 11 ms 1996 KB Output is correct
7 Correct 247 ms 26128 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 11 ms 1928 KB Output is correct
13 Correct 238 ms 26080 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 6 ms 1356 KB Output is correct
17 Correct 121 ms 12096 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 59 ms 7748 KB Output is correct
21 Correct 243 ms 26060 KB Output is correct
22 Correct 240 ms 26048 KB Output is correct
23 Correct 255 ms 26048 KB Output is correct
24 Correct 234 ms 25992 KB Output is correct
25 Correct 102 ms 12104 KB Output is correct
26 Correct 95 ms 12108 KB Output is correct
27 Correct 251 ms 25988 KB Output is correct
28 Correct 234 ms 26064 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 11 ms 2124 KB Output is correct
37 Correct 236 ms 27988 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 11 ms 2124 KB Output is correct
41 Correct 243 ms 27972 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 6 ms 1484 KB Output is correct
45 Correct 112 ms 14052 KB Output is correct
46 Correct 1 ms 332 KB Output is correct
47 Correct 1 ms 360 KB Output is correct
48 Correct 1 ms 332 KB Output is correct
49 Correct 66 ms 8240 KB Output is correct
50 Correct 236 ms 27972 KB Output is correct
51 Correct 241 ms 27960 KB Output is correct
52 Correct 264 ms 28012 KB Output is correct
53 Correct 107 ms 18116 KB Output is correct
54 Correct 103 ms 14124 KB Output is correct
55 Correct 236 ms 27964 KB Output is correct
56 Correct 257 ms 27984 KB Output is correct
57 Correct 101 ms 18116 KB Output is correct
58 Correct 1 ms 332 KB Output is correct
59 Correct 1 ms 332 KB Output is correct
60 Correct 6 ms 1520 KB Output is correct
61 Correct 114 ms 14140 KB Output is correct
62 Correct 1 ms 332 KB Output is correct
63 Correct 1 ms 332 KB Output is correct
64 Correct 1 ms 332 KB Output is correct
65 Correct 62 ms 8216 KB Output is correct
66 Correct 104 ms 14148 KB Output is correct
67 Correct 103 ms 14124 KB Output is correct
68 Correct 99 ms 14140 KB Output is correct
69 Correct 101 ms 18112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 11 ms 1996 KB Output is correct
7 Correct 247 ms 26128 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 11 ms 1928 KB Output is correct
13 Correct 238 ms 26080 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 6 ms 1356 KB Output is correct
17 Correct 121 ms 12096 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 59 ms 7748 KB Output is correct
21 Correct 243 ms 26060 KB Output is correct
22 Correct 240 ms 26048 KB Output is correct
23 Correct 255 ms 26048 KB Output is correct
24 Correct 234 ms 25992 KB Output is correct
25 Correct 102 ms 12104 KB Output is correct
26 Correct 95 ms 12108 KB Output is correct
27 Correct 251 ms 25988 KB Output is correct
28 Correct 234 ms 26064 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 11 ms 2124 KB Output is correct
37 Correct 236 ms 27988 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 11 ms 2124 KB Output is correct
41 Correct 243 ms 27972 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 6 ms 1484 KB Output is correct
45 Correct 112 ms 14052 KB Output is correct
46 Correct 1 ms 332 KB Output is correct
47 Correct 1 ms 360 KB Output is correct
48 Correct 1 ms 332 KB Output is correct
49 Correct 66 ms 8240 KB Output is correct
50 Correct 236 ms 27972 KB Output is correct
51 Correct 241 ms 27960 KB Output is correct
52 Correct 264 ms 28012 KB Output is correct
53 Correct 107 ms 18116 KB Output is correct
54 Correct 103 ms 14124 KB Output is correct
55 Correct 236 ms 27964 KB Output is correct
56 Correct 257 ms 27984 KB Output is correct
57 Correct 101 ms 18116 KB Output is correct
58 Correct 1 ms 332 KB Output is correct
59 Correct 1 ms 332 KB Output is correct
60 Correct 1 ms 332 KB Output is correct
61 Correct 64 ms 7740 KB Output is correct
62 Correct 239 ms 26020 KB Output is correct
63 Correct 257 ms 26048 KB Output is correct
64 Correct 250 ms 26052 KB Output is correct
65 Correct 1 ms 332 KB Output is correct
66 Correct 62 ms 8280 KB Output is correct
67 Correct 236 ms 28008 KB Output is correct
68 Correct 246 ms 28112 KB Output is correct
69 Correct 248 ms 27972 KB Output is correct
70 Correct 1 ms 332 KB Output is correct
71 Correct 1 ms 332 KB Output is correct
72 Correct 1 ms 332 KB Output is correct
73 Correct 61 ms 8296 KB Output is correct
74 Correct 237 ms 27948 KB Output is correct
75 Correct 246 ms 27972 KB Output is correct
76 Correct 242 ms 27824 KB Output is correct
77 Correct 236 ms 27972 KB Output is correct
78 Correct 1 ms 332 KB Output is correct
79 Correct 1 ms 332 KB Output is correct
80 Correct 6 ms 1520 KB Output is correct
81 Correct 114 ms 14140 KB Output is correct
82 Correct 1 ms 332 KB Output is correct
83 Correct 1 ms 332 KB Output is correct
84 Correct 1 ms 332 KB Output is correct
85 Correct 62 ms 8216 KB Output is correct
86 Correct 104 ms 14148 KB Output is correct
87 Correct 103 ms 14124 KB Output is correct
88 Correct 99 ms 14140 KB Output is correct
89 Correct 101 ms 18112 KB Output is correct
90 Correct 1 ms 332 KB Output is correct
91 Correct 1 ms 332 KB Output is correct
92 Correct 5 ms 1484 KB Output is correct
93 Correct 101 ms 14144 KB Output is correct
94 Correct 1 ms 332 KB Output is correct
95 Correct 1 ms 332 KB Output is correct
96 Correct 1 ms 332 KB Output is correct
97 Correct 28 ms 4792 KB Output is correct
98 Correct 102 ms 14132 KB Output is correct
99 Correct 102 ms 14136 KB Output is correct
100 Correct 102 ms 14196 KB Output is correct
101 Correct 98 ms 14020 KB Output is correct
102 Correct 100 ms 14132 KB Output is correct
103 Correct 97 ms 14020 KB Output is correct
104 Correct 99 ms 14120 KB Output is correct
105 Correct 105 ms 14020 KB Output is correct