Submission #603671

#TimeUsernameProblemLanguageResultExecution timeMemory
603671HamletPetrosyanConnecting Supertrees (IOI20_supertrees)C++17
11 / 100
173 ms21980 KiB
#include "supertrees.h"
#include <vector>
using namespace std;

#define add push_back
#define len(a) ((int)(a).size())

int construct(vector<vector<int>> p) {
	vector<vector<int>> answer(len(p));
	vector<int> h(len(p));
	vector<int> v[1005];

	int now = 0;
	for(int i = 0; i < len(p); i++){
		answer[i].resize(len(p));
		for(int j = 0; j < i; j++){
			if(p[i][j] != 0){
				h[i] = h[j];
				break;
			}
		}
		if(h[i] == 0){
			h[i] = ++now;
		}
		v[h[i]].add(i);
	}

	for(int i = 0; i < len(p); i++){
		for(int j = i + 1; j < len(p); j++){
			if(p[i][j] != 0 && h[i] != h[j]){
				return 0;
			}
		}
	}

	for(int i = 1; i <= now; i++){
		for(int j = 1; j < len(v[now]); j++){
			answer[v[now][j]][v[now][j - 1]] = answer[v[now][j - 1]][v[now][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...