답안 #300357

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
300357 2020-09-17T05:49:39 Z oolimry 슈퍼트리 잇기 (IOI20_supertrees) C++14
100 / 100
272 ms 26232 KB
#include "supertrees.h"
#include <bits/stdc++.h>
#define all(x) (x).begin() (x).end()
#define sz(x) (int) (x).size()
using namespace std;
typedef vector<vector<int>> vvi;

int n;
vector<vector<int>> die = {{-1}};

struct ufds{
	int p[1005];
	int n;
	void init(int N ){
		n = N;
		for(int i = 0;i <= n;i++) p[i] = i;
	}
	
	int findSet(int u){
		if(u == p[u]) return u;
		else{
			p[u] = findSet(p[u]);
			return p[u];
		}
	}
	
	void unionSet(int u, int v){
		u = findSet(u);
		v = findSet(v);
		
		if(u == v) return;
		if(u&v) swap(u,v);
		p[u] = v;
	}
	
	bool isSameSet(int u, int v){
		return findSet(u) == findSet(v);
	}
};
vector<vector<int>> adj;

vector<vector<int>> decomp1(){
	int good = 1, bad = 0;
	
	ufds uf; uf.init(n);
	
	for(int i = 0;i < n;i++) for(int j = 0;j < n;j++){
		if(adj[i][j] >= good) uf.unionSet(i, j);
	}
	
	for(int i = 0;i < n;i++) for(int j = 0;j < n;j++){
		if(adj[i][j] >= good){
			if(!uf.isSameSet(i,j)) return die;
		}
		else if(adj[i][j] <= bad){
			if(uf.isSameSet(i,j)) return die;
		}
	}
	
	map<int,vector<int> > M;
	for(int i = 0;i < n;i++){
		int u = uf.findSet(i);
		M[u].push_back(i);
	}
	
	vvi res;
	for(auto x : M){
		res.push_back({});
		for(int y : x.second) res.back().push_back(y);
	}
	
	return res;
}
ufds uf2;

vvi decomp2(vector<int> A){
	int good = 1, bad = 2;
	
	for(int i : A) for(int j : A){
		if(adj[i][j] == 1) uf2.unionSet(i, j);
	}
	
	for(int i : A) for(int j : A){
		if(adj[i][j] == 1){
			if(!uf2.isSameSet(i,j)) return die;
		}
		else if(adj[i][j] == 2){
			if(uf2.isSameSet(i,j)) return die;
		}
	}
	
	map<int,vector<int> > M;
	for(int i : A){
		int u = uf2.findSet(i);
		M[u].push_back(i);
	}
	
	vvi res;
	for(auto x : M){
		res.push_back({});
		for(int y : x.second) res.back().push_back(y);
	}
	
	return res;
}

int construct(vector<vector<int>> ADJ) {
	adj = ADJ;
	
	n = adj.size();
	vector<vector<int> > answer;
	for (int i = 0; i < n; i++) {
		std::vector<int> row;
		row.resize(n);
		answer.push_back(row);
	}
	
	for(auto x : ADJ) for(int y : x){
		if(y == 3) return 0;
	}
	
	vvi res = decomp1();
	
	if(res == die) return 0;
	
	uf2.init(n);
	
	for(vector<int> x : res){
		vvi res2 = decomp2(x);
		
		if(sz(res2) == 2) return 0;
		
		for(auto line : res2){
			for(int i = 1;i < sz(line);i++){
				int a = line[i-1], b = line[i];
				answer[a][b] = 1;
				answer[b][a] = 1;
			}
		}
		
		if(sz(res2) > 2){
			for(int i = 0;i < sz(res2);i++){
				int j = i+1; if(j == sz(res2)) j = 0;
				
				int a = res2[i].back(), b = res2[j].back();
				answer[a][b] = 1;
				answer[b][a] = 1;
			}
		}
		//cout << "F\n\n";
	}
	
	for(int i = 0;i < n;i++) answer[i][i] = 0;
	
	build(answer);
	return 1;
}

Compilation message

supertrees.cpp: In function 'vvi decomp2(std::vector<int>)':
supertrees.cpp:77:6: warning: unused variable 'good' [-Wunused-variable]
   77 |  int good = 1, bad = 2;
      |      ^~~~
supertrees.cpp:77:16: warning: unused variable 'bad' [-Wunused-variable]
   77 |  int good = 1, bad = 2;
      |                ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 11 ms 1408 KB Output is correct
7 Correct 268 ms 26104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 11 ms 1408 KB Output is correct
7 Correct 268 ms 26104 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 10 ms 1332 KB Output is correct
13 Correct 255 ms 26092 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 360 KB Output is correct
16 Correct 8 ms 1000 KB Output is correct
17 Correct 130 ms 16092 KB Output is correct
18 Correct 1 ms 288 KB Output is correct
19 Correct 1 ms 288 KB Output is correct
20 Correct 61 ms 6888 KB Output is correct
21 Correct 256 ms 26036 KB Output is correct
22 Correct 253 ms 26124 KB Output is correct
23 Correct 270 ms 26028 KB Output is correct
24 Correct 261 ms 26080 KB Output is correct
25 Correct 102 ms 16120 KB Output is correct
26 Correct 110 ms 16120 KB Output is correct
27 Correct 265 ms 26104 KB Output is correct
28 Correct 251 ms 26072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 10 ms 1408 KB Output is correct
9 Correct 248 ms 26108 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 11 ms 1408 KB Output is correct
13 Correct 262 ms 26104 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 5 ms 1024 KB Output is correct
17 Correct 116 ms 16120 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 1 ms 256 KB Output is correct
21 Correct 61 ms 6776 KB Output is correct
22 Correct 254 ms 26072 KB Output is correct
23 Correct 251 ms 26156 KB Output is correct
24 Correct 271 ms 26044 KB Output is correct
25 Correct 107 ms 16224 KB Output is correct
26 Correct 115 ms 16092 KB Output is correct
27 Correct 244 ms 26104 KB Output is correct
28 Correct 272 ms 26104 KB Output is correct
29 Correct 106 ms 16376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 63 ms 6776 KB Output is correct
5 Correct 252 ms 26232 KB Output is correct
6 Correct 244 ms 26104 KB Output is correct
7 Correct 264 ms 26104 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 65 ms 6776 KB Output is correct
10 Correct 246 ms 26072 KB Output is correct
11 Correct 261 ms 26104 KB Output is correct
12 Correct 262 ms 26008 KB Output is correct
13 Correct 0 ms 256 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 61 ms 6956 KB Output is correct
17 Correct 260 ms 26076 KB Output is correct
18 Correct 251 ms 26080 KB Output is correct
19 Correct 245 ms 26232 KB Output is correct
20 Correct 243 ms 26232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 11 ms 1408 KB Output is correct
7 Correct 268 ms 26104 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 10 ms 1332 KB Output is correct
13 Correct 255 ms 26092 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 360 KB Output is correct
16 Correct 8 ms 1000 KB Output is correct
17 Correct 130 ms 16092 KB Output is correct
18 Correct 1 ms 288 KB Output is correct
19 Correct 1 ms 288 KB Output is correct
20 Correct 61 ms 6888 KB Output is correct
21 Correct 256 ms 26036 KB Output is correct
22 Correct 253 ms 26124 KB Output is correct
23 Correct 270 ms 26028 KB Output is correct
24 Correct 261 ms 26080 KB Output is correct
25 Correct 102 ms 16120 KB Output is correct
26 Correct 110 ms 16120 KB Output is correct
27 Correct 265 ms 26104 KB Output is correct
28 Correct 251 ms 26072 KB Output is correct
29 Correct 1 ms 256 KB Output is correct
30 Correct 0 ms 256 KB Output is correct
31 Correct 1 ms 256 KB Output is correct
32 Correct 1 ms 256 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 0 ms 256 KB Output is correct
35 Correct 1 ms 512 KB Output is correct
36 Correct 10 ms 1408 KB Output is correct
37 Correct 248 ms 26108 KB Output is correct
38 Correct 1 ms 256 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 11 ms 1408 KB Output is correct
41 Correct 262 ms 26104 KB Output is correct
42 Correct 1 ms 256 KB Output is correct
43 Correct 1 ms 256 KB Output is correct
44 Correct 5 ms 1024 KB Output is correct
45 Correct 116 ms 16120 KB Output is correct
46 Correct 1 ms 256 KB Output is correct
47 Correct 1 ms 256 KB Output is correct
48 Correct 1 ms 256 KB Output is correct
49 Correct 61 ms 6776 KB Output is correct
50 Correct 254 ms 26072 KB Output is correct
51 Correct 251 ms 26156 KB Output is correct
52 Correct 271 ms 26044 KB Output is correct
53 Correct 107 ms 16224 KB Output is correct
54 Correct 115 ms 16092 KB Output is correct
55 Correct 244 ms 26104 KB Output is correct
56 Correct 272 ms 26104 KB Output is correct
57 Correct 106 ms 16376 KB Output is correct
58 Correct 1 ms 256 KB Output is correct
59 Correct 1 ms 256 KB Output is correct
60 Correct 5 ms 928 KB Output is correct
61 Correct 119 ms 16120 KB Output is correct
62 Correct 1 ms 256 KB Output is correct
63 Correct 1 ms 256 KB Output is correct
64 Correct 1 ms 256 KB Output is correct
65 Correct 61 ms 7032 KB Output is correct
66 Correct 101 ms 16120 KB Output is correct
67 Correct 111 ms 16120 KB Output is correct
68 Correct 99 ms 16124 KB Output is correct
69 Correct 108 ms 16504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 11 ms 1408 KB Output is correct
7 Correct 268 ms 26104 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 10 ms 1332 KB Output is correct
13 Correct 255 ms 26092 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 360 KB Output is correct
16 Correct 8 ms 1000 KB Output is correct
17 Correct 130 ms 16092 KB Output is correct
18 Correct 1 ms 288 KB Output is correct
19 Correct 1 ms 288 KB Output is correct
20 Correct 61 ms 6888 KB Output is correct
21 Correct 256 ms 26036 KB Output is correct
22 Correct 253 ms 26124 KB Output is correct
23 Correct 270 ms 26028 KB Output is correct
24 Correct 261 ms 26080 KB Output is correct
25 Correct 102 ms 16120 KB Output is correct
26 Correct 110 ms 16120 KB Output is correct
27 Correct 265 ms 26104 KB Output is correct
28 Correct 251 ms 26072 KB Output is correct
29 Correct 1 ms 256 KB Output is correct
30 Correct 0 ms 256 KB Output is correct
31 Correct 1 ms 256 KB Output is correct
32 Correct 1 ms 256 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 0 ms 256 KB Output is correct
35 Correct 1 ms 512 KB Output is correct
36 Correct 10 ms 1408 KB Output is correct
37 Correct 248 ms 26108 KB Output is correct
38 Correct 1 ms 256 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 11 ms 1408 KB Output is correct
41 Correct 262 ms 26104 KB Output is correct
42 Correct 1 ms 256 KB Output is correct
43 Correct 1 ms 256 KB Output is correct
44 Correct 5 ms 1024 KB Output is correct
45 Correct 116 ms 16120 KB Output is correct
46 Correct 1 ms 256 KB Output is correct
47 Correct 1 ms 256 KB Output is correct
48 Correct 1 ms 256 KB Output is correct
49 Correct 61 ms 6776 KB Output is correct
50 Correct 254 ms 26072 KB Output is correct
51 Correct 251 ms 26156 KB Output is correct
52 Correct 271 ms 26044 KB Output is correct
53 Correct 107 ms 16224 KB Output is correct
54 Correct 115 ms 16092 KB Output is correct
55 Correct 244 ms 26104 KB Output is correct
56 Correct 272 ms 26104 KB Output is correct
57 Correct 106 ms 16376 KB Output is correct
58 Correct 1 ms 256 KB Output is correct
59 Correct 0 ms 256 KB Output is correct
60 Correct 1 ms 256 KB Output is correct
61 Correct 63 ms 6776 KB Output is correct
62 Correct 252 ms 26232 KB Output is correct
63 Correct 244 ms 26104 KB Output is correct
64 Correct 264 ms 26104 KB Output is correct
65 Correct 1 ms 256 KB Output is correct
66 Correct 65 ms 6776 KB Output is correct
67 Correct 246 ms 26072 KB Output is correct
68 Correct 261 ms 26104 KB Output is correct
69 Correct 262 ms 26008 KB Output is correct
70 Correct 0 ms 256 KB Output is correct
71 Correct 1 ms 256 KB Output is correct
72 Correct 1 ms 256 KB Output is correct
73 Correct 61 ms 6956 KB Output is correct
74 Correct 260 ms 26076 KB Output is correct
75 Correct 251 ms 26080 KB Output is correct
76 Correct 245 ms 26232 KB Output is correct
77 Correct 243 ms 26232 KB Output is correct
78 Correct 1 ms 256 KB Output is correct
79 Correct 1 ms 256 KB Output is correct
80 Correct 5 ms 928 KB Output is correct
81 Correct 119 ms 16120 KB Output is correct
82 Correct 1 ms 256 KB Output is correct
83 Correct 1 ms 256 KB Output is correct
84 Correct 1 ms 256 KB Output is correct
85 Correct 61 ms 7032 KB Output is correct
86 Correct 101 ms 16120 KB Output is correct
87 Correct 111 ms 16120 KB Output is correct
88 Correct 99 ms 16124 KB Output is correct
89 Correct 108 ms 16504 KB Output is correct
90 Correct 1 ms 256 KB Output is correct
91 Correct 1 ms 256 KB Output is correct
92 Correct 5 ms 1024 KB Output is correct
93 Correct 114 ms 16120 KB Output is correct
94 Correct 1 ms 256 KB Output is correct
95 Correct 1 ms 384 KB Output is correct
96 Correct 0 ms 256 KB Output is correct
97 Correct 25 ms 4344 KB Output is correct
98 Correct 98 ms 16120 KB Output is correct
99 Correct 100 ms 16120 KB Output is correct
100 Correct 96 ms 16120 KB Output is correct
101 Correct 97 ms 16120 KB Output is correct
102 Correct 113 ms 16220 KB Output is correct
103 Correct 108 ms 16120 KB Output is correct
104 Correct 105 ms 16124 KB Output is correct
105 Correct 108 ms 16120 KB Output is correct