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<bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define pb push_back
#define SZ(x) ((int) (x).size())
using namespace std;
void build(vector<vector<int>> _b);
const int MAXN = 1e3+100;
int p[MAXN], sz[MAXN];
void init(int n){
iota(p, p+n, 0);
fill(sz, sz+n, 1);
}
int find_parent(int x){
if(x == p[x])
return x;
return p[x] = find_parent(p[x]);
}
bool same_set(int a, int b){
return (find_parent(a) == find_parent(b));
}
void union_set(int a, int b){
a = find_parent(a);
b = find_parent(b);
if(a == b)
return;
if(sz[a] < sz[b])
swap(a, b);
p[b] = a;
sz[a] += sz[b];
}
int construct(vector<vector<int>> p){
int N = SZ(p);
init(N);
for(int i = 0; i < N; i++){
for(int j = 0; j < N; j++){
if(p[i][j] > 0){
union_set(i, j);
}
}
}
vector<vector<int>> ans(N, vector<int>(N, 0));
vector<bool> vis(N, false);
for(int i = 0; i < N; i++){
int v = find_parent(i);
if(!vis[v]){
vis[v] = true;
vector<int> vertici;
vertici.pb(i);
for(int j = i+1; j < N; j++){
if(same_set(i, j)){
vertici.pb(j);
}
}
for(int j = 1; j < SZ(vertici); j++){
ans[vertici[j-1]][vertici[j]] = 1;
ans[vertici[j]][vertici[j-1]] = 1;
}
for(int j = 0; j < SZ(vertici); j++){
for(int k = 0; k < SZ(vertici); k++){
if(p[vertici[j]][vertici[k]] == 0)
return 0;
}
}
}
}
build(ans);
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... |