# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
576694 | Vanilla | Connecting Supertrees (IOI20_supertrees) | C++17 | 193 ms | 23968 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 d[maxn];
int dad (int x) {
return d[x] = (x == d[x] ? x: dad(d[x]));
}
void merge (int a, int b){
a = dad(a);
b = dad(b);
d[b] = a;
}
int construct(vector<vector<int>> p) {
int n = p.size();
vector <vector <int> > b (n, vector <int> (n, 0));
for (int i = 0; i < n; i++){
d[i] = i;
}
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 && dad(i) != dad(j)) {
b[i][j] = b[j][i] = 1;
merge(i,j);
}
}
}
for (int i = 0; i < n; i++){
vector <int> v;
v.push_back(dad(i));
for (int j = i + 1; j < n; j++){
if (p[i][j] == 2 && dad(i) != dad(j)) {
v.push_back(dad(j));
merge(i, j);
}
}
if (v.size() == 2) return 0;
if (v.size() > 1)
for (int i = 0; i < v.size(); i++){
int p1 = v[i], p2 = v[(i + 1) % v.size()];
b[p1][p2] = b[p2][p1] = 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... |