# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
395118 | T0p_ | Connecting Supertrees (IOI20_supertrees) | C++14 | 1 ms | 208 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 pa[2005], edge[1010][1010];
bool cycle[2005];
int fp(int u) {return (u == pa[u]) ? u : pa[u] = fp(pa[u]);}
int construct(vector<vector<int>> p)
{
int n = p.size();
for(int i=0 ; i<n+n ; i++)
pa[i] = i;
for(int i=0 ; i<n ; i++)
for(int j=i+1 ; j<n ; j++)
{
if(p[i][j] == 3) return 0;
else if(p[i][j])
{
pa[fp(i)] = fp(j);
pa[fp(i+n)] = fp(j+n);
}
else
{
pa[fp(i)] = fp(j+n);
pa[fp(i+n)] = fp(j);
}
}
for(int i=0 ; i<n ; i++)
if(fp(i) == fp(i+n)) return 0;
for(int i=0 ; i<n ; i++)
{
vector<int> tmp;
if(cycle[i]) continue;
for(int j=0 ; j<n ; j++)
{
if(i == j) continue;
if(p[i][j] == 1) goto out;
}
tmp.push_back(i);
for(int j=0 ; j<n ; j++)
{
if(p[i][j] == 2) tmp.push_back(j);
}
tmp.push_back(i);
for(int j=1 ; j<tmp.size() ; j++)
{
edge[tmp[j-1]][tmp[j]] = edge[tmp[j]][tmp[j-1]] = 1;
cycle[tmp[j]] = true;
}
out: ;
}
vector<vector<int>> ans;
for(int i=0 ; i<n ; i++)
{
vector<int> tmp;
for(int j=0 ; j<n ; j++)
tmp.push_back(edge[i][j]);
ans.push_back(tmp);
}
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... |