# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
384653 | nicholask | Connecting Supertrees (IOI20_supertrees) | C++14 | 0 ms | 0 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 construct(vector <vector <int> > p){
int n=p.size();
vector <vector <int> > ans(n,vector<int>(n,0));
vector <vector <int> > ones;
bool d[n];
for (int i=0; i<n; i++) d[i]=0;
for (int i=0; i<n; i++){
if (d[i]) continue;
vector <int> v;
for (int j=i; j<n; j++){
if (p[i][j]==1){
if (d[j]) return 0;
d[j]=1;
v.push_back(j);
}
}
for (int j=0; j<v.size()-1; j++) ans[v[j]][v[j+1]]=1;
ones.push_back(v);
}
bool e[ones.size()];
for (int i=0; i<ones.size(); i++) e[i]=0;
for (int i=0; i<ones.size(); i++){
if (e[i]) continue;
vector <int> temp;
temp.push_back(ones[i].front());
for (int j=i+1; j<ones.size(); j++){
if (!e[j]&&p[ones[i].front()][ones[j].front()]==2){
temp.push_back(ones[j].front());
e[j]=1;
}
}
int ss=temp.size();
if (ss<3) continue;
for (int j=0; j<temp.size(); j++) ans[temp[j]][temp[(j+1)%ss]]=1;
}
for (int i=0; i<n; i++){
for (int j=0; j<n; j++){
if (a[j][i]) a[i][j]=1;
}
}
build(ans);
return 1;
}