답안 #578065

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
578065 2022-06-15T21:28:38 Z 1ne 슈퍼트리 잇기 (IOI20_supertrees) C++14
100 / 100
204 ms 22108 KB
#include "supertrees.h"
#include <vector>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
struct DSU{
	vector<int>parent;
	vector<int>sz;
	vector<vector<int>>comp;
	void build(int n){
		parent.resize(n);
		sz.resize(n);
		comp.resize(n);
		for (int i = 0;i<n;++i){
			parent[i] = i;
			sz[i] = 1;
			comp[i].push_back(i);
		}
	}
	int findsets(int v){
		if (v == parent[v])return v;
		parent[v] = findsets(parent[v]);
		return parent[v];
	}
	bool unionset(int a,int b){
		int u = findsets(a);
		int v = findsets(b);
		if (u == v)return false;
		if (sz[u] < sz[v])swap(u,v);
		parent[v] = u;
		sz[u]+=sz[v];
		sz[v] = 0;
		while(!comp[v].empty()){
			comp[u].push_back(comp[v].back());
			comp[v].pop_back();
		}
		return true;
	}
};
int construct(std::vector<std::vector<int>> p) {
	int n = p.size();
	std::vector<std::vector<int>> answer(n,vector<int>(n,0));
	for (int i = 0;i<n;++i){
		for (int j = 0;j<n;++j){
			if (p[i][j] == 3)return 0;
		}
	}
	DSU st;
	st.build(n);
	for (int i = 0;i<n;++i){
		for (int j = i + 1;j<n;++j){
			int u = st.findsets(i);
			int v = st.findsets(j);
			if (p[i][j]==1 && st.unionset(i,j)){
				answer[u][v] = true;
				answer[v][u] = true;
			}
		}
	}
	vector<int>cyc(n,0);
	for (int i = 0;i<n;++i){
		vector<int>cycle;
		cycle.push_back(st.findsets(i));
		for (int j = 0;j<n;++j){
			if (p[i][j] == 2){
				if (st.findsets(i) == st.findsets(j))continue;
				cycle.push_back(st.findsets(j));
				st.unionset(i,j);
			}
		}
		if (cycle.size()==2)return 0;
		if (cycle.size()==1)continue;
		cyc[st.findsets(i)]++;
		for (int j = 0;j<cycle.size();++j){
			answer[cycle[j]][cycle[(j + 1)%(int)cycle.size()]] = true;
			answer[cycle[(j + 1)%(int)cycle.size()]][cycle[j]] = true;
		}
	}
	for (int i = 0;i<n;++i){
		for (int j = 0;j<n;++j){
			if (p[i][j] && st.findsets(i)!=st.findsets(j))return 0;
			if (!p[i][j] && st.findsets(i)==st.findsets(j))return 0;
		}
	}
	for (int i = 0;i<n;++i){
		if (cyc[st.findsets(i)] > 1)return 0;
	}
	build(answer);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:78:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |   for (int j = 0;j<cycle.size();++j){
      |                  ~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 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 8 ms 1108 KB Output is correct
7 Correct 185 ms 22048 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 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 8 ms 1108 KB Output is correct
7 Correct 185 ms 22048 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 8 ms 1108 KB Output is correct
13 Correct 179 ms 22020 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 724 KB Output is correct
17 Correct 84 ms 12172 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 48 ms 5792 KB Output is correct
21 Correct 204 ms 22020 KB Output is correct
22 Correct 181 ms 22036 KB Output is correct
23 Correct 195 ms 22016 KB Output is correct
24 Correct 177 ms 22092 KB Output is correct
25 Correct 72 ms 12160 KB Output is correct
26 Correct 77 ms 12172 KB Output is correct
27 Correct 201 ms 22020 KB Output is correct
28 Correct 182 ms 22008 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 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 1 ms 212 KB Output is correct
8 Correct 8 ms 1096 KB Output is correct
9 Correct 177 ms 22024 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 8 ms 1168 KB Output is correct
13 Correct 183 ms 22028 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 724 KB Output is correct
17 Correct 80 ms 12160 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 48 ms 5700 KB Output is correct
22 Correct 185 ms 22108 KB Output is correct
23 Correct 178 ms 22020 KB Output is correct
24 Correct 196 ms 22092 KB Output is correct
25 Correct 67 ms 12176 KB Output is correct
26 Correct 68 ms 12160 KB Output is correct
27 Correct 180 ms 22092 KB Output is correct
28 Correct 200 ms 22036 KB Output is correct
29 Correct 68 ms 12176 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 0 ms 212 KB Output is correct
4 Correct 49 ms 5760 KB Output is correct
5 Correct 181 ms 22024 KB Output is correct
6 Correct 181 ms 22080 KB Output is correct
7 Correct 194 ms 22028 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 46 ms 5676 KB Output is correct
10 Correct 183 ms 22028 KB Output is correct
11 Correct 183 ms 22016 KB Output is correct
12 Correct 194 ms 22100 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 46 ms 5764 KB Output is correct
17 Correct 181 ms 22000 KB Output is correct
18 Correct 183 ms 22092 KB Output is correct
19 Correct 187 ms 22004 KB Output is correct
20 Correct 174 ms 22040 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 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 8 ms 1108 KB Output is correct
7 Correct 185 ms 22048 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 8 ms 1108 KB Output is correct
13 Correct 179 ms 22020 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 724 KB Output is correct
17 Correct 84 ms 12172 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 48 ms 5792 KB Output is correct
21 Correct 204 ms 22020 KB Output is correct
22 Correct 181 ms 22036 KB Output is correct
23 Correct 195 ms 22016 KB Output is correct
24 Correct 177 ms 22092 KB Output is correct
25 Correct 72 ms 12160 KB Output is correct
26 Correct 77 ms 12172 KB Output is correct
27 Correct 201 ms 22020 KB Output is correct
28 Correct 182 ms 22008 KB Output is correct
29 Correct 0 ms 212 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 1 ms 212 KB Output is correct
36 Correct 8 ms 1096 KB Output is correct
37 Correct 177 ms 22024 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 8 ms 1168 KB Output is correct
41 Correct 183 ms 22028 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 724 KB Output is correct
45 Correct 80 ms 12160 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 48 ms 5700 KB Output is correct
50 Correct 185 ms 22108 KB Output is correct
51 Correct 178 ms 22020 KB Output is correct
52 Correct 196 ms 22092 KB Output is correct
53 Correct 67 ms 12176 KB Output is correct
54 Correct 68 ms 12160 KB Output is correct
55 Correct 180 ms 22092 KB Output is correct
56 Correct 200 ms 22036 KB Output is correct
57 Correct 68 ms 12176 KB Output is correct
58 Correct 0 ms 212 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 4 ms 724 KB Output is correct
61 Correct 85 ms 12160 KB Output is correct
62 Correct 0 ms 212 KB Output is correct
63 Correct 0 ms 212 KB Output is correct
64 Correct 1 ms 212 KB Output is correct
65 Correct 51 ms 5748 KB Output is correct
66 Correct 72 ms 12108 KB Output is correct
67 Correct 71 ms 12108 KB Output is correct
68 Correct 68 ms 12160 KB Output is correct
69 Correct 68 ms 12160 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 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 8 ms 1108 KB Output is correct
7 Correct 185 ms 22048 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 8 ms 1108 KB Output is correct
13 Correct 179 ms 22020 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 724 KB Output is correct
17 Correct 84 ms 12172 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 48 ms 5792 KB Output is correct
21 Correct 204 ms 22020 KB Output is correct
22 Correct 181 ms 22036 KB Output is correct
23 Correct 195 ms 22016 KB Output is correct
24 Correct 177 ms 22092 KB Output is correct
25 Correct 72 ms 12160 KB Output is correct
26 Correct 77 ms 12172 KB Output is correct
27 Correct 201 ms 22020 KB Output is correct
28 Correct 182 ms 22008 KB Output is correct
29 Correct 0 ms 212 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 1 ms 212 KB Output is correct
36 Correct 8 ms 1096 KB Output is correct
37 Correct 177 ms 22024 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 8 ms 1168 KB Output is correct
41 Correct 183 ms 22028 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 724 KB Output is correct
45 Correct 80 ms 12160 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 48 ms 5700 KB Output is correct
50 Correct 185 ms 22108 KB Output is correct
51 Correct 178 ms 22020 KB Output is correct
52 Correct 196 ms 22092 KB Output is correct
53 Correct 67 ms 12176 KB Output is correct
54 Correct 68 ms 12160 KB Output is correct
55 Correct 180 ms 22092 KB Output is correct
56 Correct 200 ms 22036 KB Output is correct
57 Correct 68 ms 12176 KB Output is correct
58 Correct 0 ms 212 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 0 ms 212 KB Output is correct
61 Correct 49 ms 5760 KB Output is correct
62 Correct 181 ms 22024 KB Output is correct
63 Correct 181 ms 22080 KB Output is correct
64 Correct 194 ms 22028 KB Output is correct
65 Correct 1 ms 212 KB Output is correct
66 Correct 46 ms 5676 KB Output is correct
67 Correct 183 ms 22028 KB Output is correct
68 Correct 183 ms 22016 KB Output is correct
69 Correct 194 ms 22100 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 46 ms 5764 KB Output is correct
74 Correct 181 ms 22000 KB Output is correct
75 Correct 183 ms 22092 KB Output is correct
76 Correct 187 ms 22004 KB Output is correct
77 Correct 174 ms 22040 KB Output is correct
78 Correct 0 ms 212 KB Output is correct
79 Correct 0 ms 212 KB Output is correct
80 Correct 4 ms 724 KB Output is correct
81 Correct 85 ms 12160 KB Output is correct
82 Correct 0 ms 212 KB Output is correct
83 Correct 0 ms 212 KB Output is correct
84 Correct 1 ms 212 KB Output is correct
85 Correct 51 ms 5748 KB Output is correct
86 Correct 72 ms 12108 KB Output is correct
87 Correct 71 ms 12108 KB Output is correct
88 Correct 68 ms 12160 KB Output is correct
89 Correct 68 ms 12160 KB Output is correct
90 Correct 1 ms 212 KB Output is correct
91 Correct 0 ms 212 KB Output is correct
92 Correct 3 ms 724 KB Output is correct
93 Correct 69 ms 12032 KB Output is correct
94 Correct 0 ms 212 KB Output is correct
95 Correct 1 ms 212 KB Output is correct
96 Correct 0 ms 212 KB Output is correct
97 Correct 17 ms 3148 KB Output is correct
98 Correct 66 ms 12048 KB Output is correct
99 Correct 69 ms 12048 KB Output is correct
100 Correct 68 ms 12108 KB Output is correct
101 Correct 65 ms 12032 KB Output is correct
102 Correct 67 ms 12040 KB Output is correct
103 Correct 71 ms 12048 KB Output is correct
104 Correct 65 ms 12028 KB Output is correct
105 Correct 74 ms 12036 KB Output is correct