답안 #1078257

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1078257 2024-08-27T14:36:08 Z mindiyak 슈퍼트리 잇기 (IOI20_supertrees) C++14
56 / 100
158 ms 22372 KB
#include "supertrees.h"
#include <vector>
#include <set>
#include <iostream>

using namespace std;
vector<int> parent(1005,0);
vector<int> parentg(1005,0);

int get_parent(int a){
	if(a == parent[a])return a;
	return get_parent(parent[a]);
}

int get_parentg(int a){
	if(a == parentg[a])return a;
	return get_parentg(parentg[a]);
}

int construct(vector<vector<int>> p) {
	int n = p.size();
	vector<vector<int>> answer(n, vector<int>(n,0));

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

	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			if(p[i][j] == 3)return 0;
			if(p[i][j] == 1){
				if(get_parent(i) == get_parent(j))continue;
				answer[i][j] = 1;
				answer[j][i] = 1;
				parent[j] = get_parent(i);
				parentg[j] = parent[j];
			}
		}
	}

	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			if(p[i][j] == 2){
				int a = get_parent(i), b = get_parent(j);
				if(a==b)
					return 0;
				if(get_parentg(a) == get_parentg(b))continue;
				if(a>b)swap(a,b);

				parentg[get_parentg(b)] = get_parentg(a);
			}	
		}
	}

	vector<set<int>> heads(1005);
	for(int i=0;i<n;i++){
		heads[get_parentg(i)].insert(get_parent(i));
	}

	for(int i=0;i<n;i++){
		vector<int> temp;
		for(int a:heads[i])temp.push_back(a);
		int m = temp.size();
		if(m < 2)continue;
		for(int j = 0;j<=temp.size();j++){
			answer[temp[j%m]][temp[(j+1)%m]] = 1;
			answer[temp[(j+1)%m]][temp[j%m]] = 1;
		}
	}

	cerr << endl;
	for(int i=0;i<n;i++)cerr << get_parent(i) << " ";
	cerr << endl;
	for(int i=0;i<n;i++)cerr << get_parentg(i) << " ";
	cerr << endl;

	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			int a = get_parent(i), b = get_parent(j);
			int c = get_parentg(a), d = get_parentg(b);
			if(p[i][j] == 0){
				if(a == b)return 0;
				if(c == d)return 0;
			}
			if(p[i][j] == 1){
				if(a != b)return 0;
			}
			if(p[i][j] == 2){
				if(heads[c].size() < 2)return 0;
				if(a == b)return 0;
				if(c != d)return 0;
			}
		}
	}


	build(answer);
	return 1;

}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:64:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |   for(int j = 0;j<=temp.size();j++){
      |                 ~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 6 ms 1372 KB Output is correct
7 Correct 127 ms 22100 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 0 ms 348 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 6 ms 1372 KB Output is correct
7 Correct 127 ms 22100 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 6 ms 1372 KB Output is correct
13 Correct 128 ms 22096 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 5 ms 860 KB Output is correct
17 Correct 88 ms 12304 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 32 ms 5792 KB Output is correct
21 Correct 146 ms 22236 KB Output is correct
22 Correct 121 ms 22100 KB Output is correct
23 Correct 127 ms 22032 KB Output is correct
24 Correct 129 ms 22100 KB Output is correct
25 Correct 55 ms 12320 KB Output is correct
26 Correct 58 ms 12320 KB Output is correct
27 Correct 126 ms 22048 KB Output is correct
28 Correct 121 ms 22288 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 0 ms 348 KB Output is correct
4 Incorrect 0 ms 600 KB Answer gives possible 1 while actual possible 0
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 38 ms 5788 KB Output is correct
5 Correct 150 ms 22100 KB Output is correct
6 Correct 122 ms 22372 KB Output is correct
7 Correct 135 ms 22032 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 33 ms 5796 KB Output is correct
10 Correct 122 ms 22100 KB Output is correct
11 Correct 129 ms 22096 KB Output is correct
12 Correct 132 ms 22040 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 31 ms 5780 KB Output is correct
17 Correct 125 ms 22048 KB Output is correct
18 Correct 127 ms 22104 KB Output is correct
19 Correct 126 ms 22100 KB Output is correct
20 Correct 158 ms 22100 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 0 ms 348 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 6 ms 1372 KB Output is correct
7 Correct 127 ms 22100 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 6 ms 1372 KB Output is correct
13 Correct 128 ms 22096 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 5 ms 860 KB Output is correct
17 Correct 88 ms 12304 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 32 ms 5792 KB Output is correct
21 Correct 146 ms 22236 KB Output is correct
22 Correct 121 ms 22100 KB Output is correct
23 Correct 127 ms 22032 KB Output is correct
24 Correct 129 ms 22100 KB Output is correct
25 Correct 55 ms 12320 KB Output is correct
26 Correct 58 ms 12320 KB Output is correct
27 Correct 126 ms 22048 KB Output is correct
28 Correct 121 ms 22288 KB Output is correct
29 Correct 0 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 Incorrect 0 ms 600 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 6 ms 1372 KB Output is correct
7 Correct 127 ms 22100 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 6 ms 1372 KB Output is correct
13 Correct 128 ms 22096 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 5 ms 860 KB Output is correct
17 Correct 88 ms 12304 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 32 ms 5792 KB Output is correct
21 Correct 146 ms 22236 KB Output is correct
22 Correct 121 ms 22100 KB Output is correct
23 Correct 127 ms 22032 KB Output is correct
24 Correct 129 ms 22100 KB Output is correct
25 Correct 55 ms 12320 KB Output is correct
26 Correct 58 ms 12320 KB Output is correct
27 Correct 126 ms 22048 KB Output is correct
28 Correct 121 ms 22288 KB Output is correct
29 Correct 0 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 Incorrect 0 ms 600 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -