# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
384766 | Micchon | Connecting Supertrees (IOI20_supertrees) | C++14 | 1 ms | 364 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>
#define vi vector<int>
using namespace std;
vi par;
int construct(std::vector<std::vector<int>> p) {
int n = p.size();
for(int i=0;i<n;i++) for(int j=0;j<n;j++) if(p[i][j] == 3) return 0;
std::vector<std::vector<int>> answer(n,vi(n,0));
par = vi(n,-1);
vi cyc(n,0);
for(int i=0;i<n;i++){
if(par[i] != -1) continue;
cyc[i] = 1;
for(int j=0;j<n;j++){
if(p[i][j] == 1){
if(par[j] != -1 && par[j] != i) return 0;
par[j] = i;
if(i != j) answer[i][j] = 1 , answer[j][i] = 1;
}
}
}
par = vi(n,-1);
for(int i=0;i<n;i++){
if(par[i] != -1) continue;
vi tmp;
for(int j=0;j<n;j++){
if(p[i][j] != 0){
if(par[j] != -1 && par[j] != i) return 0;
par[j] = i;
if(cyc[j]) tmp.push_back(j);
}
}
if(tmp.size() <= 2) return 0;
for(int j=0;j<tmp.size();j++){
int i1 = tmp[j] , i2 = tmp[(j+1)%tmp.size()];
answer[i1][i2] = 1 , answer[i2][i1] = 1;
}
}
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... |