Submission #317733

#TimeUsernameProblemLanguageResultExecution timeMemory
317733amunduzbaevConnecting Supertrees (IOI20_supertrees)C++14
40 / 100
832 ms30240 KiB
//#include "grader.cpp"
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
#define pb(a) push_back(a) 

const int N=1005;
int used[N], o[N][N], t[N][N];

int construct(vector<vector<int>> p) {
	int n = p.size();
	vector<vector<int> > b(n), ones(n), twos(n);

		for(int i=0;i<n;i++){
			b[i].resize(n);
			for(int j=0;j<n;j++){
				b[i][j] = 0;
				if(i!=j && p[i][j] == 1){
					o[i][j] = 1;
					ones[i].pb(j);
				}
				if(i!=j && p[i][j] == 2){
					t[i][j];
					twos[i].pb(j);
				}
				if(p[i][j] == 3) return 0;
			}
			for(int j=0;j<ones[i].size(); j++){
				for(int l=j+1;l<ones[i].size();l++)
					if(p[ones[i][j]][ones[i][l]] != 1) return 0;
				for(int l=0;l<twos[i].size();l++)
					if(p[ones[i][j]][twos[i][l]] != 2) return 0;
			}
			if(twos[i].size() == 1) return 0;
			for(int j=0;j<twos[i].size(); j++){
				for(int l=0;l<ones[i].size();l++)
					if(p[twos[i][j]][ones[i][l]] != 2) return 0;
				for(int l=j+1;l<twos[i].size();l++){
					if(!p[twos[i][j]][twos[i][l]]) return 0;
				}
			}
		}
		memset(used, 0, sizeof(used));
		for(int i=0;i<n;i++){
			if(used[i]) continue;
			for(int j=0;j<ones[i].size();j++){
				used[ones[i][j]] = 1;
				b[i][ones[i][j]] = 1;
				b[ones[i][j]][i] = 1;
			}
			if(twos[i].size() == 0) continue;
			int j = 0, sz = twos[i].size();
			b[i][twos[i][j]] = 1;
			b[twos[i][j]][i] = 1;
			for(;j<sz-1; j++){
				used[twos[i][j]] = 1;
				b[twos[i][j]][twos[i][j+1]] = 1;
				b[twos[i][j+1]][twos[i][j]] = 1;
			}
			used[twos[i][j]] = 1;
			b[i][twos[i][j]] = 1;
			b[twos[i][j]][i] = 1;
		}
		build(b);
		return 1;
	
	return 0;
}

Compilation message (stderr)

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:23:12: warning: statement has no effect [-Wunused-value]
   23 |      t[i][j];
      |      ~~~~~~^
supertrees.cpp:28:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |    for(int j=0;j<ones[i].size(); j++){
      |                ~^~~~~~~~~~~~~~~
supertrees.cpp:29:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |     for(int l=j+1;l<ones[i].size();l++)
      |                   ~^~~~~~~~~~~~~~~
supertrees.cpp:31:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |     for(int l=0;l<twos[i].size();l++)
      |                 ~^~~~~~~~~~~~~~~
supertrees.cpp:35:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |    for(int j=0;j<twos[i].size(); j++){
      |                ~^~~~~~~~~~~~~~~
supertrees.cpp:36:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     for(int l=0;l<ones[i].size();l++)
      |                 ~^~~~~~~~~~~~~~~
supertrees.cpp:38:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |     for(int l=j+1;l<twos[i].size();l++){
      |                   ~^~~~~~~~~~~~~~~
supertrees.cpp:46:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |    for(int j=0;j<ones[i].size();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...