답안 #977693

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
977693 2024-05-08T09:22:57 Z SmuggingSpun 슈퍼트리 잇기 (IOI20_supertrees) C++14
40 / 100
181 ms 20228 KB
#include "supertrees.h"
#include<bits/stdc++.h>
using namespace std;
int construct(vector<vector<int>>p){
	int n = p.size();
	bool is_sub1 = true, is_sub2 = true, is_sub3 = true;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			if(p[i][j] != 1){
				is_sub1 = false;
			}
			if(p[i][j] > 1){
				is_sub2 = false;
			}
			if(p[i][j] != 0 && p[i][j] != 2){
				is_sub3 = false;
			}
		}
	}
	if(is_sub1){
		p = vector<vector<int>>(n, vector<int>(n, 0));
		for(int i = 1; i < n; i++){
			p[i][i - 1] = p[i - 1][i] = 1;
		}
		build(p);
		return 1;
	}
	if(is_sub2){
		vector<int>par(n);
		iota(par.begin(), par.end(), 0);
		function<int(int)>find_set;
		find_set = [&] (int n){
			return n == par[n] ? n : par[n] = find_set(par[n]);	
		};
		function<void(int, int)>merge = [&] (int a, int b){
			par[find_set(a)] = find_set(b);
		};
		vector<bool>vis(n, false);
		vector<vector<int>>edge(n);
		for(int i = 0; i < n; i++){
			if(vis[i]){
				for(int j = 0; j < n; j++){
					if(i != j && int(find_set(i) == find_set(j)) != p[i][j]){
						return 0;
					}
				}
				continue;
			}
			for(int j = 0; j < n; j++){
				if(i != j && p[i][j] == 0 && find_set(i) == find_set(j)){
					return 0;
				}
				if(p[i][j] == 1){
					merge(i, j);
					vis[j] = true;
				}
			}
		}
		for(int i = 0; i < n; i++){
			edge[find_set(i)].emplace_back(i);
		}
		p = vector<vector<int>>(n, vector<int>(n, 0));
		for(int i = 0; i < n; i++){
			for(int j = 1; j < edge[i].size(); j++){
				p[edge[i][j]][edge[i][j - 1]] = p[edge[i][j - 1]][edge[i][j]] = 1;
			}
		}
		build(p);
		return 1;
	}
	if(is_sub3){
		vector<int>par(n);
		iota(par.begin(), par.end(), 0);
		function<int(int)>find_set;
		find_set = [&] (int n){
			return n == par[n] ? n : par[n] = find_set(par[n]);	
		};
		function<void(int, int)>merge = [&] (int a, int b){
			par[find_set(a)] = find_set(b);
		};
		vector<bool>vis(n, false);
		vector<vector<int>>edge(n);
		for(int i = 0; i < n; i++){
			if(vis[i]){
				for(int j = 0; j < n; j++){
					if(i != j && (find_set(i) == find_set(j)) != (p[i][j] == 2)){
						return 0;
					}
				}
				continue;
			}
			for(int j = 0; j < n; j++){
				if(i != j && p[i][j] == 0 && find_set(i) == find_set(j)){
					return 0;
				}
				if(p[i][j] == 2){
					merge(i, j);
					vis[j] = true;
				}
			}
		}
		for(int i = 0; i < n; i++){
			edge[find_set(i)].emplace_back(i);
		}
		p = vector<vector<int>>(n, vector<int>(n, 0));
		for(int i = 0; i < n; i++){
			if(edge[i].size() == 2){
				return 0;
			}
			if(edge[i].size() > 2){
				edge[i].emplace_back(edge[i][0]);
				for(int j = 1; j < edge[i].size(); j++){
					p[edge[i][j]][edge[i][j - 1]] = p[edge[i][j - 1]][edge[i][j]] = 1;
				}
			}
		}
		build(p);
		return 1;
	}
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:64:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |    for(int j = 1; j < edge[i].size(); j++){
      |                   ~~^~~~~~~~~~~~~~~~
supertrees.cpp:112:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  112 |     for(int j = 1; j < edge[i].size(); j++){
      |                    ~~^~~~~~~~~~~~~~~~
supertrees.cpp:120:1: warning: control reaches end of non-void function [-Wreturn-type]
  120 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 356 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 7 ms 1112 KB Output is correct
7 Correct 156 ms 18204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 356 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 7 ms 1112 KB Output is correct
7 Correct 156 ms 18204 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 7 ms 1116 KB Output is correct
13 Correct 168 ms 18264 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
17 Correct 76 ms 8220 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 42 ms 4856 KB Output is correct
21 Correct 175 ms 18064 KB Output is correct
22 Correct 181 ms 18184 KB Output is correct
23 Correct 171 ms 18256 KB Output is correct
24 Correct 171 ms 18132 KB Output is correct
25 Correct 81 ms 8200 KB Output is correct
26 Correct 69 ms 8200 KB Output is correct
27 Correct 172 ms 18256 KB Output is correct
28 Correct 171 ms 18108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 8 ms 1372 KB Output is correct
9 Correct 162 ms 20112 KB Output is correct
10 Correct 0 ms 544 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 7 ms 1216 KB Output is correct
13 Correct 166 ms 20136 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
17 Correct 68 ms 10228 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 42 ms 5404 KB Output is correct
22 Correct 167 ms 20048 KB Output is correct
23 Correct 167 ms 20052 KB Output is correct
24 Correct 170 ms 20036 KB Output is correct
25 Correct 75 ms 14160 KB Output is correct
26 Correct 79 ms 10064 KB Output is correct
27 Correct 165 ms 20088 KB Output is correct
28 Correct 170 ms 20228 KB Output is correct
29 Correct 79 ms 14276 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 0 ms 348 KB Output is correct
4 Correct 42 ms 5412 KB Output is correct
5 Correct 177 ms 19992 KB Output is correct
6 Correct 179 ms 20048 KB Output is correct
7 Correct 171 ms 20216 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 42 ms 5376 KB Output is correct
10 Correct 165 ms 20024 KB Output is correct
11 Correct 170 ms 20088 KB Output is correct
12 Correct 178 ms 20216 KB Output is correct
13 Correct 0 ms 432 KB Output is correct
14 Incorrect 0 ms 348 KB Too few ways to get from 4 to 5, should be 1 found 0
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 356 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 7 ms 1112 KB Output is correct
7 Correct 156 ms 18204 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 7 ms 1116 KB Output is correct
13 Correct 168 ms 18264 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
17 Correct 76 ms 8220 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 42 ms 4856 KB Output is correct
21 Correct 175 ms 18064 KB Output is correct
22 Correct 181 ms 18184 KB Output is correct
23 Correct 171 ms 18256 KB Output is correct
24 Correct 171 ms 18132 KB Output is correct
25 Correct 81 ms 8200 KB Output is correct
26 Correct 69 ms 8200 KB Output is correct
27 Correct 172 ms 18256 KB Output is correct
28 Correct 171 ms 18108 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 8 ms 1372 KB Output is correct
37 Correct 162 ms 20112 KB Output is correct
38 Correct 0 ms 544 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 7 ms 1216 KB Output is correct
41 Correct 166 ms 20136 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 3 ms 604 KB Output is correct
45 Correct 68 ms 10228 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 42 ms 5404 KB Output is correct
50 Correct 167 ms 20048 KB Output is correct
51 Correct 167 ms 20052 KB Output is correct
52 Correct 170 ms 20036 KB Output is correct
53 Correct 75 ms 14160 KB Output is correct
54 Correct 79 ms 10064 KB Output is correct
55 Correct 165 ms 20088 KB Output is correct
56 Correct 170 ms 20228 KB Output is correct
57 Correct 79 ms 14276 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 3 ms 676 KB Output is correct
61 Correct 71 ms 10228 KB Output is correct
62 Correct 1 ms 504 KB Output is correct
63 Incorrect 1 ms 348 KB Too few ways to get from 0 to 1, should be 1 found 0
64 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 356 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 7 ms 1112 KB Output is correct
7 Correct 156 ms 18204 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 7 ms 1116 KB Output is correct
13 Correct 168 ms 18264 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
17 Correct 76 ms 8220 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 42 ms 4856 KB Output is correct
21 Correct 175 ms 18064 KB Output is correct
22 Correct 181 ms 18184 KB Output is correct
23 Correct 171 ms 18256 KB Output is correct
24 Correct 171 ms 18132 KB Output is correct
25 Correct 81 ms 8200 KB Output is correct
26 Correct 69 ms 8200 KB Output is correct
27 Correct 172 ms 18256 KB Output is correct
28 Correct 171 ms 18108 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 8 ms 1372 KB Output is correct
37 Correct 162 ms 20112 KB Output is correct
38 Correct 0 ms 544 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 7 ms 1216 KB Output is correct
41 Correct 166 ms 20136 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 3 ms 604 KB Output is correct
45 Correct 68 ms 10228 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 42 ms 5404 KB Output is correct
50 Correct 167 ms 20048 KB Output is correct
51 Correct 167 ms 20052 KB Output is correct
52 Correct 170 ms 20036 KB Output is correct
53 Correct 75 ms 14160 KB Output is correct
54 Correct 79 ms 10064 KB Output is correct
55 Correct 165 ms 20088 KB Output is correct
56 Correct 170 ms 20228 KB Output is correct
57 Correct 79 ms 14276 KB Output is correct
58 Correct 1 ms 344 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 42 ms 5412 KB Output is correct
62 Correct 177 ms 19992 KB Output is correct
63 Correct 179 ms 20048 KB Output is correct
64 Correct 171 ms 20216 KB Output is correct
65 Correct 1 ms 348 KB Output is correct
66 Correct 42 ms 5376 KB Output is correct
67 Correct 165 ms 20024 KB Output is correct
68 Correct 170 ms 20088 KB Output is correct
69 Correct 178 ms 20216 KB Output is correct
70 Correct 0 ms 432 KB Output is correct
71 Incorrect 0 ms 348 KB Too few ways to get from 4 to 5, should be 1 found 0
72 Halted 0 ms 0 KB -