# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
316001 | gurkot | Connecting Supertrees (IOI20_supertrees) | C++14 | 244 ms | 22136 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 <iostream>
#include "supertrees.h"
#include <vector>
using namespace std;
int tree[1501],comp[1501],mas[1501];
int n,ntree,ncomp;
int construct(std::vector<std::vector<int>> p) {
n = p.size();
std::vector<std::vector<int>> answer;
for (int i = 0; i < n; i++) {
std::vector<int> row;
row.resize(n);
answer.push_back(row);
}
//cout<<"ok1: let find trees"<<endl;
for (int i=0; i<n;i++)
if (tree[i]==0){
++ntree;
for (int j=0;j<n;j++) {
if (p[i][j]==3) return 0;
if (i!=j && p[i][j]==1){
if (tree[j]>0) return 0;
tree[j]=ntree;
answer[i][j]=answer[j][i]=1;
}
}//J
}//i
//cout<<"ok2: let find connected components"<<endl;
for (int i=0; i<n;i++)
if (comp[i]==0){
ncomp++;
int s=i,a=i,k=1,cnt=0;
for (int j=0;j<n;j++)
if (i!=j && p[i][j]>0){
mas[++cnt]=j;
for (int ic=1;ic<cnt;ic++)
if (p[ic][cnt]==0 || p[cnt][ic]==0) return 0;
if (comp[j]>0) return 0;
comp[j]=ncomp;
if (tree[j]==0) {
k++;
answer[a][j]=answer[j][a]=1;
a=j;
}
}//j
if (k==2) return 0;
if (k>2) answer[a][s]=answer[s][a]=1;
}//i
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... |