# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
576201 | 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;
vector <int> ad1[maxn];
vector <int> ad2[maxn];
int d[maxn];
vector <int> comp;
bitset <maxn> vis;
bitset <maxn> vis1;
bitset <maxn> in;
int get_dad (int x) {
return d[x] = (x == d[x] ? x: get_dad(d[x]));
}
void merge (int a, int b){
a = get_dad(a);
b = get_dad(b);
d[a] = b;
}
void dfs (int u) {
vis[u] = 1;
if (!in[u]) comp.push_back(u);
for (int v: ad2[u]) {
if (!vis[v]) {
// merge(u, v);
dfs(v);
}
}
}
void dfs1 (int u) {
vis1[u] = 1;
for (int v: ad1[u]) {
if (!vis1[v]) {
// b[get_dad(u)][v] = b[v][get_dad(u)] = 1;
in[get_dad(u)] = in[v] = 1;
merge(v, u);
dfs1(v);
}
}
}
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 = 0; j < i; j++){
if (p[i][j] == 2){
ad2[i].push_back(j);
ad2[j].push_back(i);
}
else if (p[i][j] == 1) {
ad1[i].push_back(j);
ad1[j].push_back(i);
}
}
}
for (int i = 0; i < n; i++){
for (int j = i + 1; j < n; j++){
if (p[i][j] == 1) {
b[i][j] = b[j][i] = 1;
merge(i,j);
}
}
}
for (int i = 0; i < n; i++){
comp.clear();
comp.push_back(i);
for (int j = i + 1; j < n; j++){
if (get_dad(i) != get_dad(j) && p[get_dad(i)][get_dad(j)] == 2) {
comp.push_back(j);
merge(i, j);
}
}
if (comp.size() < 2) continue;
for (int l = 0; l < comp.size(); l++){
int p1 = comp[l];
int p2 = comp[(l + 1) % comp.size()];
b[p1][p2] = b[p2][p1] = 1;
}
}
// for (int i = 0; i < n; i++){
// if (!vis[i]) {
// comp.clear();
// dfs(i);
// if (comp.size() > 1)
// for (int k = 0; k < comp.size(); k++){
// // if (!vis1[comp[k]] != 1)
// b[comp[k]][comp[(k + 1) % comp.size()]] = b[comp[(k + 1) % comp.size()]][comp[k]] = 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... |