# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1078250 | mindiyak | Connecting Supertrees (IOI20_supertrees) | C++14 | 174 ms | 24188 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 <set>
#include <iostream>
using namespace std;
vector<int> parent(1005,0);
vector<int> parentg(1005,0);
int get_parent(int a){
if(a == parent[a])return a;
return get_parent(parent[a]);
}
int get_parentg(int a){
if(a == parentg[a])return a;
return get_parentg(parentg[a]);
}
int construct(vector<vector<int>> p) {
int n = p.size();
vector<vector<int>> answer(n, vector<int>(n,0));
for(int i=0;i<n;i++)parent[i]=i;
for(int i=0;i<n;i++)parentg[i]=i;
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
if(p[i][j] == 3)return 0;
if(p[i][j] == 1){
if(get_parent(i) == get_parent(j))continue;
answer[i][j] = 1;
answer[j][i] = 1;
parent[j] = get_parent(i);
parentg[j] = parent[j];
}
}
}
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
if(p[i][j] == 2){
int a = get_parent(i), b = get_parent(j);
if(a==b)continue;
if(get_parentg(a) == get_parentg(b))continue;
if(a>b)swap(a,b);
parentg[get_parentg(b)] = get_parentg(a);
}
}
}
vector<set<int>> heads(1005);
for(int i=0;i<n;i++){
heads[get_parentg(i)].insert(get_parent(i));
}
for(int i=0;i<n;i++){
vector<int> temp;
for(int a:heads[i])temp.push_back(a);
int m = temp.size();
if(m < 2)continue;
for(int j = 0;j<=temp.size();j++){
answer[temp[j%m]][temp[(j+1)%m]] = 1;
answer[temp[(j+1)%m]][temp[j%m]] = 1;
}
}
cerr << endl;
for(int i=0;i<n;i++)cerr << get_parent(i) << " ";
cerr << endl;
for(int i=0;i<n;i++)cerr << get_parentg(i) << " ";
cerr << endl;
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
int a = get_parent(i), b = get_parent(j);
int c = get_parentg(a), d = get_parentg(b);
if(p[i][j] == 0){
if(a == b)return 0;
if(c == d)return 0;
}
if(p[i][j] == 1){
if(a != b)return 0;
}
if(p[i][j] == 2){
if(heads[c].size() < 2)return 0;
if(a == b)return 0;
if(c != d)return 0;
}
}
}
build(answer);
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... |