답안 #928015

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
928015 2024-02-15T17:29:48 Z velislavgarkov 슈퍼트리 잇기 (IOI20_supertrees) C++14
100 / 100
188 ms 28088 KB
#include "supertrees.h"
#include <iostream>
#include <vector>
using namespace std;
const int MAXN=1e3+10;
vector<vector<int> > ans;
vector <int> v[MAXN], ones, ch, comp[MAXN];
int par[MAXN], d[MAXN];
bool used[MAXN], fl;
int root(int x) {
	if (x==par[x]) return x;
	return par[x]=root(par[x]);
}
void connect(int a, int b) {
	int ra, rb;
	ra=root(a);
	rb=root(b);
	if (ra==rb) return;
	if (d[ra]>d[rb]) par[rb]=ra;
	else if (d[rb]>d[ra]) par[ra]=rb;
	else {
		par[rb]=ra;
		d[ra]++;
	}
}
void find_comp(int x) {
	used[x]=true;
	ch.push_back(x);
	for (auto i:v[x]) {
		if (used[i]) continue;
		find_comp(i);
	}
}
void add_edge(int a, int b) {
	ans[a][b]=ans[b][a]=1;
}
int construct(vector<vector<int> > p) {
	int n = p.size();
	ans.resize(n);
	fl=true;
	for (int i=0;i<n;i++) {
		if (p[i][i]!=1) fl=false;
		for (int j=i+1;j<n;j++) {
			if (p[i][j]==3) fl=false;
			if (p[i][j]) {
				v[i].push_back(j);
				v[j].push_back(i);
			}
		}
		par[i]=i;
		d[i]=used[i]=0;
		ans[i].resize(n);
		for (int j=0;j<n;j++) ans[i][j]=0;
	}
	if (!fl) return 0;
	for (int x=0;x<n;x++) {
		if (used[x]) continue;
		if (!ch.empty()) ch.clear();
		find_comp(x);
		if (ch.size()==1) continue;
		bool two=false;
		for (int i=0;i<ch.size();i++) {
			for (int j=i+1;j<ch.size();j++) {
				if (p[ch[i]][ch[j]]==0) fl=false;
				else if (p[ch[i]][ch[j]]==1) connect(ch[i],ch[j]);
				else two=true;
			}
		}
		if (two && ch.size()==2) fl=false;
		if (!ones.empty()) ones.clear();
		for (int i=0;i<ch.size();i++) {
			int ri=root(ch[i]);
			if (comp[ri].empty()) ones.push_back(ri);
			comp[ri].push_back(ch[i]);
		}
		for (int i=0;i<ones.size();i++) {
			int nxt=(i-1+ones.size())%ones.size();
			if (nxt!=i) add_edge(ones[i],ones[nxt]);
			int cur=ones[i];
			for (int j=0;j<comp[cur].size();j++) {
				if (j>0) add_edge(comp[cur][j-1],comp[cur][j]);
				for (int k=1;k<comp[cur].size();k++) {
					if (p[comp[cur][j]][comp[cur][j]]==2) fl=false;
				}
			}
		}
	}
	if (!fl) return 0;
	build(ans);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:62:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |   for (int i=0;i<ch.size();i++) {
      |                ~^~~~~~~~~~
supertrees.cpp:63:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |    for (int j=i+1;j<ch.size();j++) {
      |                   ~^~~~~~~~~~
supertrees.cpp:71:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |   for (int i=0;i<ch.size();i++) {
      |                ~^~~~~~~~~~
supertrees.cpp:76:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |   for (int i=0;i<ones.size();i++) {
      |                ~^~~~~~~~~~~~
supertrees.cpp:80:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |    for (int j=0;j<comp[cur].size();j++) {
      |                 ~^~~~~~~~~~~~~~~~~
supertrees.cpp:82:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |     for (int k=1;k<comp[cur].size();k++) {
      |                  ~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1372 KB Output is correct
7 Correct 162 ms 26300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1372 KB Output is correct
7 Correct 162 ms 26300 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 6 ms 1372 KB Output is correct
13 Correct 152 ms 22216 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 4 ms 1112 KB Output is correct
17 Correct 79 ms 15428 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 41 ms 5772 KB Output is correct
21 Correct 155 ms 22612 KB Output is correct
22 Correct 177 ms 22100 KB Output is correct
23 Correct 161 ms 24148 KB Output is correct
24 Correct 161 ms 22092 KB Output is correct
25 Correct 65 ms 12884 KB Output is correct
26 Correct 64 ms 12116 KB Output is correct
27 Correct 162 ms 25352 KB Output is correct
28 Correct 161 ms 22024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 7 ms 1372 KB Output is correct
9 Correct 153 ms 23980 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 7 ms 1628 KB Output is correct
13 Correct 160 ms 28088 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 4 ms 956 KB Output is correct
17 Correct 100 ms 16956 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 38 ms 6484 KB Output is correct
22 Correct 156 ms 24744 KB Output is correct
23 Correct 154 ms 24152 KB Output is correct
24 Correct 162 ms 27148 KB Output is correct
25 Correct 64 ms 14056 KB Output is correct
26 Correct 84 ms 14812 KB Output is correct
27 Correct 160 ms 24232 KB Output is correct
28 Correct 162 ms 26280 KB Output is correct
29 Correct 68 ms 14268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 38 ms 5972 KB Output is correct
5 Correct 159 ms 23020 KB Output is correct
6 Correct 159 ms 22356 KB Output is correct
7 Correct 161 ms 24124 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 39 ms 5972 KB Output is correct
10 Correct 155 ms 22588 KB Output is correct
11 Correct 158 ms 22180 KB Output is correct
12 Correct 160 ms 25144 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 38 ms 5972 KB Output is correct
17 Correct 188 ms 22608 KB Output is correct
18 Correct 172 ms 22824 KB Output is correct
19 Correct 154 ms 22440 KB Output is correct
20 Correct 153 ms 22096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1372 KB Output is correct
7 Correct 162 ms 26300 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 6 ms 1372 KB Output is correct
13 Correct 152 ms 22216 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 4 ms 1112 KB Output is correct
17 Correct 79 ms 15428 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 41 ms 5772 KB Output is correct
21 Correct 155 ms 22612 KB Output is correct
22 Correct 177 ms 22100 KB Output is correct
23 Correct 161 ms 24148 KB Output is correct
24 Correct 161 ms 22092 KB Output is correct
25 Correct 65 ms 12884 KB Output is correct
26 Correct 64 ms 12116 KB Output is correct
27 Correct 162 ms 25352 KB Output is correct
28 Correct 161 ms 22024 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 600 KB Output is correct
35 Correct 0 ms 344 KB Output is correct
36 Correct 7 ms 1372 KB Output is correct
37 Correct 153 ms 23980 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 7 ms 1628 KB Output is correct
41 Correct 160 ms 28088 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 0 ms 344 KB Output is correct
44 Correct 4 ms 956 KB Output is correct
45 Correct 100 ms 16956 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 38 ms 6484 KB Output is correct
50 Correct 156 ms 24744 KB Output is correct
51 Correct 154 ms 24152 KB Output is correct
52 Correct 162 ms 27148 KB Output is correct
53 Correct 64 ms 14056 KB Output is correct
54 Correct 84 ms 14812 KB Output is correct
55 Correct 160 ms 24232 KB Output is correct
56 Correct 162 ms 26280 KB Output is correct
57 Correct 68 ms 14268 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 4 ms 1116 KB Output is correct
61 Correct 81 ms 19064 KB Output is correct
62 Correct 1 ms 348 KB Output is correct
63 Correct 0 ms 348 KB Output is correct
64 Correct 0 ms 348 KB Output is correct
65 Correct 47 ms 6256 KB Output is correct
66 Correct 70 ms 15020 KB Output is correct
67 Correct 67 ms 14652 KB Output is correct
68 Correct 66 ms 14396 KB Output is correct
69 Correct 67 ms 14164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1372 KB Output is correct
7 Correct 162 ms 26300 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 6 ms 1372 KB Output is correct
13 Correct 152 ms 22216 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 4 ms 1112 KB Output is correct
17 Correct 79 ms 15428 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 41 ms 5772 KB Output is correct
21 Correct 155 ms 22612 KB Output is correct
22 Correct 177 ms 22100 KB Output is correct
23 Correct 161 ms 24148 KB Output is correct
24 Correct 161 ms 22092 KB Output is correct
25 Correct 65 ms 12884 KB Output is correct
26 Correct 64 ms 12116 KB Output is correct
27 Correct 162 ms 25352 KB Output is correct
28 Correct 161 ms 22024 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 600 KB Output is correct
35 Correct 0 ms 344 KB Output is correct
36 Correct 7 ms 1372 KB Output is correct
37 Correct 153 ms 23980 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 7 ms 1628 KB Output is correct
41 Correct 160 ms 28088 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 0 ms 344 KB Output is correct
44 Correct 4 ms 956 KB Output is correct
45 Correct 100 ms 16956 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 38 ms 6484 KB Output is correct
50 Correct 156 ms 24744 KB Output is correct
51 Correct 154 ms 24152 KB Output is correct
52 Correct 162 ms 27148 KB Output is correct
53 Correct 64 ms 14056 KB Output is correct
54 Correct 84 ms 14812 KB Output is correct
55 Correct 160 ms 24232 KB Output is correct
56 Correct 162 ms 26280 KB Output is correct
57 Correct 68 ms 14268 KB Output is correct
58 Correct 1 ms 344 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 1 ms 348 KB Output is correct
61 Correct 38 ms 5972 KB Output is correct
62 Correct 159 ms 23020 KB Output is correct
63 Correct 159 ms 22356 KB Output is correct
64 Correct 161 ms 24124 KB Output is correct
65 Correct 1 ms 364 KB Output is correct
66 Correct 39 ms 5972 KB Output is correct
67 Correct 155 ms 22588 KB Output is correct
68 Correct 158 ms 22180 KB Output is correct
69 Correct 160 ms 25144 KB Output is correct
70 Correct 0 ms 344 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Correct 0 ms 348 KB Output is correct
73 Correct 38 ms 5972 KB Output is correct
74 Correct 188 ms 22608 KB Output is correct
75 Correct 172 ms 22824 KB Output is correct
76 Correct 154 ms 22440 KB Output is correct
77 Correct 153 ms 22096 KB Output is correct
78 Correct 0 ms 348 KB Output is correct
79 Correct 0 ms 348 KB Output is correct
80 Correct 4 ms 1116 KB Output is correct
81 Correct 81 ms 19064 KB Output is correct
82 Correct 1 ms 348 KB Output is correct
83 Correct 0 ms 348 KB Output is correct
84 Correct 0 ms 348 KB Output is correct
85 Correct 47 ms 6256 KB Output is correct
86 Correct 70 ms 15020 KB Output is correct
87 Correct 67 ms 14652 KB Output is correct
88 Correct 66 ms 14396 KB Output is correct
89 Correct 67 ms 14164 KB Output is correct
90 Correct 0 ms 348 KB Output is correct
91 Correct 1 ms 348 KB Output is correct
92 Correct 4 ms 1116 KB Output is correct
93 Correct 82 ms 18604 KB Output is correct
94 Correct 1 ms 344 KB Output is correct
95 Correct 0 ms 348 KB Output is correct
96 Correct 1 ms 348 KB Output is correct
97 Correct 17 ms 3756 KB Output is correct
98 Correct 67 ms 14640 KB Output is correct
99 Correct 66 ms 14712 KB Output is correct
100 Correct 70 ms 14512 KB Output is correct
101 Correct 82 ms 14144 KB Output is correct
102 Correct 70 ms 18224 KB Output is correct
103 Correct 72 ms 18232 KB Output is correct
104 Correct 74 ms 18344 KB Output is correct
105 Correct 73 ms 16952 KB Output is correct