# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
701974 | PenguinsAreCute | Connecting Supertrees (IOI20_supertrees) | C++17 | 197 ms | 24064 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;
int par[1005];
int find_set(int x) {
if(par[x] == x) return x;
return par[x] = find_set(par[x]);
}
bool same_set(int x, int y) {
return find_set(x) == find_set(y);
}
void merge_set(int x, int y) {
par[find_set(x)] = find_set(y);
}
int construct(vector<vector<int>> p) {
for(int i = 0; i < 1005; i++) par[i] = i;
int n = p.size();
vector<vector<int>> answer;
for(int i = 0; i < n; i++) {
vector<int> row;
for(int j = 0; j < n; j++) row.push_back(0);
answer.push_back(row);
}
for (int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
if(p[i][j] == 3) return 0;
if(p[i][j] != 0 && !same_set(i, j)) merge_set(i, j);
}
}
for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) if(i != j && same_set(i, j) != (bool)p[i][j]) return 0;
for(int i = 0; i < n; i++) {
vector<int> v, c;
for(int j = 0; j < n; j++) if(find_set(j) == i) v.push_back(j);
if(v.size() == 2 && p[v[0]][v[1]] == 2) return 0;
if(v.size() != 0) {
int s = v.size();
for(int j = 0; j < s; j++) {
bool inC = true;
for(int k = 0; k < j; k++) if(p[v[j]][v[k]] == 1) {
answer[v[j]][v[k]] = 1;
answer[v[k]][v[j]] = 1;
inC = false; break;
}
if(inC) c.push_back(v[j]);
}
for(int i = 0; i < c.size() - 1; i++) {
answer[c[i]][c[i + 1]] = 1;
answer[c[i + 1]][c[i]] = 1;
}
if(c.size() > 1) {
answer[c[0]][c[c.size() - 1]] = 1;
answer[c[c.size() - 1]][c[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... |