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>
#define all(x) x.begin(),x.end()
#define sz(x) ll(x.size())
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;
const ll MAX=1e6;
int f[MAX];
int fiend(int u){
if(f[u] == u)return u;
return f[u]=fiend(f[u]);//
}
void unir(int u,int v){
int x=fiend(u);
int y=fiend(v);
if(x!=y){
f[x]=y;//metemos a x en y
}
return;
}
int construct(vector<vector<int>> p) {
int n = p.size();
for(int i=0; i<n; i++){
f[i]=i;
}
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
if(p[i][j]){
unir(i,j);
}
}
}
vector<vector<int>> gfo(n,vector<int>(n));
for(int i=0; i<n; i++){
fiend(f[i]);
fiend(i);
if(f[i]!=i){
gfo[i][f[i]]=1;
gfo[f[i]][i]=1;
}
}
//cout<<'\n';
/*for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
cout<<gfo[i][j]<<' ';
}
cout<<'\n';
}*/
//cout<<'\n';
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
if(!p[i][j] && i!=j){
if(f[i]==f[j]){
return 0;
}
}
}
}
build(gfo);
return 1;
}
/* con fe
5
0 1 1 1 0
1 0 1 1 0
1 1 0 1 0
1 1 1 0 0
0 0 0 0 0
*/
# | 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... |