# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
798940 | QwertyPi | 슈퍼트리 잇기 (IOI20_supertrees) | C++14 | 182 ms | 24232 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 <bits/stdc++.h>
using namespace std;
struct DSU{
int dsu[1001];
void init(int n){
for(int i = 0; i < n; i++){
dsu[i] = i;
}
}
int f(int x){
return x == dsu[x] ? x : dsu[x] = f(dsu[x]);
}
void g(int x, int y){
x = f(x), y = f(y);
dsu[x] = y;
}
} dsu0, dsu1;
int construct(std::vector<std::vector<int>> p) {
int n = p.size();
dsu0.init(n), dsu1.init(n);
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
if(p[i][j] == 3) return false;
}
}
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
if(p[i][j] >= 1) dsu0.g(i, j);
if(p[i][j] == 1) dsu1.g(i, j);
}
}
std::vector<std::vector<int>> answer;
for (int i = 0; i < n; i++) {
std::vector<int> row;
row.resize(n);
answer.push_back(row);
}
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
if(p[i][j] == 0 && dsu0.f(i) == dsu0.f(j)){
return false;
}
if(p[i][j] == 2 && dsu1.f(i) == dsu1.f(j)){
return false;
}
}
}
map<int, vector<int>> p1, p2;
for(int i = 0; i < n; i++){
p1[dsu1.f(i)].push_back(i);
}
for(auto [i, v] : p1){
for(int j = 1; j < v.size(); j++){
answer[v[0]][v[j]] = answer[v[j]][v[0]] = 1;
}
p2[dsu0.f(v[0])].push_back(v[0]);
}
for(auto [i, v] : p2){
if(v.size() == 1) continue;
if(v.size() == 2) return false;
for(int j = 1; j < v.size(); j++){
answer[v[j - 1]][v[j]] = answer[v[j]][v[j - 1]] = 1;
}
answer[v[0]][v[v.size() - 1]] = answer[v[v.size() - 1]][v[0]] = 1;
}
build(answer);
return true;
}
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... |