Submission #1291639

#TimeUsernameProblemLanguageResultExecution timeMemory
1291639SofiatpcConnecting Supertrees (IOI20_supertrees)C++20
19 / 100
97 ms22180 KiB
#include "supertrees.h"
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1005;
int marc[MAXN];

int construct(vector<vector<int>> p) {
	int n = p.size();

	vector<vector<int>> ans; ans.resize(n);
	for(int i = 0; i < n; i++){
		ans[i].resize(n);
		for(int j = 0; j < n; j++)ans[i][j] = 0;
	}

	int nxt = 1;
	for(int i = 0; i < n; i++){
		if(marc[i]){
			for(int j = 0; j < n; j++){
				if(p[i][j] && marc[j] != marc[i])return 0;
				if(!p[i][j] && marc[j] == marc[i])return 0;
			}
		}else{
			int lst = -1, qtd = 0;
			for(int j = 0; j < n; j++)
				if(p[i][j]){
					marc[j] = nxt;
					if(lst != -1){ans[lst][j] = 1; ans[j][lst] = 1;}
					lst = j;
					qtd++;
				}
			for(int j = 0; j < n; j++)
				if(p[i][j]){
					if(lst != j){ans[lst][j] = 1; ans[j][lst] = 1;}
					break;
				}
			if(qtd == 2)return 0;
			nxt++;
		}
	}

	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...