답안 #812577

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
812577 2023-08-07T09:24:31 Z KemalK 슈퍼트리 잇기 (IOI20_supertrees) C++17
11 / 100
172 ms 23164 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; sz[i] = 1;
	}
	for (int i = 0; i < n; i++){
		for (int j = 0; j < i + 1; 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 or 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:71:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |    for (int i = 0; i < x.second.size() - 1; i++){
      |                    ~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 1220 KB Output is correct
7 Correct 172 ms 23036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 1220 KB Output is correct
7 Correct 172 ms 23036 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 7 ms 1212 KB Output is correct
13 Correct 158 ms 23164 KB Output is correct
14 Incorrect 1 ms 212 KB Answer gives possible 1 while actual possible 0
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Incorrect 1 ms 300 KB Answer gives possible 1 while actual possible 0
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 304 KB Output is correct
2 Incorrect 1 ms 304 KB Too few ways to get from 0 to 1, should be 2 found 0
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 1220 KB Output is correct
7 Correct 172 ms 23036 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 7 ms 1212 KB Output is correct
13 Correct 158 ms 23164 KB Output is correct
14 Incorrect 1 ms 212 KB Answer gives possible 1 while actual possible 0
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 1220 KB Output is correct
7 Correct 172 ms 23036 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 7 ms 1212 KB Output is correct
13 Correct 158 ms 23164 KB Output is correct
14 Incorrect 1 ms 212 KB Answer gives possible 1 while actual possible 0
15 Halted 0 ms 0 KB -