# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
309397 | pere_gil | Connecting Supertrees (IOI20_supertrees) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bits/stdc++.h"
#include "supertrees.h"
using namespace std;
int pos[1001];
void init(int n){
for(int i=0;i<n;i++) pos[i]=i;
}
int findset(int a){
if(pos[a]==a) return a;
else findset(pos[a]);
}
void unionset(int A, int B){
int a=findset(A);
int b=findset(B);
if(a!=b) pos[b]=a;
}
int construct(int p[][])
{
int n=(int)sqrt(sizeof(p)/4);
init(n);
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(p[i][j]==1) unionset(i,j);
}
}
vector<int> v[n];
for(int i=0;i<n;i++) v[findset(i)].push_back(i);
int res[n][n];
memset(res,0,sizeof(res));
for(int i=0;i<n;i++){
for(int j=0;j<v[i].size()-1;j++){
res[j][j+1]=1;
}
}
build(res[n][n]);
return 1;
return 0;
}