Submission #384765

#TimeUsernameProblemLanguageResultExecution timeMemory
384765MicchonConnecting Supertrees (IOI20_supertrees)C++14
0 / 100
1 ms364 KiB
#include "supertrees.h"
#include <bits/stdc++.h>
#define vi vector<int>
using namespace std;

vi par;

int construct(std::vector<std::vector<int>> p) {
	int n = p.size();
    for(int i=0;i<n;i++) for(int j=0;j<n;j++) if(p[i][j] == 3) return 0;
	std::vector<std::vector<int>> answer(n,vi(n,0));
	par = vi(n,-1);
	vi cyc(n,0);
	for(int i=0;i<n;i++){
        if(par[i] != -1) continue;
        cyc[i] = 1;
        for(int j=0;j<n;j++){
            if(p[i][j] == 1){
                if(par[j] != -1 && par[j] != i) return 0;
                par[j] = i;
                if(i != j) answer[i][j] = 1 , answer[j][i] = 1;
            }
        }
	}

	par = vi(n,-1);
	for(int i=0;i<n;i++){
        if(par[i] != -1) continue;
        vi tmp;
        for(int j=0;j<n;j++){
            if(p[i][j] != 0){
                if(par[j] != -1 && par[j] != i) return 0;
                par[j] = i;
                if(cyc[j]) tmp.push_back(j);
            }
        }
        for(int j=0;j<tmp.size();j++){
            int i1 = tmp[j] , i2 = tmp[(j+1)%tmp.size()];
            answer[i1][i2] = 1 , answer[i2][i1] = 1;
        }
	}

	build(answer);
	return 1;
}

Compilation message (stderr)

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:37:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |         for(int j=0;j<tmp.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...