Submission #549905

#TimeUsernameProblemLanguageResultExecution timeMemory
549905esomerConnecting Supertrees (IOI20_supertrees)C++17
11 / 100
217 ms22376 KiB
#include "supertrees.h"
#include <bits/stdc++.h>

using namespace std;

int construct(vector<vector<int>> p) {
	int n = p.size();
	vector<bool> vis(n, 0);
	bool pos = 1;
	vector<vector<int>> ans(n, vector<int>(n, 0));
	for(int i = 0; i < n; i++){
		if(!vis[i]){
			vector<int> three;
			vector<int> two;
			vector<int> one;
			vis[i] = 1;
			for(int j = 0; j < n; j++){
				if(i == j || p[i][j] == 0) continue;
				if(vis[j] == 1){
					pos = 0;
					break;
				}
				vis[j] = 1;
				if(p[i][j] == 3) three.push_back(j);
				else if(p[i][j] == 2) two.push_back(j);
				else one.push_back(j);
			}
			if((three.size() > 0 && three.size() < 3 ) || (two.size() > 0 && two.size() < 2)){
				pos = 0;
				break;
			}
			if(three.size() > 0){
				ans[i][three[three.size() - 1]] = ans[i][three[three.size() - 2]] = 1;
				ans[three[three.size() - 1]][i] = ans[three[three.size() - 2]][i] = 1;
				ans[three[0]][i] = ans[i][three[0]] = 1;
				for(int j = 0; j < three.size() - 1; j++){
					ans[three[j]][three[j+1]] = ans[three[j+1]][three[j]] = 1;
				}
			}
			if(two.size() > 0){
				ans[i][two[two.size() - 1]] = ans[two[two.size() - 1]][i] = 1;
				ans[i][two[0]] = ans[two[0]][i] = 1;
				for(int j = 0; j < two.size() - 1; j++){
					ans[two[j]][two[j+1]] = ans[two[j+1]][two[j]] = 1;
				}
			}
			if(one.size() > 0){
				ans[one[0]][i] = ans[i][one[0]] = 1;
				for(int j = 0; j < one.size() - 1; j++){
					ans[one[j]][one[j+1]] = ans[one[j+1]][one[j]] = 1;
				}
			}
			for(int i : three){
				for(int j : three){
					if(j == i) continue;
					if(p[i][j] != 3){
						pos = 0;
						break;
					}
				}
				for(int j : two){
					if(p[i][j] != 3){
						pos = 0;
						break;
					}
				}
				for(int j : one){
					if(p[i][j] != 3){
						pos = 0;
						break;
					}
				}
			}
			for(int i : two){
				for(int j : two){
					if(i == j) continue;
					if(p[i][j] != 2){
						pos = 0;
						break;
					}
				}
				for(int j : one){
					if(p[i][j] != 2){
						pos = 0;
						break;
					}
				}
			}
			for(int i : one){
				for(int j : one){
					if(i == j) continue;
					if(p[i][j] != 1){
						pos = 0;
						break;
					}
				}
			}
		}else{
      for(int j = 0; j < n; j++){
        if(p[i][j] != 0 && vis[j] == false){
          pos = 0;
          break;
        }
      }
    }
	}
	if(pos){
		build(ans);
    return 1;
	}else return 0;
}

Compilation message (stderr)

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:36:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     for(int j = 0; j < three.size() - 1; j++){
      |                    ~~^~~~~~~~~~~~~~~~~~
supertrees.cpp:43:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |     for(int j = 0; j < two.size() - 1; j++){
      |                    ~~^~~~~~~~~~~~~~~~
supertrees.cpp:49:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |     for(int j = 0; j < one.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...