# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1051386 | LittleOrange | Connecting Supertrees (IOI20_supertrees) | C++17 | 96 ms | 22152 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;
using ll = int;
struct dsu{
ll n;
vector<ll> p;
dsu(ll N):n(N),p(N,-1){}
ll g(ll i){
return p[i]<0?i:p[i]=g(p[i]);
}
bool e(ll a, ll b){
return g(a)==g(b);
}
bool m(ll a, ll b){
a = g(a);
b = g(b);
if(a==b) return false;
if (p[a]>p[b]) swap(a,b);
p[a] += p[b];
p[b] = a;
return true;
}
};
int construct(std::vector<std::vector<int>> p) {
int n = p.size();
vector<vector<ll>> ans(n,vector<ll>(n,0));
dsu d(n);
for(ll i = 0;i<n;i++) for(ll j = 0;j<n;j++){
if (p[i][j]) d.m(i,j);
}
for(ll i = 0;i<n;i++) for(ll j = 0;j<n;j++){
if (!p[i][j]&&d.e(i,j)) return 0;
}
vector<ll> g;
for(ll i = 0;i<n;i++) if(d.g(i)==i) g.push_back(i);
ll gc = g.size();
vector<vector<ll>> gs(gc);
for(ll i = 0;i<n;i++) gs[d.g(i)].push_back(i);
for(auto &o : gs) if(o.size()>1){
ll ty = p[o[0]][o[1]];
for(ll i = 1;i<o.size();i++) ans[o[i-1]][o[i]] = ans[o[i]][o[i-1]] = 1;
if (ty == 2){
ans[o.front()][o.back()] = ans[o.back()][o.front()] = 1;
}
}
build(ans);
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... |