Submission #730106

#TimeUsernameProblemLanguageResultExecution timeMemory
730106lucriConnecting Supertrees (IOI20_supertrees)C++17
21 / 100
211 ms22092 KiB
#include "supertrees.h" #include <vector> #include <cassert> #include <cstdio> #include <cstdlib> #include <string> int t[1010]; bool e[1010],dc[1010]; int tata(int nod) { if(t[nod]==nod) return nod; return t[nod]=tata(t[nod]); } int construct(std::vector<std::vector<int>> p) { int n = p.size(); std::vector<std::vector<int>> answer; answer.resize(n); for (int i = 0; i < n; i++) { t[i]=i; dc[i]=false; e[i]=true; answer[i].resize(n); } for(int i=0;i<n;++i) { for(int j=0;j<n;++j) if(p[i][j]==1) { if(tata(i)!=tata(j)) { answer[i][j]=answer[j][i]=1; t[t[i]]=t[j]; } } } for(int i=0;i<n;++i) { for(int j=0;j<n;++j) if(p[i][j]==0) { if(tata(i)==tata(j)) return 0; } } for(int i=0;i<n;++i) if(e[i]) for(int j=i+1;j<n;++j) { if(e[j]) if(tata(i)==tata(j)) { e[j]=false; for(int q=0;q<n;++q) if(p[i][q]!=p[j][q]) return 0; } } int ciclu[1010]; for(int i=0;i<n;++i) { if(e[i]==true&&dc[i]==false) { ciclu[0]=1; ciclu[1]=i; for(int j=0;j<n;++j) if(e[j]&&p[i][j]==2) { ciclu[++ciclu[0]]=j; if(dc[j]) return 0; } if(ciclu[0]>2) { for(int ii=1;ii<=ciclu[0];++ii) { dc[ii]=true; if(ii!=ciclu[0]) answer[ciclu[ii]][ciclu[ii+1]]=answer[ciclu[ii+1]][ciclu[ii]]=1; for(int jj=ii+1;jj<=ciclu[0];++jj) if(p[ciclu[ii]][ciclu[jj]]!=2) return 0; } answer[ciclu[ciclu[0]]][ciclu[1]]=answer[ciclu[1]][ciclu[ciclu[0]]]=1; } else if(ciclu[0]==2) return 0; } } build(answer); return 1; }
#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...