Submission #470416

#TimeUsernameProblemLanguageResultExecution timeMemory
470416jazzupConnecting Supertrees (IOI20_supertrees)C++14
21 / 100
274 ms24112 KiB
#include "supertrees.h" #include <vector> #include <cstdio> using namespace std; int par[1010]; vector<int> heads; int findPar(int n){ if(par[n]==n)return n; return par[n]=findPar(par[n]); } bool c[1010]; vector<vector<int> > answer; int construct(vector<vector<int> > p) { int n = p.size(); for(int i=0;i<=n;i++){ par[i]=i; } for(int i=0;i<n;i++){ vector<int> vv; answer.push_back(vv); for(int j=0;j<n;j++){ answer[i].push_back(0); } } for(int i=0;i<n-1;i++){ for(int j=i+1;j<n;j++){ if(p[i][j]!=p[j][i])return 0; } } for(int i=0;i<n-1;i++){ for(int j=i+1;j<n;j++){ if(p[i][j]==3)return 0; if(p[i][j]==1){ if(findPar(i)<findPar(j)){ par[j]=findPar(i); answer[j][par[j]]=1; answer[par[j]][j]=1; } else if(findPar(i)>findPar(j)){ par[i]=findPar(j); answer[i][par[i]]=1; answer[par[i]][i]=1; } } } } for(int i=0;i<n-1;i++){ for(int j=i+1;j<n;j++){ // if(i==j)continue; if(p[i][j]==2){ if(findPar(i)==findPar(j)){ return 0; } c[findPar(i)]=true; c[findPar(j)]=true; par[findPar(j)]=findPar(par[i]); } else if(p[i][j]==0){ if(findPar(i)==findPar(j)){ return 0; } } } } for(int i=0;i<n;i++){ if(c[i])heads.push_back(i); } if(!heads.empty()){ for(int i=0;i<heads.size()-1;i++){ answer[heads[i]][heads[i+1]]=1; answer[heads[i+1]][heads[i]]=1; } answer[heads[heads.size()-1]][heads[0]]=1; answer[heads[0]][heads[heads.size()-1]]=1; } if(heads.size()==2)return 0; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ if(i==j)continue; else if(p[i][j]==0){ if(findPar(i)==findPar(j)){ return 0; } } } } build(answer); return 1; }

Compilation message (stderr)

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:87:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |   for(int i=0;i<heads.size()-1;i++){
      |               ~^~~~~~~~~~~~~~~
#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...