답안 #733979

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
733979 2023-05-01T12:45:30 Z ismayil 슈퍼트리 잇기 (IOI20_supertrees) C++17
100 / 100
252 ms 23816 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e3 + 3;

struct DSU{
	int par[MAX];
	int find(int u){
		if(par[u] < 0) return u;
		return par[u] = find(par[u]);
	}
	bool unite(int u, int v){
		u = find(u), v = find(v);
		if(u == v) return false;
		if(par[u] > par[v]) swap(u, v);
		par[u] += par[v];
		par[v] = u;
		return true;
	}
	DSU(){
		memset(par, -1, sizeof(par));
	}
};
int construct(vector<vector<int>> p) 
{
	for(auto i : p) for(auto j : i) if(j == 3) return 0;
	DSU dsu1, dsu2;
	int n = p.size();
	vector<vector<int>> answer(n, vector<int>(n, 0));
	int mark[n] = {0};
	for (int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			if(p[i][j] == 0 && dsu1.find(i) == dsu1.find(j)) return 0;
			if(p[i][j] != 1) continue;
			if(dsu1.unite(i, j)){
				answer[i][j] = answer[j][i] = 1;
			}
		}
	}
	for (int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			if(p[dsu1.find(i)][dsu1.find(j)] == 2){
				dsu2.unite(dsu1.find(i), dsu1.find(j));
			} 
		}
	}
	for (int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			if(dsu2.find(dsu1.find(i)) == dsu2.find(dsu1.find(j)) && p[dsu1.find(i)][dsu1.find(j)] == 0) return 0;
		}
	}
	vector<int> comp[n];
	for(int i = 0; i < n; i++){
		if(mark[dsu1.find(i)]) continue;
		mark[dsu1.find(i)] = 1;
		comp[dsu2.find(dsu1.find(i))].push_back(dsu1.find(i));
	}
	for(auto &v : comp){
		if(v.size() == 2) return 0;
		if(v.size() < 2) continue;
		for(int j = 0; j < v.size() - 1; j++) answer[v[j]][v[j + 1]] = answer[v[j + 1]][v[j]] = 1;
		answer[v[v.size() - 1]][v[0]] = answer[v[0]][v[v.size() - 1]] = 1;
	}
	build(answer);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:61:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |   for(int j = 0; j < v.size() - 1; j++) answer[v[j]][v[j + 1]] = answer[v[j + 1]][v[j]] = 1;
      |                  ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 8 ms 1108 KB Output is correct
7 Correct 238 ms 22000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 8 ms 1108 KB Output is correct
7 Correct 238 ms 22000 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 13 ms 1204 KB Output is correct
13 Correct 250 ms 22080 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 5 ms 724 KB Output is correct
17 Correct 104 ms 12048 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 54 ms 5760 KB Output is correct
21 Correct 215 ms 21964 KB Output is correct
22 Correct 221 ms 22020 KB Output is correct
23 Correct 221 ms 22012 KB Output is correct
24 Correct 211 ms 21988 KB Output is correct
25 Correct 73 ms 12036 KB Output is correct
26 Correct 75 ms 12028 KB Output is correct
27 Correct 252 ms 22024 KB Output is correct
28 Correct 218 ms 22012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 300 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 9 ms 1236 KB Output is correct
9 Correct 236 ms 23816 KB Output is correct
10 Correct 1 ms 304 KB Output is correct
11 Correct 1 ms 304 KB Output is correct
12 Correct 8 ms 1212 KB Output is correct
13 Correct 224 ms 23444 KB Output is correct
14 Correct 1 ms 240 KB Output is correct
15 Correct 1 ms 296 KB Output is correct
16 Correct 6 ms 852 KB Output is correct
17 Correct 96 ms 13300 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 304 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 50 ms 6260 KB Output is correct
22 Correct 210 ms 23768 KB Output is correct
23 Correct 193 ms 23700 KB Output is correct
24 Correct 208 ms 23792 KB Output is correct
25 Correct 80 ms 13824 KB Output is correct
26 Correct 87 ms 13820 KB Output is correct
27 Correct 185 ms 23688 KB Output is correct
28 Correct 224 ms 23632 KB Output is correct
29 Correct 76 ms 13816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 64 ms 5708 KB Output is correct
5 Correct 201 ms 22156 KB Output is correct
6 Correct 232 ms 22032 KB Output is correct
7 Correct 213 ms 22084 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 51 ms 5688 KB Output is correct
10 Correct 189 ms 21992 KB Output is correct
11 Correct 197 ms 22140 KB Output is correct
12 Correct 221 ms 22032 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 50 ms 5676 KB Output is correct
17 Correct 202 ms 22032 KB Output is correct
18 Correct 203 ms 22024 KB Output is correct
19 Correct 189 ms 22000 KB Output is correct
20 Correct 203 ms 22032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 8 ms 1108 KB Output is correct
7 Correct 238 ms 22000 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 13 ms 1204 KB Output is correct
13 Correct 250 ms 22080 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 5 ms 724 KB Output is correct
17 Correct 104 ms 12048 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 54 ms 5760 KB Output is correct
21 Correct 215 ms 21964 KB Output is correct
22 Correct 221 ms 22020 KB Output is correct
23 Correct 221 ms 22012 KB Output is correct
24 Correct 211 ms 21988 KB Output is correct
25 Correct 73 ms 12036 KB Output is correct
26 Correct 75 ms 12028 KB Output is correct
27 Correct 252 ms 22024 KB Output is correct
28 Correct 218 ms 22012 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 300 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 9 ms 1236 KB Output is correct
37 Correct 236 ms 23816 KB Output is correct
38 Correct 1 ms 304 KB Output is correct
39 Correct 1 ms 304 KB Output is correct
40 Correct 8 ms 1212 KB Output is correct
41 Correct 224 ms 23444 KB Output is correct
42 Correct 1 ms 240 KB Output is correct
43 Correct 1 ms 296 KB Output is correct
44 Correct 6 ms 852 KB Output is correct
45 Correct 96 ms 13300 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 304 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 50 ms 6260 KB Output is correct
50 Correct 210 ms 23768 KB Output is correct
51 Correct 193 ms 23700 KB Output is correct
52 Correct 208 ms 23792 KB Output is correct
53 Correct 80 ms 13824 KB Output is correct
54 Correct 87 ms 13820 KB Output is correct
55 Correct 185 ms 23688 KB Output is correct
56 Correct 224 ms 23632 KB Output is correct
57 Correct 76 ms 13816 KB Output is correct
58 Correct 0 ms 300 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 4 ms 852 KB Output is correct
61 Correct 78 ms 14124 KB Output is correct
62 Correct 1 ms 304 KB Output is correct
63 Correct 1 ms 212 KB Output is correct
64 Correct 1 ms 212 KB Output is correct
65 Correct 49 ms 6264 KB Output is correct
66 Correct 82 ms 14068 KB Output is correct
67 Correct 73 ms 14084 KB Output is correct
68 Correct 109 ms 13992 KB Output is correct
69 Correct 81 ms 14080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 8 ms 1108 KB Output is correct
7 Correct 238 ms 22000 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 13 ms 1204 KB Output is correct
13 Correct 250 ms 22080 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 5 ms 724 KB Output is correct
17 Correct 104 ms 12048 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 54 ms 5760 KB Output is correct
21 Correct 215 ms 21964 KB Output is correct
22 Correct 221 ms 22020 KB Output is correct
23 Correct 221 ms 22012 KB Output is correct
24 Correct 211 ms 21988 KB Output is correct
25 Correct 73 ms 12036 KB Output is correct
26 Correct 75 ms 12028 KB Output is correct
27 Correct 252 ms 22024 KB Output is correct
28 Correct 218 ms 22012 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 300 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 9 ms 1236 KB Output is correct
37 Correct 236 ms 23816 KB Output is correct
38 Correct 1 ms 304 KB Output is correct
39 Correct 1 ms 304 KB Output is correct
40 Correct 8 ms 1212 KB Output is correct
41 Correct 224 ms 23444 KB Output is correct
42 Correct 1 ms 240 KB Output is correct
43 Correct 1 ms 296 KB Output is correct
44 Correct 6 ms 852 KB Output is correct
45 Correct 96 ms 13300 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 304 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 50 ms 6260 KB Output is correct
50 Correct 210 ms 23768 KB Output is correct
51 Correct 193 ms 23700 KB Output is correct
52 Correct 208 ms 23792 KB Output is correct
53 Correct 80 ms 13824 KB Output is correct
54 Correct 87 ms 13820 KB Output is correct
55 Correct 185 ms 23688 KB Output is correct
56 Correct 224 ms 23632 KB Output is correct
57 Correct 76 ms 13816 KB Output is correct
58 Correct 0 ms 212 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 1 ms 212 KB Output is correct
61 Correct 64 ms 5708 KB Output is correct
62 Correct 201 ms 22156 KB Output is correct
63 Correct 232 ms 22032 KB Output is correct
64 Correct 213 ms 22084 KB Output is correct
65 Correct 0 ms 212 KB Output is correct
66 Correct 51 ms 5688 KB Output is correct
67 Correct 189 ms 21992 KB Output is correct
68 Correct 197 ms 22140 KB Output is correct
69 Correct 221 ms 22032 KB Output is correct
70 Correct 0 ms 212 KB Output is correct
71 Correct 0 ms 212 KB Output is correct
72 Correct 0 ms 212 KB Output is correct
73 Correct 50 ms 5676 KB Output is correct
74 Correct 202 ms 22032 KB Output is correct
75 Correct 203 ms 22024 KB Output is correct
76 Correct 189 ms 22000 KB Output is correct
77 Correct 203 ms 22032 KB Output is correct
78 Correct 0 ms 300 KB Output is correct
79 Correct 1 ms 212 KB Output is correct
80 Correct 4 ms 852 KB Output is correct
81 Correct 78 ms 14124 KB Output is correct
82 Correct 1 ms 304 KB Output is correct
83 Correct 1 ms 212 KB Output is correct
84 Correct 1 ms 212 KB Output is correct
85 Correct 49 ms 6264 KB Output is correct
86 Correct 82 ms 14068 KB Output is correct
87 Correct 73 ms 14084 KB Output is correct
88 Correct 109 ms 13992 KB Output is correct
89 Correct 81 ms 14080 KB Output is correct
90 Correct 1 ms 212 KB Output is correct
91 Correct 1 ms 212 KB Output is correct
92 Correct 7 ms 664 KB Output is correct
93 Correct 77 ms 10116 KB Output is correct
94 Correct 1 ms 212 KB Output is correct
95 Correct 1 ms 300 KB Output is correct
96 Correct 1 ms 212 KB Output is correct
97 Correct 20 ms 2668 KB Output is correct
98 Correct 77 ms 10228 KB Output is correct
99 Correct 78 ms 10104 KB Output is correct
100 Correct 76 ms 10100 KB Output is correct
101 Correct 72 ms 10032 KB Output is correct
102 Correct 81 ms 10112 KB Output is correct
103 Correct 70 ms 10152 KB Output is correct
104 Correct 73 ms 10112 KB Output is correct
105 Correct 83 ms 10116 KB Output is correct