답안 #977452

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
977452 2024-05-08T02:22:58 Z Amaarsaa 슈퍼트리 잇기 (IOI20_supertrees) C++14
40 / 100
194 ms 23500 KB
#include<bits/stdc++.h>
#include "supertrees.h"
using namespace std;
vector < int > adj[1002];
int ataman[10002], used[1002];
int Get(int x) {
	if ( x == ataman[x]) return x;
	return ataman[x] = Get(ataman[x]);
}
void Unite(int x, int y) {
	x = Get(x);
	y = Get(y);
	if (x == y) return ;
	if ( x < y) swap(x, y);
	ataman[x]= y;
}
int construct(vector<vector<int>> a) {
	int n = a.size(), i, j;
	vector < vector < int > > ans(n, vector<int>(n, 0));
	for (i = 0; i < n; i ++) ataman[i]= i;
	int s = 1;
	for ( i = 0; i < n; i++) {
		for ( j = 0; j < n; j ++) {
			if ( a[i][j] == 1 && i != j) Unite(i, j);
		}
	}
	for (i = 0; i < n; i ++) {
		for (j = 0; j < n; j ++) {
			if ( i == j) continue;
			if ( (a[i][j] == 0 || a[i][j] == 3) && Get(i) == Get(j)) s= 0;
			if ( a[i][j] == 1 && Get(i) != Get(j)) s = 0; 
		}
	}
	
	for (i = 0; i < n; i ++) {
		vector < int > v;
		v.push_back(i);
		for (j = i + 1; j < n; j ++) {
			if ( Get(j) == Get(i) && !used[j]) v.push_back(j);
		}
		used[i] = 1;
		for (j = 1; j < v.size(); j ++) {
			used[v[j]] = 1;
			ans[v[j]][v[j - 1]] = ans[v[j - 1]][v[j]] = 1;
		}
		
	}
	for (i = 0; i < n; i ++) ataman[i] = i;
	for (i = 0; i < n; i ++) {
		for (j = 0; j < n; j ++) {
			if ( a[i][j] == 2 && i != j) Unite(i, j);
		}
	}
	for (i = 0; i < n; i ++) used[i] = 0;
	for (i = 0; i < n; i ++) {
		for (j = 0; j < n; j ++) {
			if ( i == j) continue;
			if ( (a[i][j] == 0 || a[i][j] == 3) && Get(i) == Get(j)) s= 0;
			if ( a[i][j] == 2 && Get(i) != Get(j)) s = 0; 
		}
	}
	
	for (i = 0; i < n; i ++) {
		vector < int > v;
		v.push_back(i);
		for (j = i + 1; j < n; j ++) {
			if ( Get(j) == Get(i) && !used[j]) v.push_back(j);
		}
		if(v.size() == 1) continue;
		if ( v.size() == 2){
			s = 0;
			break;
		}
		used[i] = 1;
		for (j = 1; j < v.size(); j ++) {
			used[v[j]] = 1;
			ans[v[j]][v[j - 1]] = ans[v[j - 1]][v[j]] = 1;
		}
		ans[v[0]][v[v.size() -1]] = ans[v[v.size() -1]][v[0]] = 1;
		
	}
	if ( s == 0) return 0;
	build(ans);
	return s;
}
/*
vector < vector < int > > b;
inp() {
	int n, i, j, x;
	cin >>n;
	b.resize(n);
	for (i = 0; i < n; i ++) {
		for (j = 0; j < n; j ++) {
			cin >> x;
			b[i].push_back(x);
		}
	}
}
int main() {
	inp();
	cout << construct(b) << endl;
}
*/

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:42:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |   for (j = 1; j < v.size(); j ++) {
      |               ~~^~~~~~~~~~
supertrees.cpp:75:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |   for (j = 1; j < v.size(); j ++) {
      |               ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1116 KB Output is correct
7 Correct 160 ms 22192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1116 KB Output is correct
7 Correct 160 ms 22192 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 600 KB Output is correct
12 Correct 7 ms 1112 KB Output is correct
13 Correct 170 ms 22168 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 4 ms 860 KB Output is correct
17 Correct 92 ms 12068 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 41 ms 5720 KB Output is correct
21 Correct 164 ms 22100 KB Output is correct
22 Correct 163 ms 22004 KB Output is correct
23 Correct 194 ms 22100 KB Output is correct
24 Correct 163 ms 22080 KB Output is correct
25 Correct 81 ms 12116 KB Output is correct
26 Correct 78 ms 12116 KB Output is correct
27 Correct 165 ms 22100 KB Output is correct
28 Correct 163 ms 22100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 7 ms 1412 KB Output is correct
9 Correct 162 ms 23380 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 7 ms 1404 KB Output is correct
13 Correct 163 ms 23460 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 4 ms 856 KB Output is correct
17 Correct 94 ms 13552 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 42 ms 6244 KB Output is correct
22 Correct 166 ms 23480 KB Output is correct
23 Correct 172 ms 23436 KB Output is correct
24 Correct 165 ms 23424 KB Output is correct
25 Correct 76 ms 13396 KB Output is correct
26 Correct 79 ms 13408 KB Output is correct
27 Correct 162 ms 23380 KB Output is correct
28 Correct 165 ms 23500 KB Output is correct
29 Correct 77 ms 13396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 46 ms 6260 KB Output is correct
5 Correct 166 ms 23304 KB Output is correct
6 Correct 162 ms 23456 KB Output is correct
7 Correct 180 ms 23296 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 42 ms 6312 KB Output is correct
10 Correct 167 ms 23376 KB Output is correct
11 Correct 163 ms 23376 KB Output is correct
12 Correct 167 ms 23500 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Incorrect 1 ms 600 KB Too many ways to get from 0 to 4, should be 1 found no less than 2
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1116 KB Output is correct
7 Correct 160 ms 22192 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 600 KB Output is correct
12 Correct 7 ms 1112 KB Output is correct
13 Correct 170 ms 22168 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 4 ms 860 KB Output is correct
17 Correct 92 ms 12068 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 41 ms 5720 KB Output is correct
21 Correct 164 ms 22100 KB Output is correct
22 Correct 163 ms 22004 KB Output is correct
23 Correct 194 ms 22100 KB Output is correct
24 Correct 163 ms 22080 KB Output is correct
25 Correct 81 ms 12116 KB Output is correct
26 Correct 78 ms 12116 KB Output is correct
27 Correct 165 ms 22100 KB Output is correct
28 Correct 163 ms 22100 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 0 ms 344 KB Output is correct
36 Correct 7 ms 1412 KB Output is correct
37 Correct 162 ms 23380 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 1 ms 344 KB Output is correct
40 Correct 7 ms 1404 KB Output is correct
41 Correct 163 ms 23460 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 4 ms 856 KB Output is correct
45 Correct 94 ms 13552 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 42 ms 6244 KB Output is correct
50 Correct 166 ms 23480 KB Output is correct
51 Correct 172 ms 23436 KB Output is correct
52 Correct 165 ms 23424 KB Output is correct
53 Correct 76 ms 13396 KB Output is correct
54 Correct 79 ms 13408 KB Output is correct
55 Correct 162 ms 23380 KB Output is correct
56 Correct 165 ms 23500 KB Output is correct
57 Correct 77 ms 13396 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 4 ms 860 KB Output is correct
61 Correct 104 ms 13392 KB Output is correct
62 Correct 1 ms 348 KB Output is correct
63 Correct 0 ms 348 KB Output is correct
64 Correct 0 ms 348 KB Output is correct
65 Incorrect 41 ms 6228 KB Too many ways to get from 1 to 269, should be 1 found no less than 2
66 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1116 KB Output is correct
7 Correct 160 ms 22192 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 600 KB Output is correct
12 Correct 7 ms 1112 KB Output is correct
13 Correct 170 ms 22168 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 4 ms 860 KB Output is correct
17 Correct 92 ms 12068 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 41 ms 5720 KB Output is correct
21 Correct 164 ms 22100 KB Output is correct
22 Correct 163 ms 22004 KB Output is correct
23 Correct 194 ms 22100 KB Output is correct
24 Correct 163 ms 22080 KB Output is correct
25 Correct 81 ms 12116 KB Output is correct
26 Correct 78 ms 12116 KB Output is correct
27 Correct 165 ms 22100 KB Output is correct
28 Correct 163 ms 22100 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 0 ms 344 KB Output is correct
36 Correct 7 ms 1412 KB Output is correct
37 Correct 162 ms 23380 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 1 ms 344 KB Output is correct
40 Correct 7 ms 1404 KB Output is correct
41 Correct 163 ms 23460 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 4 ms 856 KB Output is correct
45 Correct 94 ms 13552 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 42 ms 6244 KB Output is correct
50 Correct 166 ms 23480 KB Output is correct
51 Correct 172 ms 23436 KB Output is correct
52 Correct 165 ms 23424 KB Output is correct
53 Correct 76 ms 13396 KB Output is correct
54 Correct 79 ms 13408 KB Output is correct
55 Correct 162 ms 23380 KB Output is correct
56 Correct 165 ms 23500 KB Output is correct
57 Correct 77 ms 13396 KB Output is correct
58 Correct 0 ms 344 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 1 ms 348 KB Output is correct
61 Correct 46 ms 6260 KB Output is correct
62 Correct 166 ms 23304 KB Output is correct
63 Correct 162 ms 23456 KB Output is correct
64 Correct 180 ms 23296 KB Output is correct
65 Correct 1 ms 348 KB Output is correct
66 Correct 42 ms 6312 KB Output is correct
67 Correct 167 ms 23376 KB Output is correct
68 Correct 163 ms 23376 KB Output is correct
69 Correct 167 ms 23500 KB Output is correct
70 Correct 1 ms 344 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Incorrect 1 ms 600 KB Too many ways to get from 0 to 4, should be 1 found no less than 2
73 Halted 0 ms 0 KB -