Submission #789670

#TimeUsernameProblemLanguageResultExecution timeMemory
789670FEDIKUSConnecting Supertrees (IOI20_supertrees)C++17
100 / 100
153 ms24056 KiB
#include "supertrees.h" #include <vector> #include<map> #include<algorithm> using namespace std; const int maxn=1010; int dsu[maxn]; int dsu2[maxn]; int cale(int a,int *dsu){ return dsu[a]==a ? a:cale(dsu[a],dsu); } void join(int a,int b,int *dsu){ dsu[cale(a,dsu)]=cale(b,dsu); } int construct(vector<vector<int>> p) { int n = p.size(); vector<vector<int>> answer; for (int i = 0; i < n; i++) { vector<int> row; row.resize(n); answer.push_back(row); } for(int i=0;i<n;i++) dsu[i]=i; for(int i=0;i<n;i++) dsu2[i]=i; for(int i=0;i<n;i++){ for(int j=0;j<i;j++){ if(p[i][j]==1) join(i,j,dsu); if(p[i][j]==3) return 0; } } for(int i=0;i<n;i++){ if(i!=cale(i,dsu)){ answer[i][cale(i,dsu)]=1; answer[cale(i,dsu)][i]=1; } } for(int i=0;i<n;i++){ for(int j=0;j<i;j++){ if(p[i][j]==0) if(cale(i,dsu)==cale(j,dsu)) return 0; if(p[i][j]==2){ if(cale(i,dsu)==cale(j,dsu)) return 0; join(cale(i,dsu),cale(j,dsu),dsu2); } } } for(int i=0;i<n;i++){ for(int j=0;j<i;j++){ if(p[i][j]==0) if(cale(cale(i,dsu),dsu2)==cale(cale(j,dsu),dsu2)) return 0; } } map<int,vector<int> > kurac; for(int i=0;i<n;i++){ kurac[cale(cale(i,dsu),dsu2)].push_back(cale(i,dsu)); } for(auto i:kurac){ sort(i.second.begin(),i.second.end()); i.second.resize(unique(i.second.begin(),i.second.end())-i.second.begin()); int prev=i.second.back(); if(i.second.size()==2) return 0; for(int j:i.second){ if(prev==j) break; if(prev!=-1){ answer[prev][j]=1; answer[j][prev]=1; } prev=j; } } 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...