Submission #384930

#TimeUsernameProblemLanguageResultExecution timeMemory
384930Ahmadsm2005Connecting Supertrees (IOI20_supertrees)C++14
100 / 100
265 ms30572 KiB
#include <bits/stdc++.h> #include "supertrees.h" using namespace std; int N,edges[1001][1001],GRP[1001],Z,FAIL,GRP2[1001],Z2; vector<vector<int>>ALL; vector<vector<int>>P; void CONNECT2(vector<int>X){ for(int i=1;i<X.size();i++){ edges[X[i]][X[i-1]]=1,edges[X[i-1]][X[i]]=1; } } void CONNECT(vector<int>X){ vector<vector<int>>CYCLE; for(int i=0;i<X.size();i++){ vector<int>TEMP; if(GRP2[X[i]]+1) continue; TEMP.push_back(X[i]); GRP2[X[i]]=Z2; for(int l=0;l<N;l++){ if(P[X[i]][l]==1&&X[i]!=l){ if(GRP2[l]+1){ FAIL=1; return; } TEMP.push_back(l),GRP2[l]=Z2; } } for(int l=0;l<TEMP.size();l++){ int CNT=0; for(int x=0;x<TEMP.size();x++){ if(l!=x&&(P[TEMP[l]][TEMP[x]]!=1)){ FAIL=1; return; } } for(int x=0;x<N;x++) if(P[TEMP[l]][x]==1) CNT++; if(CNT!=TEMP.size()){ FAIL=1; return; } } CYCLE.push_back(TEMP); Z2++; } if(CYCLE.size()==2){ FAIL=1; return; } for(int i=1;i<CYCLE.size();i++) edges[CYCLE[i][0]][CYCLE[i-1][0]]=1,edges[CYCLE[i-1][0]][CYCLE[i][0]]=1; if(CYCLE.size()>2) edges[CYCLE.back()[0]][CYCLE[0][0]]=1,edges[CYCLE[0][0]][CYCLE.back()[0]]=1; for(int i=0;i<CYCLE.size();i++) CONNECT2(CYCLE[i]); } int construct(std::vector<std::vector<int>>p){ N=p.size(); P=p; for(int i=0;i<N;i++) for(int l=0;l<N;l++) if(p[i][l]==3) return 0; for(int i=0;i<1001;i++) GRP[i]=-1,GRP2[i]=-1; for(int i=0;i<N;i++){ vector<int>TEMP; if(GRP[i]+1) continue; TEMP.push_back(i); GRP[i]=Z; for(int l=0;l<N;l++){ if(p[i][l]&&i!=l){ if(GRP[l]+1) return 0; TEMP.push_back(l),GRP[l]=Z; } } for(int l=0;l<TEMP.size();l++){ int CNT=0; for(int x=0;x<TEMP.size();x++){ if(l!=x&&(!p[TEMP[l]][TEMP[x]])) return 0; } for(int x=0;x<N;x++) if(p[TEMP[l]][x]) CNT++; if(CNT!=TEMP.size()) return 0; } ALL.push_back(TEMP); Z++; } for(int i=0;i<ALL.size();i++) CONNECT(ALL[i]); vector<vector<int>>ANS; for(int i=0;i<N;i++){ vector<int>FF; for(int l=0;l<N;l++) FF.push_back(edges[i][l]); ANS.push_back(FF); } if(FAIL) return 0; build(ANS); return 1; }

Compilation message (stderr)

supertrees.cpp: In function 'void CONNECT2(std::vector<int>)':
supertrees.cpp:8:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 | for(int i=1;i<X.size();i++){
      |             ~^~~~~~~~~
supertrees.cpp: In function 'void CONNECT(std::vector<int>)':
supertrees.cpp:14:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 | for(int i=0;i<X.size();i++){
      |             ~^~~~~~~~~
supertrees.cpp:29:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 | for(int l=0;l<TEMP.size();l++){
      |             ~^~~~~~~~~~~~
supertrees.cpp:31:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 | for(int x=0;x<TEMP.size();x++){
      |             ~^~~~~~~~~~~~
supertrees.cpp:40:7: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 | if(CNT!=TEMP.size()){
      |    ~~~^~~~~~~~~~~~~
supertrees.cpp:52:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 | for(int i=1;i<CYCLE.size();i++)
      |             ~^~~~~~~~~~~~~
supertrees.cpp:56:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 | for(int i=0;i<CYCLE.size();i++)
      |             ~^~~~~~~~~~~~~
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:81:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 | for(int l=0;l<TEMP.size();l++){
      |             ~^~~~~~~~~~~~
supertrees.cpp:83:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 | for(int x=0;x<TEMP.size();x++){
      |             ~^~~~~~~~~~~~
supertrees.cpp:90:7: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   90 | if(CNT!=TEMP.size())
      |    ~~~^~~~~~~~~~~~~
supertrees.cpp:96:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   96 | for(int i=0;i<ALL.size();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...