Submission #601103

#TimeUsernameProblemLanguageResultExecution timeMemory
601103FatihSolakConnecting Supertrees (IOI20_supertrees)C++17
100 / 100
226 ms24040 KiB
#include "supertrees.h"
#include <bits/stdc++.h>
#define N 1005
using namespace std;

int construct(vector<vector<int>> p){
	int n = p.size();
	vector<vector<int>> answer;
	for (int i = 0; i < n; i++) {
		vector<int> row;
		row.resize(n);
		answer.push_back(row);
	}
	vector<bool> vis(n);
	for(int i = 0;i<n;i++){
		if(!vis[i]){
			vector<bool> vis2(n,0);
			vector<int> cur(n,0);
			vector<int> now;
			for(int j = 0;j<n;j++){
				if(p[i][j]){
					if(vis[j])
						return 0;
					vis[j] = 1;
					cur[j]  = 1;
					now.push_back(j);
				}
			}
			for(auto u:now){
				for(int j = 0;j<n;j++){
					if(!!p[u][j] != cur[j]){
						return 0;
					}
				}
			}
			vector<int> circle;
			vector<int> par_on_circle(n);
			for(auto u:now){
				if(vis2[u])continue;
				circle.push_back(u);
				for(int j = 0;j<n;j++){
					if(p[u][j] == 1){
						par_on_circle[j] = u;
						vis2[j] = 1;
						if(u != j){
							answer[u][j] = answer[j][u] = 1;
						}
					}
				}
			}
			int sz = circle.size();
			if(sz == 2)
				return 0;
			for(auto u:now){
				for(auto c:now){
					if(p[u][c] != (sz == 1?1:2 - (par_on_circle[u] == par_on_circle[c])) ){
						return 0;
					}
				}
			}
			if(sz != 1){
				for(int j = 0;j<sz;j++){
					answer[circle[j]][circle[(j+1)%sz]] = answer[circle[(j+1)%sz]][circle[j]] = 1;
				}
			}
		}
	}
	build(answer);
	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...