# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
309465 | pere_gil | Connecting Supertrees (IOI20_supertrees) | C++17 | 1 ms | 256 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 "bits/stdc++.h"
#include "supertrees.h"
using namespace std;
int pos[1001];
void init(int n){
for(int i=0;i<n;i++) pos[i]=i;
}
int findset(int a){
if(pos[a]==a) return a;
else return pos[a]=findset(pos[a]);
}
void unionset(int A, int B){
int a=findset(A);
int b=findset(B);
if(a!=b) pos[b]=a;
}
bool issameset(int a, int b){
if(findset(a)==findset(b)) return true;
else return false;
}
int construct(std::vector<std::vector<int> > p)
{
int n = p.size();
std::vector<std::vector<int> > answer;
init(n);
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(p[i][j]==1) unionset(i,j);
}
}
vector<int> ja[n];
for(int i=0;i<n;i++) ja[findset(i)].push_back(i);
bool semamo=false;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(issameset(i,j) and p[i][j]==0) semamo=true;
}
}
if(semamo) return 0;
int res[n+1][n+1];
memset(res,0,sizeof(res));
for(int i=0;i<n;i++){
for(int j=1;j<ja[i].size();j++){
res[ ja[i][j] ] [ ja[i][j-1] ]=1;
res[ ja[i][j-1] ] [ ja[i][j] ]=1;
}
res[ja[i][0]] [ ja[i][ja[i].size()-1] ]=1;
res[ja[i][ja[i].size()-1]][ja[i][0]]=1;
}
for (int i = 0; i < n; i++) {
std::vector<int> row;
for(int j=0;j<n;j++) row.push_back(res[i][j]);
row.resize(n);
answer.push_back(row);
}
build(answer);
return 1;
return 0;
}
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... |