# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
431265 | MOUF_MAHMALAT | Connecting Supertrees (IOI20_supertrees) | C++14 | 1 ms | 204 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;
typedef int ll;
vector<vector<ll> >v,w;
vector<pair<ll,ll> >op;
ll n,p[1009];
bool b[1009];
ll gp(ll z)
{
if(p[z]==z)
return z;
return p[z]=gp(p[z]);
}
void mrg(ll x,ll y)
{
if(w[y].size()>w[x].size())
swap(x,y);
p[y]=x;
for(auto z:w[y])
w[x].push_back(z);
}
int construct(vector<vector<int> > pp)
{
n=pp.size();
v.resize(n);
w.resize(n);
for(ll i=0; i<n; i++)
v[i].resize(n);
for(ll i=0; i<n; i++)
p[i]=i,w[i].push_back(i);
for(ll i=0; i<n; i++)
for(ll j=0; j<n; j++)
{
if(i==j||pp[i][j]==0)
continue;
ll x=gp(i),y=gp(j);
if(x==y)
continue;
mrg(x,y);
}
for(ll i=0; i<n; i++)
{
if(p[i]!=i)
continue;
if(w[i].size()<=2)
return 0;
for(ll k=0; k<w[i].size(); k++)
op.push_back({w[i][k],w[i][(k+1)%w[i].size()]});
}
for(ll i=0; i<n; i++)
for(ll j=0; j<n; j++)
{
if(pp[i][j])
continue;
ll x=gp(i),y=gp(j);
if(x==y)
return 0;
}
for(auto z:op)
v[z.first][z.second]=v[z.second][z.first]=1;
build(v);
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... |