# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
953762 | Trisanu_Das | Connecting Supertrees (IOI20_supertrees) | C++17 | 175 ms | 24148 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>
using namespace std;
int par[1005];
int fi(int i){
if(par[i]==i)
return i;
else
return par[i]=fi(par[i]);
}
void un(int i,int j){
par[fi(j)]=fi(i);
}
int construct(vector<vector<int>> p) {
int n = p.size();
vector<vector<int>> ans;
for (int i = 0; i < n; i++) {
vector<int> row;
row.resize(n);
ans.push_back(row);
}
for(int i=0;i<n;i++)
par[i]=i;
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
if(p[i][j]==1&&fi(i)!=fi(j)){
ans[i][j]=ans[j][i]=1;
un(i,j);
}
if(p[i][j]==3||(p[i][j]==0&&fi(i)==fi(j)))
return 0;
}
}
for(int i=0;i<n;i++){
vector<int> v;
v.push_back(par[i]);
for(int j=i+1;j<n;j++){
if(p[i][j]==2&&fi(i)!=fi(j)){
v.push_back(par[j]);
un(i,j);
}
}
if(v.size()==2)
return 0;
for(int k=0;k+1<v.size();k++)
ans[v[k]][v[k+1]]=ans[v[k+1]][v[k]]=1;
ans[v[0]][v[v.size()-1]]=ans[v[v.size()-1]][v[0]]=1;
}
for(int i=0;i<n;i++)
ans[i][i]=0;
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... |