제출 #983802

#제출 시각아이디문제언어결과실행 시간메모리
983802phoenix0423Connecting Supertrees (IOI20_supertrees)C++17
100 / 100
166 ms24452 KiB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define pb push_back
#define eb emplace_back
#include "supertrees.h"

struct DSU{
	vector<int> par, siz;
	int n;
	DSU(int _n) : n(_n){
		par.resize(n);
		siz.resize(n, 1);
		iota(par.begin(), par.end(), 0);
	}
	int root(int x){ return x == par[x] ? x : par[x] = root(par[x]);}
	bool same(int x, int y){ return root(x) == root(y);}
	void unite(int x, int y){
		x = root(x), y = root(y);
		if(x == y) return;
		if(siz[x] > siz[y]) swap(x, y);
		siz[y] += siz[x];
		par[x] = y;
	}
};

int construct(std::vector<std::vector<int>> p) {
	int n = p.size();
	vector<vector<int>> ans(n, vector<int>(n));
	DSU dsu(n), dsu2(n);
	for(int i = 0; i < n; i++){
		if(p[i][i] != 1) return 0;
		for(int j = i + 1; j < n; j++){
			if(p[i][j] == 3) return 0;
			if(p[i][j] != p[j][i]) return 0;
			if(p[i][j] == 1) dsu.unite(i, j);
		}
	}
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			if(p[i][j] == 2){
				if(dsu.same(i, j)) return 0;
				dsu2.unite(dsu.root(i), dsu.root(j));
			}
		}
	}
	auto add = [&](int x, int y) -> void {
		ans[x][y] = ans[y][x] = 1;
	};
	vector<vector<int>> loop(n);
	for(int i = 0; i < n; i++){
		if(i != dsu.root(i)){
			add(i, dsu.root(i));
		}
		if(i != dsu2.root(i)) loop[dsu2.root(i)].pb(i);
	}
	for(int i = 0; i < n; i++){
		if(!loop[i].size()) continue;
		if(loop[i].size() == 1) return 0;
		loop[i].pb(i);
		for(int j = 0; j < loop[i].size(); j++){
			add(loop[i][j], loop[i][(j + 1) % loop[i].size()]);
		}
	}
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			if(!p[i][j] && dsu2.same(dsu.root(i), dsu.root(j))) return 0;
		}
	}
	build(ans);
	return 1;
}

컴파일 시 표준 에러 (stderr) 메시지

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:62:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |   for(int j = 0; j < loop[i].size(); j++){
      |                  ~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...