Submission #651891

#TimeUsernameProblemLanguageResultExecution timeMemory
651891coding_snorlaxConnecting Supertrees (IOI20_supertrees)C++14
0 / 100
1 ms212 KiB
#include "supertrees.h" #include<bits/stdc++.h> using namespace std; int Boss[1005]; int Rank[1005]; int query(int x){ if(Boss[x]==x) return x; else return Boss[x]=query(Boss[x]); } int Union(int x,int y){ int A1=query(x); int A2=query(y); if(A1==A2){ return 0; } if (Rank[A1]>Rank[A2]) Boss[A2]=A1; else if(Rank[A1]<Rank[A2]) Boss[A1]=A2; else{ Boss[A2]=A1; Rank[A1]++; } return 1; } int construct(vector<vector<int>> x){ for(int i=0;i<1005;i++){ Boss[i]=i; Rank[i]=0; } vector<vector<int>> built; for(int i=0;i<x.size();i++){ vector<int> New; for(int j=0;j<x.size();j++){ New.push_back(0); } built.push_back(New); } int check=0; for(int i=0;i<x.size();i++){ for(int j=0;j<x.size();j++){ if (x[i][j]){ check=Union(i,j); /* if(check && i!=j){ built[i][j]=1; built[j][i]=1; */ } } } int OK_List[1000]={1}; int answer=1; for(int i=0;i<x.size();i++){ int now_check=Boss[i]; vector<int> List1={i}; if(OK_List[i]){ OK_List[i]=0; for(int j=0;j<x.size();j++){ if(i!=j && now_check==Boss[j]){ List1.push_back(j); OK_List[j]=0; } } } List1.push_back(i); if(List1.size()>3){ for(int k=0;k<List1.size()-1;k++){ built[List1[k]][List1[k+1]]=1; built[List1[k+1]][List1[k]]=1; } } else{ if(List1.size()==1||List1.size()==2) answer=0; } } for(int i=0;i<x.size();i++){ for(int j=i+1;j<x.size();j++){ if ((x[i][j] && query(i)!=query(j)) || (!x[i][j] && query(i)==query(j))){ answer=0; } } } if(answer) build(built); return answer; }

Compilation message (stderr)

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:30:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     for(int i=0;i<x.size();i++){
      |                 ~^~~~~~~~~
supertrees.cpp:32:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |         for(int j=0;j<x.size();j++){
      |                     ~^~~~~~~~~
supertrees.cpp:38:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |     for(int i=0;i<x.size();i++){
      |                 ~^~~~~~~~~
supertrees.cpp:39:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |         for(int j=0;j<x.size();j++){
      |                     ~^~~~~~~~~
supertrees.cpp:53:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |     for(int i=0;i<x.size();i++){
      |                 ~^~~~~~~~~
supertrees.cpp:58:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |             for(int j=0;j<x.size();j++){
      |                         ~^~~~~~~~~
supertrees.cpp:67:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |         for(int k=0;k<List1.size()-1;k++){
      |                     ~^~~~~~~~~~~~~~~
supertrees.cpp:76:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |     for(int i=0;i<x.size();i++){
      |                 ~^~~~~~~~~
supertrees.cpp:77:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |         for(int j=i+1;j<x.size();j++){
      |                       ~^~~~~~~~~
supertrees.cpp:37:9: warning: variable 'check' set but not used [-Wunused-but-set-variable]
   37 |     int check=0;
      |         ^~~~~
#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...