# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
576136 | Vanilla | Connecting Supertrees (IOI20_supertrees) | C++17 | 1 ms | 356 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>
#include "supertrees.h"
using namespace std;
const int maxn = 1002;
int dsu[maxn];
set <int> comp [maxn];
int get_dad (int x) {
return dsu[x] = (x == dsu[x] ? x: get_dad(dsu[x]));
}
void merge (int a, int b){
a = get_dad(a);
b = get_dad(b);
dsu[b] = a;
}
int construct(vector<vector<int>> p) {
int n = p.size();
vector <vector <int> > b (n, vector <int> (n));
for (int i = 0; i < n; i++){
dsu[i] = i;
comp[i].insert(i);
}
for (int i = 0; i < n; i++){
for (int j = 0; j < i; j++){
if (p[i][j] != 0) merge(i,j);
}
}
for (int i = 0; i < n; i++){
for (int j = 0; j < i; j++){
if (p[i][j] == 0 && get_dad(i) == get_dad(j)) return 0;
if (get_dad(i) == get_dad(j)) comp[get_dad(i)].insert(j);
}
}
for (int i = 0; i < n; i++){
vector <int> v;
if (comp[i].size() == 1) continue;;
for (int j: comp[i]) {
v.push_back(j);
}
for (int j = 0; j < v.size(); j++){
// cout << v[j] << " " << v[(j + 1) % v.size()] << "\n";
b[v[j]][v[(j + 1) % v.size()]] = b[v[(j + 1) % v.size()]][v[j]] = 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... |