Submission #470336

#TimeUsernameProblemLanguageResultExecution timeMemory
470336jazzupConnecting Supertrees (IOI20_supertrees)C++14
Compilation error
0 ms0 KiB
#include"supertrees.h" #include<vector> 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]; int construct(vector<vector<int> > p) { for(int i=0;i<=n;i++){ par[i]=i; } int n = p.size(); vector<vector<int> > answer; for (int i = 0; i < n; i++) { vector<int> row; row.resize(n); answer.push_back(row); } for(int i=0;i<n;i++){ 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]==3)return 0; if(p[i][j]==1){ par[j]=findPar(i); answer[j][par[j]]=1; answer[par[j]][j]=1; } } } for(int i=0;i<n-1;i++){ for(int j=i+1;j<n;j++){ if(p[i][j]==2){ if(findPar(i)==findPar(j)){ return 0; } c[findPar(i)]=true; c[findPar(j)]=true; } } } for(int i=0;i<n;i++){ if(c[i])heads.push_back(i); } 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; build(answer); return 1; }

Compilation message (stderr)

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:18:17: error: 'n' was not declared in this scope
   18 |  for(int i=0;i<=n;i++){
      |                 ^
supertrees.cpp:64:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |  for(int i=0;i<heads.size()-1;i++){
      |              ~^~~~~~~~~~~~~~~