답안 #316363

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
316363 2020-10-26T06:55:59 Z tigicha 슈퍼트리 잇기 (IOI20_supertrees) C++14
100 / 100
291 ms 34168 KB
#include "supertrees.h"
#include<bits/stdc++.h>
using namespace std;
int par[1005], ar[1005], a[1005][1005], ans[1005][1005], fix1[1005], n, fix[1005];
vector<int> V[1005], vec[1005], v1;
vector<vector<int> > answer;
int parent(int x){
	if(par[x]==x) return x;
	return par[x]=parent(par[x]);
}
void dsu(int x, int y){
	x=parent(x);
	y=parent(y);
	if(x==y) return;
	if(ar[x]<ar[y]) swap(x, y);
	par[y]=x;
	ar[x]+=ar[y];
}
void rec(int x){
	for(int i=0; i<V[x].size(); i++)
	for(int j=i+1; j<V[x].size(); j++)
	if(a[V[x][i]][V[x][j]]==1){
	vec[V[x][i]].push_back(V[x][j]);
	vec[V[x][j]].push_back(V[x][i]);
	}
	v1.clear();
	for(int i=0; i<V[x].size(); i++){
		int y=V[x][i]; 
		if(fix[y]) continue;
		v1.push_back(y);
		fix1[y]=1;
		if(!fix[y])
		for(int j=0; j<vec[y].size(); j++){
			fix[vec[y][j]]=y;
			ans[y][vec[y][j]]=ans[vec[y][j]][y]=1;
		}
	}
	if(v1.size()>1)
	for(int i=0; i<v1.size(); i++)
	ans[v1[i]][v1[(i+1)%v1.size()]]=ans[v1[(i+1)%v1.size()]][v1[i]]=1;
}
bool check(){
	for(int i=1; i<=n; i++){
		std::vector<int> vec1;
		for(int j=1; j<=n; j++){
			if(i==j) ans[i][j]=0;
			else{
				int x=parent(i);
				int y=parent(j);
				if(a[i][j]==0 && parent(i)==parent(j)) return 0;
				if(!fix1[i] && !fix1[j] && a[i][j]==2 && fix[i]==fix[j]) return 0;
			}
			vec1.push_back(ans[i][j]); 
		}
		answer.push_back(vec1);
	}
	return 1;
}
int construct(std::vector<std::vector<int> > v){
	n=v.size(); 
	for(int i=1; i<=n; i++){
		par[i]=i;
		ar[i]=1;
	}
	for(int i=1; i<=n; i++)
	for(int j=1; j<=n; j++){
		a[i][j]=v[i-1][j-1];
		if(a[i][j]==3)  return 0;	
		if(a[i][j]!=0) dsu(i, j);
	}
	for(int i=1; i<=n; i++)
	V[parent(i)].push_back(i);
	for(int i=1; i<=n; i++){
		rec(i);
		if(v1.size()==2 && a[v1[0]][v1[1]]==2) return 0;
	}
	if(!check()) return 0;
	build(answer);
	return 1;
}

Compilation message

supertrees.cpp: In function 'void rec(int)':
supertrees.cpp:20:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |  for(int i=0; i<V[x].size(); i++)
      |               ~^~~~~~~~~~~~
supertrees.cpp:21:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |  for(int j=i+1; j<V[x].size(); j++)
      |                 ~^~~~~~~~~~~~
supertrees.cpp:27:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |  for(int i=0; i<V[x].size(); i++){
      |               ~^~~~~~~~~~~~
supertrees.cpp:33:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |   for(int j=0; j<vec[y].size(); j++){
      |                ~^~~~~~~~~~~~~~
supertrees.cpp:39:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |  for(int i=0; i<v1.size(); i++)
      |               ~^~~~~~~~~~
supertrees.cpp: In function 'bool check()':
supertrees.cpp:48:9: warning: unused variable 'x' [-Wunused-variable]
   48 |     int x=parent(i);
      |         ^
supertrees.cpp:49:9: warning: unused variable 'y' [-Wunused-variable]
   49 |     int y=parent(j);
      |         ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 12 ms 3072 KB Output is correct
7 Correct 264 ms 34168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 12 ms 3072 KB Output is correct
7 Correct 264 ms 34168 KB Output is correct
8 Correct 1 ms 416 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 11 ms 2816 KB Output is correct
13 Correct 242 ms 30088 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 6 ms 2432 KB Output is correct
17 Correct 125 ms 18936 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 65 ms 9848 KB Output is correct
21 Correct 259 ms 30584 KB Output is correct
22 Correct 249 ms 30088 KB Output is correct
23 Correct 276 ms 32120 KB Output is correct
24 Correct 245 ms 30200 KB Output is correct
25 Correct 103 ms 16760 KB Output is correct
26 Correct 101 ms 15864 KB Output is correct
27 Correct 278 ms 33272 KB Output is correct
28 Correct 247 ms 30096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 11 ms 2816 KB Output is correct
9 Correct 243 ms 30200 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 512 KB Output is correct
12 Correct 13 ms 2816 KB Output is correct
13 Correct 267 ms 30092 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 512 KB Output is correct
16 Correct 6 ms 2304 KB Output is correct
17 Correct 116 ms 16136 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 67 ms 9848 KB Output is correct
22 Correct 255 ms 30072 KB Output is correct
23 Correct 252 ms 30072 KB Output is correct
24 Correct 271 ms 30072 KB Output is correct
25 Correct 100 ms 12536 KB Output is correct
26 Correct 107 ms 16120 KB Output is correct
27 Correct 248 ms 30072 KB Output is correct
28 Correct 269 ms 30072 KB Output is correct
29 Correct 96 ms 12408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 65 ms 9848 KB Output is correct
5 Correct 256 ms 30584 KB Output is correct
6 Correct 260 ms 30072 KB Output is correct
7 Correct 277 ms 32248 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 65 ms 9848 KB Output is correct
10 Correct 257 ms 30072 KB Output is correct
11 Correct 254 ms 30072 KB Output is correct
12 Correct 271 ms 30072 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 65 ms 9864 KB Output is correct
17 Correct 291 ms 30072 KB Output is correct
18 Correct 264 ms 30072 KB Output is correct
19 Correct 259 ms 30072 KB Output is correct
20 Correct 245 ms 30200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 12 ms 3072 KB Output is correct
7 Correct 264 ms 34168 KB Output is correct
8 Correct 1 ms 416 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 11 ms 2816 KB Output is correct
13 Correct 242 ms 30088 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 6 ms 2432 KB Output is correct
17 Correct 125 ms 18936 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 65 ms 9848 KB Output is correct
21 Correct 259 ms 30584 KB Output is correct
22 Correct 249 ms 30088 KB Output is correct
23 Correct 276 ms 32120 KB Output is correct
24 Correct 245 ms 30200 KB Output is correct
25 Correct 103 ms 16760 KB Output is correct
26 Correct 101 ms 15864 KB Output is correct
27 Correct 278 ms 33272 KB Output is correct
28 Correct 247 ms 30096 KB Output is correct
29 Correct 0 ms 384 KB Output is correct
30 Correct 0 ms 384 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Correct 0 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 512 KB Output is correct
36 Correct 11 ms 2816 KB Output is correct
37 Correct 243 ms 30200 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 0 ms 512 KB Output is correct
40 Correct 13 ms 2816 KB Output is correct
41 Correct 267 ms 30092 KB Output is correct
42 Correct 0 ms 384 KB Output is correct
43 Correct 0 ms 512 KB Output is correct
44 Correct 6 ms 2304 KB Output is correct
45 Correct 116 ms 16136 KB Output is correct
46 Correct 0 ms 384 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 67 ms 9848 KB Output is correct
50 Correct 255 ms 30072 KB Output is correct
51 Correct 252 ms 30072 KB Output is correct
52 Correct 271 ms 30072 KB Output is correct
53 Correct 100 ms 12536 KB Output is correct
54 Correct 107 ms 16120 KB Output is correct
55 Correct 248 ms 30072 KB Output is correct
56 Correct 269 ms 30072 KB Output is correct
57 Correct 96 ms 12408 KB Output is correct
58 Correct 1 ms 384 KB Output is correct
59 Correct 1 ms 512 KB Output is correct
60 Correct 6 ms 2432 KB Output is correct
61 Correct 122 ms 18424 KB Output is correct
62 Correct 1 ms 416 KB Output is correct
63 Correct 0 ms 512 KB Output is correct
64 Correct 0 ms 512 KB Output is correct
65 Correct 67 ms 9848 KB Output is correct
66 Correct 106 ms 16120 KB Output is correct
67 Correct 103 ms 15864 KB Output is correct
68 Correct 104 ms 15864 KB Output is correct
69 Correct 98 ms 12300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 12 ms 3072 KB Output is correct
7 Correct 264 ms 34168 KB Output is correct
8 Correct 1 ms 416 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 11 ms 2816 KB Output is correct
13 Correct 242 ms 30088 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 6 ms 2432 KB Output is correct
17 Correct 125 ms 18936 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 65 ms 9848 KB Output is correct
21 Correct 259 ms 30584 KB Output is correct
22 Correct 249 ms 30088 KB Output is correct
23 Correct 276 ms 32120 KB Output is correct
24 Correct 245 ms 30200 KB Output is correct
25 Correct 103 ms 16760 KB Output is correct
26 Correct 101 ms 15864 KB Output is correct
27 Correct 278 ms 33272 KB Output is correct
28 Correct 247 ms 30096 KB Output is correct
29 Correct 0 ms 384 KB Output is correct
30 Correct 0 ms 384 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Correct 0 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 512 KB Output is correct
36 Correct 11 ms 2816 KB Output is correct
37 Correct 243 ms 30200 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 0 ms 512 KB Output is correct
40 Correct 13 ms 2816 KB Output is correct
41 Correct 267 ms 30092 KB Output is correct
42 Correct 0 ms 384 KB Output is correct
43 Correct 0 ms 512 KB Output is correct
44 Correct 6 ms 2304 KB Output is correct
45 Correct 116 ms 16136 KB Output is correct
46 Correct 0 ms 384 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 67 ms 9848 KB Output is correct
50 Correct 255 ms 30072 KB Output is correct
51 Correct 252 ms 30072 KB Output is correct
52 Correct 271 ms 30072 KB Output is correct
53 Correct 100 ms 12536 KB Output is correct
54 Correct 107 ms 16120 KB Output is correct
55 Correct 248 ms 30072 KB Output is correct
56 Correct 269 ms 30072 KB Output is correct
57 Correct 96 ms 12408 KB Output is correct
58 Correct 1 ms 384 KB Output is correct
59 Correct 0 ms 384 KB Output is correct
60 Correct 0 ms 384 KB Output is correct
61 Correct 65 ms 9848 KB Output is correct
62 Correct 256 ms 30584 KB Output is correct
63 Correct 260 ms 30072 KB Output is correct
64 Correct 277 ms 32248 KB Output is correct
65 Correct 0 ms 384 KB Output is correct
66 Correct 65 ms 9848 KB Output is correct
67 Correct 257 ms 30072 KB Output is correct
68 Correct 254 ms 30072 KB Output is correct
69 Correct 271 ms 30072 KB Output is correct
70 Correct 1 ms 384 KB Output is correct
71 Correct 1 ms 512 KB Output is correct
72 Correct 1 ms 512 KB Output is correct
73 Correct 65 ms 9864 KB Output is correct
74 Correct 291 ms 30072 KB Output is correct
75 Correct 264 ms 30072 KB Output is correct
76 Correct 259 ms 30072 KB Output is correct
77 Correct 245 ms 30200 KB Output is correct
78 Correct 1 ms 384 KB Output is correct
79 Correct 1 ms 512 KB Output is correct
80 Correct 6 ms 2432 KB Output is correct
81 Correct 122 ms 18424 KB Output is correct
82 Correct 1 ms 416 KB Output is correct
83 Correct 0 ms 512 KB Output is correct
84 Correct 0 ms 512 KB Output is correct
85 Correct 67 ms 9848 KB Output is correct
86 Correct 106 ms 16120 KB Output is correct
87 Correct 103 ms 15864 KB Output is correct
88 Correct 104 ms 15864 KB Output is correct
89 Correct 98 ms 12300 KB Output is correct
90 Correct 1 ms 384 KB Output is correct
91 Correct 0 ms 384 KB Output is correct
92 Correct 5 ms 640 KB Output is correct
93 Correct 104 ms 8440 KB Output is correct
94 Correct 0 ms 384 KB Output is correct
95 Correct 0 ms 384 KB Output is correct
96 Correct 0 ms 384 KB Output is correct
97 Correct 25 ms 2688 KB Output is correct
98 Correct 95 ms 8568 KB Output is correct
99 Correct 99 ms 8824 KB Output is correct
100 Correct 94 ms 8568 KB Output is correct
101 Correct 97 ms 9592 KB Output is correct
102 Correct 95 ms 8324 KB Output is correct
103 Correct 95 ms 8312 KB Output is correct
104 Correct 95 ms 8312 KB Output is correct
105 Correct 99 ms 8312 KB Output is correct