# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
431125 | Rouge_Hugo | Connecting Supertrees (IOI20_supertrees) | C++14 | 262 ms | 28052 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"
#include <vector>
#define fi first
#define se second
#define pb push_back
using namespace std;
int n;const int N=1009;
vector<vector<int>>ans;
int pa[N],sz[N],p[N][N],vis[N];
vector<int>v[N];vector<int>sta;
vector<int>u;
void merge(int x,int y)
{
x=pa[x];y=pa[y];
if(x==y)return;
if(sz[x]<sz[y])swap(x,y);
for(auto it:v[y])
{
sz[x]++;
v[x].pb(it);
pa[it]=x;
}
}
void go(int x)
{
sta.clear();int last=x;
for(auto it:v[x])sta.pb(it);
for(int i=x+1;i<u.size();i++)
{
if(vis[i])continue;
int r=1;
for(auto it:v[i])
{
for(auto pp:sta)
{
if(p[it][pp]==0)r=0;
}
}
if(r==0)continue;
vis[i]=1;
for(auto it:v[i])sta.pb(it);
ans[last][i]=1;
ans[i][last]=1;
last=i;
}
if(x==last)return;
if(ans[x][last])return;
ans[x][last]=1;
ans[last][x]=1;
}
vector<int>w;
int construct(vector<vector<int>> P) {
n = P.size();
for(int i=0;i<n;i++)
{
pa[i]=i;sz[i]=1;v[i].pb(i);
}
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(i==j)continue;
p[i][j]=P[i][j];
if(p[i][j]==1)merge(i,j);
}
}
for(int i=0;i<n;i++)w.pb(0);
for(int i=0;i<n;i++)
{
ans.pb(w);
}
for(int i=0;i<n;i++)
{
if(pa[i]!=i)continue;
for(auto it:v[i])
{
if(it==i)continue;
ans[i][it]=1;
ans[it][i]=1;
}
u.pb(i);
}
for(int i=0;i<u.size();i++)
{
int it=u[i];
if(vis[it])continue;
vis[it]=1;
go(it);
}
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... |