답안 #812484

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
812484 2023-08-07T08:56:14 Z KemalK 슈퍼트리 잇기 (IOI20_supertrees) C++17
0 / 100
1000 ms 2031208 KB
#include "supertrees.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
int pr[N];
int sz[N];
int get(int x){
	if (pr[x] == x){
		return x;
	}
	return pr[x] == get(pr[x]);
}
void unit(int a, int b){
	a = get(a);
	b = get(b);
	if (a != b){
		if (sz[a] < sz[b]){
			swap(a, b);
		}
		pr[b] = a;
		sz[a] += sz[b];
	}
}
int construct(std::vector<std::vector<int>> p) {
	int n = p.size();
	bool sub_task_1 = true;
	bool sub_task_2 = true;
	for (int i = 0; i < n; i++){
		pr[i] = i;
	}
	for (int i = 0; i < n; i++){
		for (int j = 0; j < n; j++){
			if (i != j and p[i][j]){
				unit(i, j);
			}
		}
	}
	for (int i = 0; i < n; i++){
		for (int j = 0; j < n; j++){

			if (p[i][j] != 1){
				sub_task_1 = false;
			}
			if (p[i][j] != 2 and p[i][j] != 3){
				sub_task_2 = false;
			}
		}
	}
	std::vector<std::vector<int>> answer;
	for (int i = 0; i < n; i++) {
		std::vector<int> row;
		row.resize(n);
		answer.push_back(row);
	}
	if (n == 1){
		//nothing to change
	}	
	else if (sub_task_1){ // p[i][j] = 1
		for (int i = 0; i < n - 1; i++){
			answer[i][i + 1] = 1;
			answer[i + 1][i] = 1;
		}
	}
	else if(sub_task_2) {	// p[i][j] = 1 or p[i][j] = 0
		map <int, vector<int>> mp;
		for (int i = 0; i < n; i++){
			int x = get(i);
			mp[x].push_back(i);
		}
		for (auto x: mp){
			for (int i = 0; i < x.second.size() - 1; i++){
				answer[x.second[i]][x.second[i + 1]] = 1;
				answer[x.second[i + 1]][x.second[i]] = 1;
			}
		}
	}
	build(answer);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:72:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |    for (int i = 0; i < x.second.size() - 1; i++){
      |                    ~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Execution timed out 1178 ms 1758732 KB Time limit exceeded
4 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 Execution timed out 1178 ms 1758732 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Incorrect 1 ms 304 KB Answer gives possible 1 while actual possible 0
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 1164 ms 2031208 KB Time limit exceeded
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 Execution timed out 1178 ms 1758732 KB Time limit exceeded
4 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 Execution timed out 1178 ms 1758732 KB Time limit exceeded
4 Halted 0 ms 0 KB -