이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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();
if(k==2)return 0;
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]]==0)return 0;
}
}
if(k!=1){
answer[ meh[i][k-1] ][ meh[i][0] ]=1;
answer[ meh[i][0] ][ meh[i][k-1] ]=1;}
for(a=0;a<k;a++){
if(p[meh[i][0]][meh[i][a]]==0)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... |