# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
429328 | pere_gil | Connecting Supertrees (IOI20_supertrees) | C++14 | 1 ms | 204 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;
int p[1005];
void init(int n){
for(int i=0;i<n;i++) p[i]=i;
}
int find_set(int n){
return (p[n]==n) ? n : p[n]=find_set(p[n]);
}
bool same_set(int a, int b){
return find_set(a)==find_set(b);
}
void union_set(int a, int b){
if(!same_set(a,b)) p[find_set(a)]=find_set(b);
}
void form_group(vector<int> &g, vector<vector<int> > &v){
for(int i=0;i<g.size();i++){
int j=(i+1)%g.size();
v[i][j]=v[j][i]=1;
}
}
int construct(vector<vector<int> > v){
int n=v.size();
init(n);
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
if(v[i][j]) union_set(i,j);
vector<vector<int> > g(n);
for(int i=0;i<n;i++)
g[find_set(i)].push_back(i);
/*
printf("Groups are:\n");
for(int i=0;i<n;i++){
if(g[i].size()==0) continue;
printf("%d: ",i);
for(int j=0;j<g[i].size();j++) printf("%d ",g[i][j]);
printf("\n");
}
*/
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
if(same_set(i,j) && v[i][j]==0) return 0;
vector<vector<int> > ans(n,vector<int> (n,0));
for(int i=0;i<n;i++)
form_group(g[i],ans);
build(ans);
return 1;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |