Submission #1024219

#TimeUsernameProblemLanguageResultExecution timeMemory
1024219gaurezzzConnecting Supertrees (IOI20_supertrees)C++17
40 / 100
132 ms22300 KiB
#include <bits/stdc++.h> #include "supertrees.h" using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; int m; struct UF{ vi e; vi con; UF(int n){ e.assign(n,-1); con.assign(n,0);} int find(int x){ return (e[x] < 0 ? x : find(e[x])); } void _union(int a, int b){ int x = find(a); int y = find(b); if(x == y) return; if(e[x] > e[y]) swap(x,y); e[x] += e[y]; e[y] = x; } }; int construct(vvi p){ m = (int)p.size(); int ban=0; UF fu(m); vvi ans(m, vi(m,0)); vector<set<int>> coneect(m, set<int>()); vvi conect(m, vi()); for(int i=0; i<m; i++){ for(int j=i; j<m; j++){ if(i==j) continue; if(p[i][j]==1 && ban==0){ ban=1; } if(p[i][j]==2 && ban==0){ ban=2; } if(p[i][j]!=0){ fu._union(i, j); } } } for(int i=0; i<m; i++){ for(int j=i; j<m; j++){ if(p[i][j]==0){ if(fu.find(i)==fu.find(j)){ return 0; } }else{ int t = fu.find(i); int size=(int)coneect[t].size(); coneect[t].insert(i); if((int)coneect[t].size() > size) {conect[t].push_back(i); size++;} coneect[t].insert(j); if((int)coneect[t].size() > size) {conect[t].push_back(j); size++;} } } } for(int i=0; i<m; i++){ if(ban==2 && (int)conect[i].size()==2){ return 0; } if(ban==2 && (int)conect[i].size()==0){ continue; } for(int j=0; j<(int)conect[i].size()-1; j++){ ans[conect[i][j+1]][conect[i][j]]=1; ans[conect[i][j]][conect[i][j+1]]=1; } if(ban==2){ ans[conect[i][(int)conect[i].size()-1]][conect[i][0]]=1; ans[conect[i][0]][conect[i][(int)conect[i].size()-1]]=1; } } for(int i=0; i<m; i++){ ans[i][i]=0; } build(ans); 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...