Submission #757726

#TimeUsernameProblemLanguageResultExecution timeMemory
757726PiokemonConnecting Supertrees (IOI20_supertrees)C++17
56 / 100
195 ms22192 KiB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

bool odw[1009];
int nr[1009];
vector<int> lista[1009];

int construct(vector<vector<int>> p) {
	int n = p.size();
	vector<int> czesc(n,0);
	vector<vector<int>> answer(n,czesc);
	for(int i=0;i<=n;i++) odw[i]=0;
	for (int i=0;i<n;i++){
		if (odw[i]) continue;
		nr[i] = i;
		lista[i].push_back(i);
		odw[i] = 1;
		for (int j=0;j<n;j++){
			if (p[i][j]==3) return 0;
			if (odw[j] || i==j) continue;
			if (p[i][j]==1){
				answer[i][j] = 1;
				answer[j][i] = 1;
				nr[j] = i;
				lista[i].push_back(j);
				odw[j] = 1;
			}
		}
	}
	for (int i=0;i<n;i++){
		for (int j=0;j<n;j++){
			if (p[i][j] != p[nr[i]][j]) return 0;
		}
	}
	for(int i=0;i<=n;i++) odw[i]=0;
	/*cout << "nr: ";
	for (int i=0;i<n;i++) cout << nr[i] << ' ';
	cout << '\n';*/
	for (int i=0;i<n;i++){
		if (nr[i]!=i || odw[i]) continue;
		vector<int> cykl;
		cykl.push_back(i);
		for (int j=0;j<n;j++){
			if (p[i][j]==2 && !odw[nr[j]]){
				cykl.push_back(nr[j]);
				odw[nr[j]] = 1;
			}
		}
		for (int x=0;x<cykl.size();x++){
			for (int y=0;y<cykl.size();y++){
				if (x==y) continue;
				for (int z:lista[cykl[y]]){
					if (p[cykl[x]][z]!=2) return 0;
				}
			}
		}
		/*cout << "cykl: ";
		for (int j:cykl){
			cout << j << ' ';
		}
		cout << '\n';*/
		if (cykl.size()==1) continue;
		for (int j=0;j<cykl.size()-1;j++){
			answer[cykl[j]][cykl[j+1]] = 1;
			answer[cykl[j+1]][cykl[j]] = 1;
		}
		answer[cykl.back()][cykl[0]] = 1;
		answer[cykl[0]][cykl.back()] =1;
	}
	build(answer);
	return 1;
}

Compilation message (stderr)

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:51:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |   for (int x=0;x<cykl.size();x++){
      |                ~^~~~~~~~~~~~
supertrees.cpp:52:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |    for (int y=0;y<cykl.size();y++){
      |                 ~^~~~~~~~~~~~
supertrees.cpp:65:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |   for (int j=0;j<cykl.size()-1;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...