# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
812706 | KemalK | Connecting Supertrees (IOI20_supertrees) | C++17 | 172 ms | 24012 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;
const int N = 1e3 + 5;
int pr[N];
int sz[N];
int get(int x){
if (pr[x] == x){
return x;
}
return (pr[x] = get(pr[x]));
}
void unit(int a, int b){
a = get(a);
b = get(b);
if (a != b){
if (sz[a] < sz[b]){
swap(a, b);
}
pr[b] = a;
sz[a] += sz[b];
}
}
int construct(std::vector<std::vector<int>> p) {
int n = p.size();
for (int i = 0; i < n; i++){
pr[i] = i; sz[i] = 1;
}
int check = 0;
for (int i = 0; i < n; i++){
for (int j = 0; j < n; j++){
if (p[i][j]){
unit(i, j);
check = max(check, p[i][j]);
}
}
}
for (int i = 0; i < n; i++){
for (int j = 0; j < n; j++){
if (p[i][j] == 0 and get(i) == get(j)){ //impossible
return 0;
}
}
}
vector <vector<int>> answer(n, vector<int>(n));
if(!check){
build(answer);
return 1;
}
for (int i = 0; i < n; i++){
vector <int> branch;
for (int j = 0; j < n; j++){
if (get(j) == i){
branch.push_back(j);
}
}
for (int j = 0; j + 1 < branch.size(); j++){
answer[branch[j]][branch[j + 1]] = 1;
answer[branch[j + 1]][branch[j]] = 1;
}
if (check == 2){
if(branch.size() == 2){
return 0;
}
if (branch.size() > 2){
answer[branch[0]][branch.back()] = 1;
answer[branch.back()][branch[0]] = 1;
}
}
}
build(answer);
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... |