Submission #310372

#TimeUsernameProblemLanguageResultExecution timeMemory
310372APROHACKConnecting Supertrees (IOI20_supertrees)C++14
21 / 100
270 ms23544 KiB
#include "supertrees.h" #include <bits/stdc++.h> using namespace std; long long padres[1001]; vector<int>conjuntos[1001]; long long fnd(long long nodo){ if(padres[nodo]==nodo)return nodo; return padres[nodo]=fnd(padres[nodo]); } int construct(vector<vector<int> >p) { bool haydos=false, hayuno=false; int n = p.size(); vector<vector<int> > answer; for (int i = 0; i < n; i++) { std::vector<int> row; row.resize(n); for(int j = 0 ; j < n ; j ++){ if(p[i][j]==2)haydos=true; if(p[i][j]==1)hayuno=true; row[j]=0; } answer.push_back(row); padres[i]= i; conjuntos[i].push_back(i); } if(!haydos){ for(int i = 0 ; i < n-1 ; i ++){ for(int j= i +1 ; j < n ; j ++){ if(p[i][j]==1){ padres[fnd(i)]=fnd(j); } } } for(int i = 0 ; i < n-1 ; i ++){ for(int j= i +1 ; j < n ; j ++){ if(p[i][j]==0){ if(fnd(i)==fnd(j))return 0; } } } for(int i = 0 ; i < n ; i ++){ if(fnd(i)==i)continue; else { answer[padres[i]][i]=1; answer[i][padres[i]]=1; } } }else if(!hayuno){ for(int i = 0 ; i < n-1 ; i ++){ for(int j= i +1 ; j < n ; j ++){ if(p[i][j]==2){ if(fnd(i)==fnd(j))continue; for(int p = 0 ; p < conjuntos[fnd(i)].size() ; p ++){ conjuntos[fnd(j)].push_back(conjuntos[fnd(i)][p]); } conjuntos[fnd(i)].clear(); padres[fnd(i)]=fnd(j); } } } for(int i = 0 ; i < n-1 ; i ++){ for(int j= i +1 ; j < n ; j ++){ if(p[i][j]==0){ if(fnd(i)==fnd(j))return 0; } } } for(int i = 0 ; i < n ; i ++){ if(conjuntos[i].size()<=1)continue; if(conjuntos[i].size()==2)return 0; for(int j = 0 ; j < conjuntos[i].size(); j ++){ if(j==0){ answer[conjuntos[i][conjuntos[i].size()-1]][conjuntos[i][0]]=1; answer[conjuntos[i][0]][conjuntos[i][conjuntos[i].size()-1]]=1; }else{ answer[conjuntos[i][j]][conjuntos[i][j-1]]=1; answer[conjuntos[i][j-1]][conjuntos[i][j]]=1; } } } }else{ for(int i = 0 ; i < n-1 ; i ++){ for(int j= i +1 ; j < n ; j ++){ if(p[i][j]==2){ if(fnd(i)==fnd(j))continue; for(int p = 0 ; p < conjuntos[fnd(i)].size() ; p ++){ conjuntos[fnd(j)].push_back(conjuntos[fnd(i)][p]); } conjuntos[fnd(i)].clear(); padres[fnd(i)]=fnd(j); } } } for(int i = 0 ; i < n ; i ++){ if(conjuntos[i].size()<=1)continue; //if(conjuntos[i].size()==2)return 0; for(int j = 0 ; j < conjuntos[i].size(); j ++){ if(j==0){ answer[conjuntos[i][conjuntos[i].size()-1]][conjuntos[i][0]]=1; answer[conjuntos[i][0]][conjuntos[i][conjuntos[i].size()-1]]=1; }else{ answer[conjuntos[i][j]][conjuntos[i][j-1]]=1; answer[conjuntos[i][j-1]][conjuntos[i][j]]=1; } } } for(int i = 0 ; i < n-1 ; i ++){ for(int j= i +1 ; j < n ; j ++){ if(p[i][j]==1&&fnd(i)!=fnd(j)){ answer[fnd(i)][fnd(j)]=1; answer[fnd(j)][fnd(i)]=1; padres[fnd(i)]=fnd(j); } } } } build(answer); return 1; }

Compilation message (stderr)

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:53:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |                     for(int p = 0 ; p < conjuntos[fnd(i)].size() ; p ++){
      |                                     ~~^~~~~~~~~~~~~~~~~~~~~~~~~~
supertrees.cpp:71:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |             for(int j = 0 ; j < conjuntos[i].size(); j ++){
      |                             ~~^~~~~~~~~~~~~~~~~~~~~
supertrees.cpp:89:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |                     for(int p = 0 ; p < conjuntos[fnd(i)].size() ; p ++){
      |                                     ~~^~~~~~~~~~~~~~~~~~~~~~~~~~
supertrees.cpp:101:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  101 |             for(int j = 0 ; j < conjuntos[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...