답안 #977672

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
977672 2024-05-08T09:03:40 Z SmuggingSpun 슈퍼트리 잇기 (IOI20_supertrees) C++17
11 / 100
156 ms 18016 KB
#include "supertrees.h"
#include<bits/stdc++.h>
using namespace std;
int construct(vector<vector<int>>p){
	int n = p.size();
	bool is_sub1 = true;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			if(p[i][j] != 1){
				is_sub1 = false;
				i = n;
				break;
			}
		}
	}
	if(is_sub1){
		p = vector<vector<int>>(n, vector<int>(n, 0));
		for(int i = 1; i < n; i++){
			p[i][i - 1] = p[i - 1][i] = 1;
		}
		build(p);
		return 1;
	}
	vector<int>par(n);
	iota(par.begin(), par.end(), 0);
	function<int(int)>find_set;
	find_set = [&] (int n){
		return n == par[n] ? n : par[n] = find_set(par[n]);	
	};
	function<void(int, int)>merge = [&] (int a, int b){
		par[find_set(a)] = find_set(b);
	};
	vector<bool>vis(n, false);
	vector<vector<int>>edge(n);
	for(int i = 0; i < n; i++){
		if(vis[i]){
			for(int j = 0; j < n; j++){
				if(i != j && int(find_set(i) == find_set(j)) != p[i][j]){
					return 0;
				}
			}
			continue;
		}
		for(int j = 0; j < n; j++){
			if(i != j && p[i][j] == 0 && find_set(i) == find_set(j)){
				return 0;
			}
			if(p[i][j] == 1){
				merge(i, j);
				vis[j] = true;
			}
		}
	}
	for(int i = 0; i < n; i++){
		edge[find_set(i)].emplace_back(i);
	}
	for(int i = 0; i < n; i++){
		for(int j = 1; j < edge.size(); j++){
			p[edge[i][j]][edge[i][j - 1]] = p[edge[i][j - 1]][edge[i][j]] = 1;
		}
	}
	build(p);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:58:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |   for(int j = 1; j < edge.size(); j++){
      |                  ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 6 ms 1108 KB Output is correct
7 Correct 156 ms 18016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 6 ms 1108 KB Output is correct
7 Correct 156 ms 18016 KB Output is correct
8 Incorrect 1 ms 344 KB b[0][0] is not 0
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB b[0][0] is not 0
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 6 ms 1108 KB Output is correct
7 Correct 156 ms 18016 KB Output is correct
8 Incorrect 1 ms 344 KB b[0][0] is not 0
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 6 ms 1108 KB Output is correct
7 Correct 156 ms 18016 KB Output is correct
8 Incorrect 1 ms 344 KB b[0][0] is not 0
9 Halted 0 ms 0 KB -