# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
927664 | Rifal | Connecting Supertrees (IOI20_supertrees) | C++14 | 1 ms | 348 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 endl '\n'
using namespace std;
int construct(std::vector<std::vector<int>> p) {
bool ok = true;
int n = p.size();
int typ[n+4]= {};
vector<int> v1[n+4], v2[n+4];
vector<vector<int>> gr;
bool egd[n+4][n+4] = {};
int cnt = 1;
for(int i = 0; i < n; i++) {
if(typ[i] == 0) {
typ[i] = cnt;
v1[cnt].push_back(i);
v2[cnt].push_back(i);
cnt++;
}
for(int j = 0; j < n; j++) {
if(j == i) continue;
if(p[i][j] == 1) {
if(typ[j] == 0) {
v1[typ[i]].push_back(j);
typ[j] = typ[i];
}
else if(typ[j] != typ[i]){
ok = false; break;
}
}
else if(p[i][j] == 2){
if(typ[j] == 0) {
v2[typ[i]].push_back(j);
typ[j] = typ[i];
}
else if(typ[j] != typ[i]){
ok = false; break;
}
}
else if(p[i][j] == 0 && typ[i] == typ[j]) {
ok = false; break;
}
}
if(!ok) break;
}
for(int i = 0; i < n; i++) cout << typ[i] << ' ';
cout << endl;
if(ok) {
for(int i = 1; i < cnt; i++) {
if(v1[i].size() > 1) {
for(int j = 1; j < v1[i].size(); j++) {
egd[v1[i][0]][v1[i][j]] = 1;
egd[v1[i][j]][v1[i][0]] = 1;
}
}
if(v2[i].size() > 1) {
for(int j = 1; j < v2[i].size(); j++) {
egd[v2[i][j]][v2[i][j-1]] = 1;
egd[v2[i][j-1]][v2[i][j]] = 1;
}
int siz = v2[i].size();
egd[v2[i][0]][v2[i][siz-1]] = 1;
egd[v2[i][siz-1]][v2[i][0]] = 1;
}
}
for(int i = 0; i < n; i++) {
// cout << 'i' << i << endl;
vector<int> cur;
for(int j = 0; j < n; j++) {
//cout << 'j' << ' ' << j << ' ' << egd[i][j] << endl;
cur.push_back(egd[i][j]);
}
gr.push_back(cur);
}
build(gr);
return 1;
}
else {
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... |