# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
612899 | jairRS | Connecting Supertrees (IOI20_supertrees) | C++17 | 1 ms | 340 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;
using vi = vector<int>;
using vvi = vector<vi>;
struct DSU{
vi p, s;
DSU(int size){
p = s = vi(size + 1, 1);
for(int i = 0; i <= size; i++)
p[i] = i;
}
int find(int x){
if(p[x] == x)
return x;
return p[x] = find(p[x]);
}
void unite(int a, int b){
a = find(a);
b = find(b);
if(a == b)
return;
if(s[a] > s[b])
swap(a, b);
s[b] += s[a];
p[a] = b;
}
};
int construct(vvi p) {
int n = p.size();
vvi answer = vvi(n, vi(n, 0));
DSU dsu(n);
for (int i = 0; i < n; i++)
for (int j = i + 1; j < n; j++)
if(p[i][j] == 2)
dsu.unite(i, j);
vvi group(n, vi());
for (int i = 0; i < n; i++)
group[dsu.find(i)].push_back(i);
for (int i = 0; i < n; i++)
for (int j = i + 1; j < n; j++)
if(dsu.find(i) == dsu.find(j) && p[i][j] == 0)
return 0;
for(vi & g : group){
if(g.size() == 1)
continue;
if(g.size() == 2)
return 0;
for (int i = 0; i + 1 < g.size(); i++)
{
answer[g[i]][g[i + 1]] = 1;
answer[g[i + 1]][g[i]] = 1;
}
answer[g.back()][g[0]] = 1;
answer[g[0]][g.back()] = 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... |