답안 #362606

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
362606 2021-02-03T17:42:13 Z mosiashvililuka 슈퍼트리 잇기 (IOI20_supertrees) C++14
100 / 100
306 ms 30332 KB
#include "supertrees.h"
#include<bits/stdc++.h>
using namespace std;
int a,c,d,e,i,j,ii,jj,zx,xc,msh1[1009],zm1[1009],msh2[1009],zm2[1009];
int bo[1009],k[1009][1009],cnt;
int B[1009][1009];
vector <int> v[1009],vv[1009];
vector <vector <int> > ans;
int fnd1(int q){
	if(msh1[q]==q) return q; else return msh1[q]=fnd1(msh1[q]);
}
void mrg1(int q, int w){
	q=fnd1(q);w=fnd1(w);
	if(q==w) return;
	if(zm1[q]<zm1[w]) swap(q,w);
	msh1[w]=q;
	if(zm1[q]==zm1[w]) zm1[q]++;
}

int fnd2(int q){
	if(msh2[q]==q) return q; else return msh2[q]=fnd2(msh2[q]);
}
void mrg2(int q, int w){
	q=fnd2(q);w=fnd2(w);
	if(q==w) return;
	if(zm2[q]<zm2[w]) swap(q,w);
	msh2[w]=q;
	if(zm2[q]==zm2[w]) zm2[q]++;
}
void dfs(int q){
	bo[q]=cnt;
	k[i][q]++;
	for(vector <int>::iterator it=v[q].begin(); it!=v[q].end(); it++){
		if(bo[(*it)]==cnt) continue;
		dfs((*it));
	}
	bo[q]=0;
}
int construct(vector <vector <int> > A) {
	a = A.size();
	for(i=0; i<a; i++){
		for(j=0; j<a; j++){
			if(A[i][j]==3){
				return 0;
			}
		}
	}
	for(i=0; i<a; i++){
		msh1[i]=i;zm1[i]=1;
	}
	for(i=0; i<a; i++){
		for(j=i+1; j<a; j++){
			if(A[i][j]==1){
				mrg1(i,j);
			}
		}
	}
	for(i=0; i<a; i++){
		fnd1(i);
		if(i!=msh1[i]){
			B[i][msh1[i]]=1;
			B[msh1[i]][i]=1;
			v[i].push_back(msh1[i]);
			v[msh1[i]].push_back(i);
		}
	}
	for(i=0; i<a; i++){
		msh2[i]=i;zm2[i]=1;
	}
	for(i=0; i<a; i++){
		for(j=i+1; j<a; j++){
			if(A[i][j]==2){
				mrg2(msh1[i],msh1[j]);
			}
		}
	}
	for(i=0; i<a; i++){
		fnd2(i);
		vv[msh2[i]].push_back(i);
	}
	for(i=0; i<a; i++){
		if(vv[i].size()==2){
			return 0;
		}
		if(vv[i].size()>2){
			for(j=0; j<vv[i].size(); j++){
				jj=j-1;if(jj<0) jj=vv[i].size()-1;
				B[vv[i][j]][vv[i][jj]]=1;
				B[vv[i][jj]][vv[i][j]]=1;
				v[vv[i][j]].push_back(vv[i][jj]);
				v[vv[i][jj]].push_back(vv[i][j]);
			}
		}
	}
	for(i=0; i<a; i++){
		cnt++;
		dfs(i);
		for(j=0; j<a; j++){
			if(k[i][j]!=A[i][j]){
				return 0;
			}
		}
	}
	for(i=0; i<a; i++){
		vector <int> va;
		for(j=0; j<a; j++){
			va.push_back(B[i][j]);
		}
		ans.push_back(va);
	}
	build(ans);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:86:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |    for(j=0; j<vv[i].size(); j++){
      |             ~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 12 ms 2924 KB Output is correct
7 Correct 268 ms 30188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 12 ms 2924 KB Output is correct
7 Correct 268 ms 30188 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 12 ms 2156 KB Output is correct
13 Correct 286 ms 26220 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 6 ms 1516 KB Output is correct
17 Correct 115 ms 12268 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 72 ms 9744 KB Output is correct
21 Correct 260 ms 30188 KB Output is correct
22 Correct 271 ms 29624 KB Output is correct
23 Correct 277 ms 30188 KB Output is correct
24 Correct 257 ms 26476 KB Output is correct
25 Correct 108 ms 12396 KB Output is correct
26 Correct 108 ms 12012 KB Output is correct
27 Correct 271 ms 30188 KB Output is correct
28 Correct 256 ms 26348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 12 ms 2156 KB Output is correct
9 Correct 276 ms 26348 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 17 ms 2924 KB Output is correct
13 Correct 284 ms 30188 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 6 ms 1516 KB Output is correct
17 Correct 115 ms 12268 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 69 ms 9708 KB Output is correct
22 Correct 270 ms 30332 KB Output is correct
23 Correct 264 ms 30060 KB Output is correct
24 Correct 279 ms 30188 KB Output is correct
25 Correct 104 ms 8600 KB Output is correct
26 Correct 108 ms 12312 KB Output is correct
27 Correct 271 ms 30060 KB Output is correct
28 Correct 306 ms 30104 KB Output is correct
29 Correct 117 ms 8556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 68 ms 9668 KB Output is correct
5 Correct 267 ms 30112 KB Output is correct
6 Correct 264 ms 29720 KB Output is correct
7 Correct 275 ms 30188 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 68 ms 9708 KB Output is correct
10 Correct 266 ms 30188 KB Output is correct
11 Correct 267 ms 30060 KB Output is correct
12 Correct 286 ms 30316 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 67 ms 9708 KB Output is correct
17 Correct 270 ms 30188 KB Output is correct
18 Correct 266 ms 30008 KB Output is correct
19 Correct 263 ms 29804 KB Output is correct
20 Correct 257 ms 26344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 12 ms 2924 KB Output is correct
7 Correct 268 ms 30188 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 12 ms 2156 KB Output is correct
13 Correct 286 ms 26220 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 6 ms 1516 KB Output is correct
17 Correct 115 ms 12268 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 72 ms 9744 KB Output is correct
21 Correct 260 ms 30188 KB Output is correct
22 Correct 271 ms 29624 KB Output is correct
23 Correct 277 ms 30188 KB Output is correct
24 Correct 257 ms 26476 KB Output is correct
25 Correct 108 ms 12396 KB Output is correct
26 Correct 108 ms 12012 KB Output is correct
27 Correct 271 ms 30188 KB Output is correct
28 Correct 256 ms 26348 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 492 KB Output is correct
36 Correct 12 ms 2156 KB Output is correct
37 Correct 276 ms 26348 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 1 ms 492 KB Output is correct
40 Correct 17 ms 2924 KB Output is correct
41 Correct 284 ms 30188 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 6 ms 1516 KB Output is correct
45 Correct 115 ms 12268 KB Output is correct
46 Correct 1 ms 364 KB Output is correct
47 Correct 1 ms 364 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 69 ms 9708 KB Output is correct
50 Correct 270 ms 30332 KB Output is correct
51 Correct 264 ms 30060 KB Output is correct
52 Correct 279 ms 30188 KB Output is correct
53 Correct 104 ms 8600 KB Output is correct
54 Correct 108 ms 12312 KB Output is correct
55 Correct 271 ms 30060 KB Output is correct
56 Correct 306 ms 30104 KB Output is correct
57 Correct 117 ms 8556 KB Output is correct
58 Correct 1 ms 364 KB Output is correct
59 Correct 1 ms 492 KB Output is correct
60 Correct 6 ms 1516 KB Output is correct
61 Correct 119 ms 12268 KB Output is correct
62 Correct 1 ms 492 KB Output is correct
63 Correct 1 ms 492 KB Output is correct
64 Correct 1 ms 492 KB Output is correct
65 Correct 67 ms 9708 KB Output is correct
66 Correct 108 ms 12268 KB Output is correct
67 Correct 110 ms 12012 KB Output is correct
68 Correct 110 ms 11884 KB Output is correct
69 Correct 103 ms 8556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 12 ms 2924 KB Output is correct
7 Correct 268 ms 30188 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 12 ms 2156 KB Output is correct
13 Correct 286 ms 26220 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 6 ms 1516 KB Output is correct
17 Correct 115 ms 12268 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 72 ms 9744 KB Output is correct
21 Correct 260 ms 30188 KB Output is correct
22 Correct 271 ms 29624 KB Output is correct
23 Correct 277 ms 30188 KB Output is correct
24 Correct 257 ms 26476 KB Output is correct
25 Correct 108 ms 12396 KB Output is correct
26 Correct 108 ms 12012 KB Output is correct
27 Correct 271 ms 30188 KB Output is correct
28 Correct 256 ms 26348 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 492 KB Output is correct
36 Correct 12 ms 2156 KB Output is correct
37 Correct 276 ms 26348 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 1 ms 492 KB Output is correct
40 Correct 17 ms 2924 KB Output is correct
41 Correct 284 ms 30188 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 6 ms 1516 KB Output is correct
45 Correct 115 ms 12268 KB Output is correct
46 Correct 1 ms 364 KB Output is correct
47 Correct 1 ms 364 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 69 ms 9708 KB Output is correct
50 Correct 270 ms 30332 KB Output is correct
51 Correct 264 ms 30060 KB Output is correct
52 Correct 279 ms 30188 KB Output is correct
53 Correct 104 ms 8600 KB Output is correct
54 Correct 108 ms 12312 KB Output is correct
55 Correct 271 ms 30060 KB Output is correct
56 Correct 306 ms 30104 KB Output is correct
57 Correct 117 ms 8556 KB Output is correct
58 Correct 1 ms 364 KB Output is correct
59 Correct 1 ms 364 KB Output is correct
60 Correct 1 ms 364 KB Output is correct
61 Correct 68 ms 9668 KB Output is correct
62 Correct 267 ms 30112 KB Output is correct
63 Correct 264 ms 29720 KB Output is correct
64 Correct 275 ms 30188 KB Output is correct
65 Correct 1 ms 364 KB Output is correct
66 Correct 68 ms 9708 KB Output is correct
67 Correct 266 ms 30188 KB Output is correct
68 Correct 267 ms 30060 KB Output is correct
69 Correct 286 ms 30316 KB Output is correct
70 Correct 1 ms 364 KB Output is correct
71 Correct 1 ms 492 KB Output is correct
72 Correct 1 ms 492 KB Output is correct
73 Correct 67 ms 9708 KB Output is correct
74 Correct 270 ms 30188 KB Output is correct
75 Correct 266 ms 30008 KB Output is correct
76 Correct 263 ms 29804 KB Output is correct
77 Correct 257 ms 26344 KB Output is correct
78 Correct 1 ms 364 KB Output is correct
79 Correct 1 ms 492 KB Output is correct
80 Correct 6 ms 1516 KB Output is correct
81 Correct 119 ms 12268 KB Output is correct
82 Correct 1 ms 492 KB Output is correct
83 Correct 1 ms 492 KB Output is correct
84 Correct 1 ms 492 KB Output is correct
85 Correct 67 ms 9708 KB Output is correct
86 Correct 108 ms 12268 KB Output is correct
87 Correct 110 ms 12012 KB Output is correct
88 Correct 110 ms 11884 KB Output is correct
89 Correct 103 ms 8556 KB Output is correct
90 Correct 1 ms 364 KB Output is correct
91 Correct 1 ms 364 KB Output is correct
92 Correct 5 ms 748 KB Output is correct
93 Correct 104 ms 8300 KB Output is correct
94 Correct 1 ms 364 KB Output is correct
95 Correct 1 ms 364 KB Output is correct
96 Correct 1 ms 364 KB Output is correct
97 Correct 36 ms 2412 KB Output is correct
98 Correct 106 ms 8300 KB Output is correct
99 Correct 103 ms 8300 KB Output is correct
100 Correct 107 ms 8300 KB Output is correct
101 Correct 100 ms 8300 KB Output is correct
102 Correct 101 ms 8300 KB Output is correct
103 Correct 119 ms 8300 KB Output is correct
104 Correct 105 ms 8300 KB Output is correct
105 Correct 106 ms 8300 KB Output is correct