# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
305694 | a_player | 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 "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
const int nax=1e3+3;
int alt[nax];
int link[nax];
int find(int a){
if(link[a]==a)return a;
return link[a]=find(link[a]);
}
void unite(int a,int b){
int x=find(a);
int y=find(b);
if(x==y)return;
if(alt[x]>alt[y])link[y]=x;
else{
link[x]=y;
if(alt[x]==alt[y])alt[y]++;
}
}
bool same(int a, int b){
return find(a)==find(b);
}
int construct(std::vector<std::vector<int>> p){
int n=p.size();
vector<vector<int>> b(n,vector<int>(n));
for(int i=0;i<n;i++)
for(int j=i+1;j<n;j++){
if(p[i][j]==0&&same(i,j))return 0;#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
const int nax=1e3+3;
int alt[nax];
int link[nax];
int find(int a){
if(link[a]==a)return a;
return link[a]=find(link[a]);
}
void unite(int a,int b){
int x=find(a);
int y=find(b);
if(x==y)return;
if(alt[x]>alt[y])link[y]=x;
else{
link[x]=y;
if(alt[x]==alt[y])alt[y]++;
}
}
bool same(int a, int b){
return find(a)==find(b);
}
int construct(std::vector<std::vector<int>> p){
int n=p.size();
vector<vector<int>> b(n,vector<int>(n));
for(int i=0;i<n;i++)
for(int j=i+1;j<n;j++){
if(p[i][j]==1&&!same(i,j)){
unite(i,j);
b[i][j]=1;
b[j][i]=1;
}
}
for(int i=0;i<n;i++)
for(int j=i+1;j<n;j++)if(same(i,j)&&p[i][j]==0)return 0;
build(b);
return 1;
}