답안 #822198

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
822198 2023-08-12T02:01:46 Z Username4132 슈퍼트리 잇기 (IOI20_supertrees) C++14
100 / 100
229 ms 24120 KB
#include "supertrees.h"
#include<iostream>
#include <vector>
using namespace std;
#define forn(i, n) for(int i=0; i<(int)n; ++i)
#define forsn(i, s, n) for(int i=s; i<(int)n; ++i)
#define PB push_back

const int MAXN = 1010;
int n;
bool vi1[MAXN], vi2[MAXN], ad1[MAXN][MAXN], ad2[MAXN][MAXN];
vector<int> comp;

void dfs(int v, bool* vis, bool adj[][MAXN]){
	vis[v]=true;
	comp.PB(v);
	forn(i, n) if(!vis[i] && adj[v][i]) dfs(i, vis, adj);
}

bool check(vector<int>& com, bool adj[][MAXN]){
	bool ret = true;
	int sz = (int)com.size();
	forn(i, sz) forsn(j, i+1, sz) ret &= adj[com[i]][com[j]];
	return ret;
}



int construct(std::vector<std::vector<int>> p) {
	n = (int)p.size();
	std::vector<std::vector<int>> ans(n, vector<int>(n, 0));
	bool has3 = false;
	forn(i, n) forn(j, n) has3 |= (p[i][j] == 3);
	if(has3) return 0;
	forn(i, n) forn(j, n) ad1[i][j] = (p[i][j] > 0);
	forn(i, n) forn(j, n) ad2[i][j] = (p[i][j] == 1);
	forn(i, n) if(!vi1[i]){
		dfs(i, vi1, ad1);
		if(!check(comp, ad1)) return 0;
		vector<int> al, rep;
		swap(comp, al);
		for(int el:al) if(!vi2[el]){
			dfs(el, vi2, ad2);
			if(!check(comp, ad2)) return 0;
			forn(j, comp.size() - 1) ans[comp[j]][comp[j+1]]=ans[comp[j+1]][comp[j]]=1;
			rep.PB(comp.back());
			comp.clear();
		}
		if((int)rep.size() == 2) return 0;
		if((int)rep.size() > 2){
			forn(j, rep.size() - 1) ans[rep[j]][rep[j+1]]=ans[rep[j+1]][rep[j]]=1;
			ans[rep.front()][rep.back()]=ans[rep.back()][rep.front()]=1;
		}
	}
	build(ans);
	return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 1492 KB Output is correct
7 Correct 165 ms 24064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 1492 KB Output is correct
7 Correct 165 ms 24064 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1560 KB Output is correct
13 Correct 179 ms 23908 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 1112 KB Output is correct
17 Correct 74 ms 14080 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 50 ms 6728 KB Output is correct
21 Correct 176 ms 24100 KB Output is correct
22 Correct 174 ms 23952 KB Output is correct
23 Correct 200 ms 23948 KB Output is correct
24 Correct 220 ms 23952 KB Output is correct
25 Correct 86 ms 14096 KB Output is correct
26 Correct 76 ms 14108 KB Output is correct
27 Correct 169 ms 24120 KB Output is correct
28 Correct 165 ms 23972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 280 KB Output is correct
8 Correct 7 ms 1484 KB Output is correct
9 Correct 165 ms 23960 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1492 KB Output is correct
13 Correct 175 ms 24044 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 1108 KB Output is correct
17 Correct 71 ms 14108 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 63 ms 6724 KB Output is correct
22 Correct 169 ms 23956 KB Output is correct
23 Correct 161 ms 23964 KB Output is correct
24 Correct 167 ms 23952 KB Output is correct
25 Correct 80 ms 14092 KB Output is correct
26 Correct 77 ms 14072 KB Output is correct
27 Correct 180 ms 23948 KB Output is correct
28 Correct 172 ms 24056 KB Output is correct
29 Correct 84 ms 14092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 50 ms 6748 KB Output is correct
5 Correct 167 ms 23968 KB Output is correct
6 Correct 202 ms 23980 KB Output is correct
7 Correct 229 ms 23948 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 60 ms 6684 KB Output is correct
10 Correct 163 ms 23920 KB Output is correct
11 Correct 184 ms 23972 KB Output is correct
12 Correct 172 ms 23948 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 44 ms 6692 KB Output is correct
17 Correct 175 ms 24024 KB Output is correct
18 Correct 181 ms 23964 KB Output is correct
19 Correct 172 ms 23940 KB Output is correct
20 Correct 161 ms 23952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 1492 KB Output is correct
7 Correct 165 ms 24064 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1560 KB Output is correct
13 Correct 179 ms 23908 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 1112 KB Output is correct
17 Correct 74 ms 14080 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 50 ms 6728 KB Output is correct
21 Correct 176 ms 24100 KB Output is correct
22 Correct 174 ms 23952 KB Output is correct
23 Correct 200 ms 23948 KB Output is correct
24 Correct 220 ms 23952 KB Output is correct
25 Correct 86 ms 14096 KB Output is correct
26 Correct 76 ms 14108 KB Output is correct
27 Correct 169 ms 24120 KB Output is correct
28 Correct 165 ms 23972 KB Output is correct
29 Correct 1 ms 256 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 280 KB Output is correct
36 Correct 7 ms 1484 KB Output is correct
37 Correct 165 ms 23960 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 7 ms 1492 KB Output is correct
41 Correct 175 ms 24044 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 3 ms 1108 KB Output is correct
45 Correct 71 ms 14108 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 63 ms 6724 KB Output is correct
50 Correct 169 ms 23956 KB Output is correct
51 Correct 161 ms 23964 KB Output is correct
52 Correct 167 ms 23952 KB Output is correct
53 Correct 80 ms 14092 KB Output is correct
54 Correct 77 ms 14072 KB Output is correct
55 Correct 180 ms 23948 KB Output is correct
56 Correct 172 ms 24056 KB Output is correct
57 Correct 84 ms 14092 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 3 ms 1108 KB Output is correct
61 Correct 76 ms 14100 KB Output is correct
62 Correct 0 ms 212 KB Output is correct
63 Correct 0 ms 212 KB Output is correct
64 Correct 0 ms 308 KB Output is correct
65 Correct 47 ms 6752 KB Output is correct
66 Correct 72 ms 14096 KB Output is correct
67 Correct 81 ms 14080 KB Output is correct
68 Correct 72 ms 14096 KB Output is correct
69 Correct 83 ms 14108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 1492 KB Output is correct
7 Correct 165 ms 24064 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1560 KB Output is correct
13 Correct 179 ms 23908 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 1112 KB Output is correct
17 Correct 74 ms 14080 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 50 ms 6728 KB Output is correct
21 Correct 176 ms 24100 KB Output is correct
22 Correct 174 ms 23952 KB Output is correct
23 Correct 200 ms 23948 KB Output is correct
24 Correct 220 ms 23952 KB Output is correct
25 Correct 86 ms 14096 KB Output is correct
26 Correct 76 ms 14108 KB Output is correct
27 Correct 169 ms 24120 KB Output is correct
28 Correct 165 ms 23972 KB Output is correct
29 Correct 1 ms 256 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 280 KB Output is correct
36 Correct 7 ms 1484 KB Output is correct
37 Correct 165 ms 23960 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 7 ms 1492 KB Output is correct
41 Correct 175 ms 24044 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 3 ms 1108 KB Output is correct
45 Correct 71 ms 14108 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 63 ms 6724 KB Output is correct
50 Correct 169 ms 23956 KB Output is correct
51 Correct 161 ms 23964 KB Output is correct
52 Correct 167 ms 23952 KB Output is correct
53 Correct 80 ms 14092 KB Output is correct
54 Correct 77 ms 14072 KB Output is correct
55 Correct 180 ms 23948 KB Output is correct
56 Correct 172 ms 24056 KB Output is correct
57 Correct 84 ms 14092 KB Output is correct
58 Correct 1 ms 256 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 0 ms 212 KB Output is correct
61 Correct 50 ms 6748 KB Output is correct
62 Correct 167 ms 23968 KB Output is correct
63 Correct 202 ms 23980 KB Output is correct
64 Correct 229 ms 23948 KB Output is correct
65 Correct 1 ms 212 KB Output is correct
66 Correct 60 ms 6684 KB Output is correct
67 Correct 163 ms 23920 KB Output is correct
68 Correct 184 ms 23972 KB Output is correct
69 Correct 172 ms 23948 KB Output is correct
70 Correct 0 ms 212 KB Output is correct
71 Correct 0 ms 212 KB Output is correct
72 Correct 1 ms 212 KB Output is correct
73 Correct 44 ms 6692 KB Output is correct
74 Correct 175 ms 24024 KB Output is correct
75 Correct 181 ms 23964 KB Output is correct
76 Correct 172 ms 23940 KB Output is correct
77 Correct 161 ms 23952 KB Output is correct
78 Correct 1 ms 212 KB Output is correct
79 Correct 0 ms 212 KB Output is correct
80 Correct 3 ms 1108 KB Output is correct
81 Correct 76 ms 14100 KB Output is correct
82 Correct 0 ms 212 KB Output is correct
83 Correct 0 ms 212 KB Output is correct
84 Correct 0 ms 308 KB Output is correct
85 Correct 47 ms 6752 KB Output is correct
86 Correct 72 ms 14096 KB Output is correct
87 Correct 81 ms 14080 KB Output is correct
88 Correct 72 ms 14096 KB Output is correct
89 Correct 83 ms 14108 KB Output is correct
90 Correct 1 ms 212 KB Output is correct
91 Correct 1 ms 212 KB Output is correct
92 Correct 5 ms 724 KB Output is correct
93 Correct 109 ms 12044 KB Output is correct
94 Correct 1 ms 212 KB Output is correct
95 Correct 1 ms 312 KB Output is correct
96 Correct 1 ms 316 KB Output is correct
97 Correct 20 ms 3660 KB Output is correct
98 Correct 66 ms 14092 KB Output is correct
99 Correct 72 ms 14088 KB Output is correct
100 Correct 70 ms 14084 KB Output is correct
101 Correct 68 ms 14080 KB Output is correct
102 Correct 70 ms 14088 KB Output is correct
103 Correct 74 ms 14076 KB Output is correct
104 Correct 72 ms 14096 KB Output is correct
105 Correct 69 ms 14080 KB Output is correct