답안 #807368

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
807368 2023-08-04T16:28:38 Z nemethm 슈퍼트리 잇기 (IOI20_supertrees) C++17
21 / 100
166 ms 26456 KB
#include "supertrees.h"
#include <vector>

using namespace std;

int cmp[1010] = {0};

int subtask3(std::vector<std::vector<int>> p){
	int n = p.size();
	std::vector<std::vector<int>> answer;
	for (int i = 0; i < n; i++) {
		std::vector<int> row;
		row.resize(n);
		answer.push_back(row);
	}
	int id = 0;
	vector<vector<int>> elek;
	for(int i = 0; i < n; ++i){
		bool uj = false;
		if(cmp[i] != 0 && p[i][i] == 1){
			return 0;
		}
		if(cmp[i] == 0){
			++id;
			cmp[i] = id;
			uj = true;
			elek.push_back({i});
		}
		for(int j = 0; j < n; ++j){
			if(j == i) continue;
			if(p[i][j] == 1){
				if(cmp[j] != cmp[i] && !uj){
					return 0;
				}
				else if(uj){
					cmp[j] = cmp[i];
					elek.back().push_back(j);
				}
			}
			else{
				if(cmp[j] == cmp[i]){
					return 0;
				}
			}
		}
		if(uj && elek.size() > 1 && p[i][i] == 1){
			return 0;
		}
	}
	for(auto& v : elek){
		if(v.size() == 2){
			return 0;
		}
		if(v.size() > 2){
			for(int i = 0; i < v.size(); ++i){
				answer[v[i]][v[(i + 1) % v.size()]] = answer[v[(i + 1) % v.size()]][v[i]] = 1;
			}
		}
	}
	build(answer);
	return 1;
}

int subtask12(std::vector<std::vector<int>> p){
		int n = p.size();
	std::vector<std::vector<int>> answer;
	for (int i = 0; i < n; i++) {
		std::vector<int> row;
		row.resize(n);
		answer.push_back(row);
	}
	int id = 0;
	vector<vector<pair<int,int>>> elek;
	for(int i = 0; i < n; ++i){
		bool uj = false;
		if(cmp[i] == 0){
			++id;
			cmp[i] = id;
			uj = true;
			elek.push_back({});
		}
		for(int j = 0; j < n; ++j){
			if(j == i) continue;
			if(p[i][j] == 1){
				if(cmp[j] != cmp[i] && !uj){
					return 0;
				}
				else if(uj){
					cmp[j] = cmp[i];
					elek.back().push_back({j, i});
				}
			}
			else{
				if(cmp[j] == cmp[i]){
					return 0;
				}
			}
		}
	}
	for(auto& v : elek){
		for(auto i : v){
			answer[i.first][i.second] = answer[i.second][i.first] = 1;
		}
	}
	build(answer);
	return 1;
}

int construct(std::vector<std::vector<int>> p) {
	for(int i = 0; i < p.size(); ++i){
		for(int j = 0; j < p.size(); ++j){
			if(p[i][j] == 2){
				return subtask3(p);
			}
		}
	}
	return subtask12(p);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int subtask3(std::vector<std::vector<int> >)':
supertrees.cpp:55:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |    for(int i = 0; i < v.size(); ++i){
      |                   ~~^~~~~~~~~~
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:110:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  110 |  for(int i = 0; i < p.size(); ++i){
      |                 ~~^~~~~~~~~~
supertrees.cpp:111:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  111 |   for(int j = 0; j < p.size(); ++j){
      |                  ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 8 ms 1368 KB Output is correct
7 Correct 148 ms 26456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 8 ms 1368 KB Output is correct
7 Correct 148 ms 26456 KB Output is correct
8 Correct 1 ms 284 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1440 KB Output is correct
13 Correct 142 ms 26068 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 944 KB Output is correct
17 Correct 70 ms 16164 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 37 ms 6804 KB Output is correct
21 Correct 141 ms 26060 KB Output is correct
22 Correct 143 ms 26152 KB Output is correct
23 Correct 150 ms 26056 KB Output is correct
24 Correct 146 ms 26104 KB Output is correct
25 Correct 68 ms 16204 KB Output is correct
26 Correct 65 ms 16124 KB Output is correct
27 Correct 166 ms 26140 KB Output is correct
28 Correct 149 ms 26088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 288 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Incorrect 0 ms 288 KB Answer gives possible 0 while actual possible 1
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 292 KB Output is correct
2 Incorrect 0 ms 212 KB Answer gives possible 0 while actual possible 1
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 8 ms 1368 KB Output is correct
7 Correct 148 ms 26456 KB Output is correct
8 Correct 1 ms 284 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1440 KB Output is correct
13 Correct 142 ms 26068 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 944 KB Output is correct
17 Correct 70 ms 16164 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 37 ms 6804 KB Output is correct
21 Correct 141 ms 26060 KB Output is correct
22 Correct 143 ms 26152 KB Output is correct
23 Correct 150 ms 26056 KB Output is correct
24 Correct 146 ms 26104 KB Output is correct
25 Correct 68 ms 16204 KB Output is correct
26 Correct 65 ms 16124 KB Output is correct
27 Correct 166 ms 26140 KB Output is correct
28 Correct 149 ms 26088 KB Output is correct
29 Correct 0 ms 288 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Incorrect 0 ms 288 KB Answer gives possible 0 while actual possible 1
34 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 8 ms 1368 KB Output is correct
7 Correct 148 ms 26456 KB Output is correct
8 Correct 1 ms 284 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1440 KB Output is correct
13 Correct 142 ms 26068 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 944 KB Output is correct
17 Correct 70 ms 16164 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 37 ms 6804 KB Output is correct
21 Correct 141 ms 26060 KB Output is correct
22 Correct 143 ms 26152 KB Output is correct
23 Correct 150 ms 26056 KB Output is correct
24 Correct 146 ms 26104 KB Output is correct
25 Correct 68 ms 16204 KB Output is correct
26 Correct 65 ms 16124 KB Output is correct
27 Correct 166 ms 26140 KB Output is correct
28 Correct 149 ms 26088 KB Output is correct
29 Correct 0 ms 288 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Incorrect 0 ms 288 KB Answer gives possible 0 while actual possible 1
34 Halted 0 ms 0 KB -