# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
554379 | n0sk1ll | Connecting Supertrees (IOI20_supertrees) | C++14 | 231 ms | 24268 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;
int up[1003];
vector<int> chain[1003];
vector<int> head;
vector<int> kompofheads[1003];
int Up(int x)
{
if (up[x]<0) return x;
return up[x]=Up(up[x]);
}
void dsu(int a, int b)
{
a=Up(a),b=Up(b);
if (a==b) return;
up[a]=b;
}
vector<vector<int>> ans;
void add(int i, int j)
{
ans[i][j]=1,ans[j][i]=1;
}
int construct(vector<vector<int>> p)
{
int n = p.size();
for (int i=0;i<n;i++)
{
vector<int> pom(n,0);
ans.push_back(pom);
}
for (int i=0;i<n;i++)
if (p[i][i]!=1) return 0;
for (int i=0;i<n;i++)
for (int j=0;j<n;j++)
if (p[i][j]==3) return 0;
for (int i=0;i<n;i++) up[i]=-1;
for (int i=0;i<n;i++)
for (int j=0;j<n;j++)
if (p[i][j]==1) dsu(i,j);
for (int i=0;i<n;i++)
for (int j=0;j<n;j++)
if (Up(i)==Up(j) && p[i][j]!=1) return 0;
for (int i=0;i<n;i++) chain[Up(i)].push_back(i);
for (int i=0;i<n;i++) if (up[i]<0) head.push_back(i);
for (int i=0;i<n;i++)
for (int j=0;j<n;j++)
if (p[i][j]) dsu(i,j);
for (int i=0;i<n;i++)
for (int j=0;j<n;j++)
if (Up(i)==Up(j) && !p[i][j]) return 0;
for (int i=0;i<head.size();i++)
kompofheads[Up(head[i])].push_back(head[i]);
for (int i=0;i<n;i++)
{
if (kompofheads[i].size()==2) return 0;
if (kompofheads[i].size()>2)
{
for (int j=1;j<kompofheads[i].size();j++) add(kompofheads[i][j-1],kompofheads[i][j]);
add(kompofheads[i].front(),kompofheads[i].back());
}
}
for (int i=0;i<n;i++)
for (int j=1;j<chain[i].size();j++)
add(chain[i][j-1],chain[i][j]);
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... |