답안 #300280

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
300280 2020-09-17T03:58:22 Z easrui 슈퍼트리 잇기 (IOI20_supertrees) C++14
100 / 100
273 ms 22392 KB
#include "supertrees.h"

#include <bits/stdc++.h>
#define va first
#define vb second
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;

const int MN = 1e3+5;
const int MOD = 1e9+7;
const int INF = 1e9;

int par[MN];
vector<int> G[MN],L[MN],C;

int fnd(int u)
{
	return u==par[u] ? u : par[u]=fnd(par[u]);
}

void join(int u, int v)
{
	u = fnd(u), v = fnd(v);
	par[u] = v;
}

int construct(vector<vector<int>> p) {
    int n = p.size();
	for(int i=0; i<n; i++) par[i] = i;

	vector<vector<int>> ans;
	vector<int> v(n);
	for(int i=0; i<n; i++) ans.push_back(v);

	for(int i=0; i<n; i++)
		for(int j=0; j<n; j++){
			if(p[i][j]) join(i,j);
			if(p[i][j]==3) return 0;
		}

	for(int i=0; i<n; i++)
		for(int j=0; j<n; j++)
			if(fnd(i)==fnd(j)&&!p[i][j]) return 0;

	for(int i=0; i<n; i++) G[par[i]].push_back(i);

	for(int i=0; i<n; i++) par[i] = i;

	for(int t=0; t<n; t++){
		//FOR G[i]
		for(int i=0; i<n; i++) L[i].clear();
		C.clear();

		int nn = G[t].size();
		for(int i:G[t])
			for(int j:G[t])
				if(p[i][j]==1) join(i,j);

		for(int i:G[t])
			for(int j:G[t])
				if(fnd(i)==fnd(j)&&p[i][j]==2) return 0;

		for(int i:G[t]) if(par[i]==i){
			L[i].push_back(i);
			C.push_back(i);
		}
		for(int i:G[t]) if(par[i]!=i) L[par[i]].push_back(i);

		for(int i:G[t]){
			if(par[i]!=i) continue;
			for(int j=0; j<L[i].size()-1; j++){
				ans[L[i][j]][L[i][j+1]] = 1;
				ans[L[i][j+1]][L[i][j]] = 1;
			}
		}
		int c = C.size();
		if(c==2) return 0;

		for(int i=0; i<c; i++){
			ans[C[i]][C[(i+1)%c]] = 1;
			ans[C[(i+1)%c]][C[i]] = 1;
		}
	}
	
	for(int i=0; i<n; i++) ans[i][i] = 0;

	/*for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			cout << ans[i][j] << ' ';
		}
		cout << '\n';
	}*/
	build(ans);
	return 1;
}

/*int main()
{
	#ifdef L0TUS
    freopen("C:\\Users\\SKYPC364\\Documents\\Coding\\BOJ\\input.txt", "r", stdin);
    freopen("C:\\Users\\SKYPC364\\Documents\\Coding\\BOJ\\output.txt", "w", stdout);
	#endif
	int n;
	cin >> n;
	vector<vector<int>> p(n);
	for(int i=0; i<n; i++)
		for(int j=0; j<n; j++){
			int x;
			cin >> x;
			p[i].push_back(x);
		}
	construct(p);
}*/

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:75:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |    for(int j=0; j<L[i].size()-1; j++){
      |                 ~^~~~~~~~~~~~~~
supertrees.cpp:58:7: warning: unused variable 'nn' [-Wunused-variable]
   58 |   int nn = G[t].size();
      |       ^~
# 결과 실행 시간 메모리 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 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 11 ms 1280 KB Output is correct
7 Correct 264 ms 22160 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 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 11 ms 1280 KB Output is correct
7 Correct 264 ms 22160 KB Output is correct
8 Correct 1 ms 416 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 416 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 12 ms 1280 KB Output is correct
13 Correct 250 ms 22136 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 5 ms 896 KB Output is correct
17 Correct 112 ms 12256 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 60 ms 5880 KB Output is correct
21 Correct 242 ms 22136 KB Output is correct
22 Correct 248 ms 22136 KB Output is correct
23 Correct 273 ms 22136 KB Output is correct
24 Correct 239 ms 22136 KB Output is correct
25 Correct 100 ms 12280 KB Output is correct
26 Correct 100 ms 12168 KB Output is correct
27 Correct 269 ms 22168 KB Output is correct
28 Correct 238 ms 22136 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 1 ms 416 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 384 KB Output is correct
8 Correct 10 ms 1280 KB Output is correct
9 Correct 236 ms 22264 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 11 ms 1280 KB Output is correct
13 Correct 250 ms 22264 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 5 ms 896 KB Output is correct
17 Correct 114 ms 12152 KB Output is correct
18 Correct 1 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 60 ms 5880 KB Output is correct
22 Correct 246 ms 22392 KB Output is correct
23 Correct 248 ms 22256 KB Output is correct
24 Correct 271 ms 22264 KB Output is correct
25 Correct 98 ms 12284 KB Output is correct
26 Correct 98 ms 12152 KB Output is correct
27 Correct 240 ms 22136 KB Output is correct
28 Correct 256 ms 22136 KB Output is correct
29 Correct 97 ms 12280 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 62 ms 5880 KB Output is correct
5 Correct 250 ms 22136 KB Output is correct
6 Correct 245 ms 22136 KB Output is correct
7 Correct 267 ms 22156 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 66 ms 6136 KB Output is correct
10 Correct 248 ms 22136 KB Output is correct
11 Correct 245 ms 22136 KB Output is correct
12 Correct 259 ms 22136 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 384 KB Output is correct
16 Correct 60 ms 5880 KB Output is correct
17 Correct 249 ms 22136 KB Output is correct
18 Correct 242 ms 22264 KB Output is correct
19 Correct 238 ms 22136 KB Output is correct
20 Correct 247 ms 22264 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 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 11 ms 1280 KB Output is correct
7 Correct 264 ms 22160 KB Output is correct
8 Correct 1 ms 416 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 416 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 12 ms 1280 KB Output is correct
13 Correct 250 ms 22136 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 5 ms 896 KB Output is correct
17 Correct 112 ms 12256 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 60 ms 5880 KB Output is correct
21 Correct 242 ms 22136 KB Output is correct
22 Correct 248 ms 22136 KB Output is correct
23 Correct 273 ms 22136 KB Output is correct
24 Correct 239 ms 22136 KB Output is correct
25 Correct 100 ms 12280 KB Output is correct
26 Correct 100 ms 12168 KB Output is correct
27 Correct 269 ms 22168 KB Output is correct
28 Correct 238 ms 22136 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 416 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 384 KB Output is correct
36 Correct 10 ms 1280 KB Output is correct
37 Correct 236 ms 22264 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 11 ms 1280 KB Output is correct
41 Correct 250 ms 22264 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 5 ms 896 KB Output is correct
45 Correct 114 ms 12152 KB Output is correct
46 Correct 1 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 60 ms 5880 KB Output is correct
50 Correct 246 ms 22392 KB Output is correct
51 Correct 248 ms 22256 KB Output is correct
52 Correct 271 ms 22264 KB Output is correct
53 Correct 98 ms 12284 KB Output is correct
54 Correct 98 ms 12152 KB Output is correct
55 Correct 240 ms 22136 KB Output is correct
56 Correct 256 ms 22136 KB Output is correct
57 Correct 97 ms 12280 KB Output is correct
58 Correct 1 ms 384 KB Output is correct
59 Correct 1 ms 384 KB Output is correct
60 Correct 6 ms 896 KB Output is correct
61 Correct 108 ms 12164 KB Output is correct
62 Correct 1 ms 384 KB Output is correct
63 Correct 1 ms 384 KB Output is correct
64 Correct 1 ms 512 KB Output is correct
65 Correct 60 ms 5884 KB Output is correct
66 Correct 103 ms 12152 KB Output is correct
67 Correct 98 ms 12284 KB Output is correct
68 Correct 95 ms 12152 KB Output is correct
69 Correct 98 ms 12280 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 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 11 ms 1280 KB Output is correct
7 Correct 264 ms 22160 KB Output is correct
8 Correct 1 ms 416 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 416 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 12 ms 1280 KB Output is correct
13 Correct 250 ms 22136 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 5 ms 896 KB Output is correct
17 Correct 112 ms 12256 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 60 ms 5880 KB Output is correct
21 Correct 242 ms 22136 KB Output is correct
22 Correct 248 ms 22136 KB Output is correct
23 Correct 273 ms 22136 KB Output is correct
24 Correct 239 ms 22136 KB Output is correct
25 Correct 100 ms 12280 KB Output is correct
26 Correct 100 ms 12168 KB Output is correct
27 Correct 269 ms 22168 KB Output is correct
28 Correct 238 ms 22136 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 416 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 384 KB Output is correct
36 Correct 10 ms 1280 KB Output is correct
37 Correct 236 ms 22264 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 11 ms 1280 KB Output is correct
41 Correct 250 ms 22264 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 5 ms 896 KB Output is correct
45 Correct 114 ms 12152 KB Output is correct
46 Correct 1 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 60 ms 5880 KB Output is correct
50 Correct 246 ms 22392 KB Output is correct
51 Correct 248 ms 22256 KB Output is correct
52 Correct 271 ms 22264 KB Output is correct
53 Correct 98 ms 12284 KB Output is correct
54 Correct 98 ms 12152 KB Output is correct
55 Correct 240 ms 22136 KB Output is correct
56 Correct 256 ms 22136 KB Output is correct
57 Correct 97 ms 12280 KB Output is correct
58 Correct 1 ms 384 KB Output is correct
59 Correct 1 ms 384 KB Output is correct
60 Correct 1 ms 384 KB Output is correct
61 Correct 62 ms 5880 KB Output is correct
62 Correct 250 ms 22136 KB Output is correct
63 Correct 245 ms 22136 KB Output is correct
64 Correct 267 ms 22156 KB Output is correct
65 Correct 1 ms 384 KB Output is correct
66 Correct 66 ms 6136 KB Output is correct
67 Correct 248 ms 22136 KB Output is correct
68 Correct 245 ms 22136 KB Output is correct
69 Correct 259 ms 22136 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 384 KB Output is correct
73 Correct 60 ms 5880 KB Output is correct
74 Correct 249 ms 22136 KB Output is correct
75 Correct 242 ms 22264 KB Output is correct
76 Correct 238 ms 22136 KB Output is correct
77 Correct 247 ms 22264 KB Output is correct
78 Correct 1 ms 384 KB Output is correct
79 Correct 1 ms 384 KB Output is correct
80 Correct 6 ms 896 KB Output is correct
81 Correct 108 ms 12164 KB Output is correct
82 Correct 1 ms 384 KB Output is correct
83 Correct 1 ms 384 KB Output is correct
84 Correct 1 ms 512 KB Output is correct
85 Correct 60 ms 5884 KB Output is correct
86 Correct 103 ms 12152 KB Output is correct
87 Correct 98 ms 12284 KB Output is correct
88 Correct 95 ms 12152 KB Output is correct
89 Correct 98 ms 12280 KB Output is correct
90 Correct 1 ms 416 KB Output is correct
91 Correct 1 ms 512 KB Output is correct
92 Correct 4 ms 896 KB Output is correct
93 Correct 104 ms 12152 KB Output is correct
94 Correct 1 ms 384 KB Output is correct
95 Correct 1 ms 384 KB Output is correct
96 Correct 1 ms 384 KB Output is correct
97 Correct 24 ms 3328 KB Output is correct
98 Correct 97 ms 12296 KB Output is correct
99 Correct 99 ms 12156 KB Output is correct
100 Correct 93 ms 12152 KB Output is correct
101 Correct 97 ms 12152 KB Output is correct
102 Correct 95 ms 12152 KB Output is correct
103 Correct 96 ms 12280 KB Output is correct
104 Correct 94 ms 12152 KB Output is correct
105 Correct 99 ms 12152 KB Output is correct