Submission #1108742

#TimeUsernameProblemLanguageResultExecution timeMemory
1108742SteveBroConnecting Supertrees (IOI20_supertrees)C++17
100 / 100
182 ms24144 KiB
#include <bits/stdc++.h> #include "supertrees.h" using namespace std; vector <vector<int>> sol; int sef[1001]; int ef(int x) { if(sef[x]==x) return x; else return sef[x]=ef(sef[x]); } vector <int> comp[1001],rez,l; bool ok[1001]; int construct(vector <vector <int>> p) { int i,j,nr,n; n=p.size(); for(i=0;i<n;i++) sef[i]=i; l.resize(n); for(i=0;i<n;i++) sol.push_back(l); for(i=0;i<n;i++) { for(j=0,nr=0;j<n;j++) { if(p[i][j]==3) return 0; if(p[i][j]==0&&ef(i)==ef(j)) return 0; if(p[i][j]>0) sef[ef(i)]=ef(j); if(p[i][j]==2) nr++; if(p[i][j]==1&&i!=j) ok[i]=true; } if(nr==1) return 0; } for(i=0;i<n;i++) comp[ef(i)].push_back(i); for(i=0;i<n;i++) sef[i]=-1; for(i=0;i<n;i++) { if(!comp[i].empty()) { rez.clear(); for(auto x : comp[i]) { if(!ok[x])/// se alfa pe ciclu rez.push_back(x); else { if(sef[x]==-1)///nou lant { rez.push_back(x); sef[x]=x; for(j=0;j<n;j++) { if(p[x][j]==1&&x!=j) { if(sef[j]==-1) { sef[j]=x; sol[x][j]=sol[j][x]=1; } else return 0; } } } else { for(j=0;j<n;j++) { if(p[x][j]==2&&sef[x]==sef[j]) return 0; if(p[x][j]==1&&sef[x]!=sef[j]) return 0; } } } } if(rez.size()>2) { for(j=1;j<rez.size();j++) { sol[rez[j-1]][rez[j]]=sol[rez[j]][rez[j-1]]=1; } sol[rez[0]][rez[j-1]]=sol[rez[j-1]][rez[0]]=1; } } } build(sol); return 1; }

Compilation message (stderr)

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:89:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |                 for(j=1;j<rez.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...