제출 #1358775

#제출 시각아이디문제언어결과실행 시간메모리
1358775maya_sConnecting Supertrees (IOI20_supertrees)C++20
40 / 100
618 ms26240 KiB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
typedef int ll;

vector<bool> info(1010);

bool solve(ll n, vector<ll> v, vector<vector<ll>> &p, vector<vector<ll>> &ans){ 
	vector<bool> vis(n);
	vector<vector<ll>> c(n);
	for(ll i: v) if(!vis[i]){
		for(ll j = 0; j < n; j++) if(p[i][j] == 1) c[i].push_back(j), vis[j] = 1;
	}
	vector<ll> cyc;
	for(ll i = 0; i < n; i++) if(c[i].size()) {
		if(cyc.size()) ans[cyc.back()][c[i][0]] = ans[c[i][0]][cyc.back()] = 1;
		cyc.push_back(c[i][0]); info[c[i][0]] = 1;
		for(ll j = 1; j < c[i].size(); j++) ans[c[i][j-1]][c[i][j]] = ans[c[i][j]][c[i][j-1]] = 1;
	}
	if(cyc.size() > 1) ans[cyc[0]][cyc.back()] = ans[cyc.back()][cyc[0]] = 1;
	return 1;
}

void test(ll n, ll org, ll val, vector<bool> &vis, vector<vector<ll>> &g, vector<vector<ll>> &p){
	vis[n] = 1;
	for(ll i : g[n]) if(!vis[i]){
		if(info[n] && info[i]) val = 2;
		p[org][i] = val;
		test(i, org, val, vis, g, p);
	}
}

int construct(vector<vector<int>> p) {
	int n = p.size();
	vector<bool> vis(n);
	vector<vector<ll>> ans(n, vector<ll>(n));
	for(ll i = 0; i < n; i++) if(!vis[n]){
		vector<ll> comp;
		for(ll j = 0; j < n; j++) if(p[i][j]) comp.push_back(j), vis[j] = 1;
		solve(n, comp, p, ans);
	}
	vector<vector<ll>> g(n);
	for(ll i = 0; i < n; i++) for(ll j = i+1; j < n; j++) if(ans[i][j]) g[i].push_back(j), g[j].push_back(i);
	vector<vector<ll>> values(n, vector<ll>(n));
	for(ll i = 0; i < n; i++) {
		vector<bool> test_vis(n);
		values[i][i] = 1;
		test(i, i, 1, test_vis, g, values);
		ll cnt = 0;
		for(ll j = 0; j < n; j++) if(p[i][j] == 2) cnt++;
		if(cnt == 1) return 0;
		for(ll j = 0; j < n; j++) if(values[i][j] != p[i][j]) return 0;
	}
	build(ans);
	return 1;
}
#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...