# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
953783 | Trisanu_Das | Connecting Supertrees (IOI20_supertrees) | C++17 | 0 ms | 0 KiB |
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>
using namespace std;
int n, par[1005], ls[1005];
vector<vector<int> > b;
int find(int u){
if(par[u] == u) return u;
par[u] = find(par[u]);
return par[u];
}
void union_(int u, int v){
u = find(u); v = find(v);
if(u == v) return;
par[u] = v;
b[u][ls[v]] = b[ls[v]][u] = 1;
ls[v] = ls[u];
}
int construct(vector<vector<int> > p){
n = p.size();
b.assign(n, vector<int>(n, 0));
iota(par, par + n, 0); iota(ls, ls + n, 0);
for(int i = 0; i < n; i++) {
for(int j = i + 1; j < n; j++) {
if(p[i][j] == 3) return 0;
if(p[i][j] == 1) union_(i, j);
}
}
for(int i = 0; i < n; i++) for(int j = i + 1; j < n; j++) if(p[i][j] != 1 && find(i) == find(j)) return 0;
iota(ls, ls + n, 0);
for(int i = 0; i < n; i++) for(int j = i + 1; j < n; j++) if(p[i][j] == 2) union_(i, j);
for(int i = 0; i < n; i++){
if(par[i] == i && ls[i] != i){
if(b[ls[i]][i] == 1) return 0;
b[ls[i]][i] = b[i][ls[i]] = 1;
}
}
for(int i = 0; i < n; i++) for(int j = i + 1; j < n; j++) if(find(i) == find(j) && p[i][j] == 0) return 0;
build(b);
return 1;
}