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 <vector>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
typedef pair<ll,ll> pii;
const ll MAXN = 2e5+5;
int parent[MAXN],sizee[MAXN];
int find(ll x){
if(x==parent[x])return x;
return parent[x]=find(parent[x]);
}
void unite(ll a, ll b){
a = find(a);
b = find(b);
if(a==b)return;
if(sizee[a]<sizee[b])swap(a,b);
sizee[a]+=sizee[b];
parent[b]=a;
}
int construct(std::vector<std::vector<int>> p) {
int n = p.size(),i,j,k,a;
std::vector<std::vector<int>> answer;
for (i = 0; i < n; i++) {
std::vector<int> row;
row.resize(n);
answer.push_back(row);
}
for(i=0;i<n;i++){
parent[i]=i;
sizee[i]=1;
}
for(i=0;i<n;i++){
for(j=i+1;j<n;j++){
if(p[i][j]==0)continue;
unite(i,j);
}
}
vector<vector<int>>meh(n);
for(i=0;i<n;i++){
k=find(i);
meh[k].pb(i);
}//meh[i] e set da componente de i
for(i=0;i<n;i++){
if(i!=find(i))continue;
k = meh[i].size();
for(j=1;j<k;j++){
answer[ meh[i][j] ][ meh[i][j-1] ]=1;
answer[ meh[i][j-1] ][ meh[i][j] ]=1;
for(a=0;a<k;a++){
if(p[meh[i][j]][meh[i][a]]==1)return 0;
}
}
}
build(answer);
return 1;
}
# | 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... |