# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
621153 | Mr_Husanboy | Connecting Supertrees (IOI20_supertrees) | C++14 | 192 ms | 24132 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 "supertrees.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
struct DSU{
vector<int> parent, sz;
void init(int n){
parent.resize(n), sz.resize(n);
for(int i = 0; i < n; i ++) parent[i] = i, sz[i] = 1;
}
int get(int a){
return parent[a] == a ? a : parent[a] = get(parent[a]);
}
void unite(int a, int b){
a = get(a); b = get(b);
if(a==b) return;
if(sz[a] < sz[b]) swap(a,b);
sz[a] += sz[b];
parent[b] = a;
}
};
int construct(vector<vector<int>> p) {
int n = p.size();
vector<vector<int>> b(n,vector<int> (n));
DSU t; t.init(n);
for(int j = 0; j < n; j ++){
for(int i = 0; i < n; i ++){
if(p[i][j]) t.unite(i,j);
}
}
for(int i = 0; i < n; i ++){
for(int j = 0; j < n; j ++){
if(p[i][j] == 0 && t.get(i) == t.get(j)) return 0;
}
}
vector<vector<int>> par(n);
for(int i = 0; i < n; i ++){
par[t.get(i)].push_back(i);
}
for(int i = 0; i < n; i ++){
for(int j = 1; j < par[i].size(); j ++){
int u = par[i][j], v = par[i][j-1];
b[u][v] = b[v][u] = 1;
}
}
build(b);
return 1;
}
Compilation message (stderr)
# | 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... |