# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
807388 | nemethm | Connecting Supertrees (IOI20_supertrees) | C++17 | 150 ms | 27952 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 cmp[1010] = {0};
int subtask3(std::vector<std::vector<int>> p){
int 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);
}
int id = 0;
vector<vector<int>> elek;
for(int i = 0; i < n; ++i){
bool uj = false;
if(cmp[i] == 0){
++id;
cmp[i] = id;
uj = true;
elek.push_back({i});
}
for(int j = 0; j < n; ++j){
if(j == i) continue;
if(p[i][j] == 2){
if(cmp[j] != cmp[i] && !uj){
return 0;
}
else if(uj){
cmp[j] = cmp[i];
elek.back().push_back(j);
}
}
else{
if(cmp[j] == cmp[i]){
return 0;
}
}
}
}
for(auto& v : elek){
if(v.size() == 2){
return 0;
}
if(v.size() > 2){
for(int i = 0; i < v.size(); ++i){
answer[v[i]][v[(i + 1) % v.size()]] = answer[v[(i + 1) % v.size()]][v[i]] = 1;
}
}
}
build(answer);
return 1;
}
int subtask12(std::vector<std::vector<int>> p){
int 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);
}
int id = 0;
vector<vector<pair<int,int>>> elek;
for(int i = 0; i < n; ++i){
bool uj = false;
if(cmp[i] == 0){
++id;
cmp[i] = id;
uj = true;
elek.push_back({});
}
for(int j = 0; j < n; ++j){
if(j == i) continue;
if(p[i][j] == 1){
if(cmp[j] != cmp[i] && !uj){
return 0;
}
else if(uj){
cmp[j] = cmp[i];
elek.back().push_back({j, i});
}
}
else{
if(cmp[j] == cmp[i]){
return 0;
}
}
}
}
for(auto& v : elek){
for(auto i : v){
answer[i.first][i.second] = answer[i.second][i.first] = 1;
}
}
build(answer);
return 1;
}
int construct(std::vector<std::vector<int>> p) {
for(int i = 0; i < p.size(); ++i){
for(int j = 0; j < p.size(); ++j){
if(p[i][j] == 2){
return subtask3(p);
}
}
}
return subtask12(p);
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... |