이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include"supertrees.h"
#pragma GCC optimize("O2")
#define S second
#define F first
#define PB push_back
#define sz(x) (int) x.size()
#define all(x) x.begin(),x.end()
#define L(x) 2*x
#define R(x) 2*x+1
#define M(x,y) (x+y)/2
using namespace std;
typedef long long ll;
const int N=1e3+1;
int p[N],lvl[N];
int getp(int x){
return (p[x]==x)? x : p[x]=getp(p[x]);
}
void unite(int i,int j){
int x=getp(i),y=getp(j);
if(x==y)
return ;
if(lvl[x]>lvl[y])
swap(x,y);
p[x]=y;
if(lvl[x]==lvl[y])
lvl[y]++;
}
/*
void build(vector<vector<int>> t){
for(auto v:t){
for(auto x:v)
cout<<x<<" ";
cout<<endl;
}
}
*/
int construct(vector<vector<int>> b){
int n=sz(b);
vector<vector<int>> ans(n,vector<int>(n,0));
for(int i=0;i<n;i++){
lvl[i]=0;
p[i]=i;
}
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
if(b[i][j] && i!=j)
unite(i,j);
vector<int> co[n];
for(int i=0;i<n;i++)
co[getp(i)].PB(i);
for(int i=0;i<n;i++){
if(sz(co[i])<=1)
continue;
for(int j=0;j<sz(co[i])-1;j++)
ans[co[i][j]][co[i][j+1]]=1,ans[co[i][j+1]][co[i][j]]=1;
for(auto x:co[i])
for(auto y:co[i]){
if(x==y)
continue;
if(b[x][y]==0)
return 0;
}
}
build(ans);
return 1;
}
/*
int main(){
int n;
cin>>n;
vector<vector<int>> t(n,vector<int>(n,0));
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
cin>>t[i][j];
construct(t);
}
*/
# | 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... |