# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
894671 | carla73 | Connecting Supertrees (IOI20_supertrees) | C++14 | 0 ms | 0 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 <vector>
using namespace std;
const int MAXT = 200;
const int MAXP = 20;
int p[MAXT][MAXT];
void build(vector<vector<int>>& b) {
// Output the constructed bridges
for (int i = 0; i < b.size(); ++i) {
for (int j = 0; j < b[i].size(); ++j) {
cout << b[i][j] << " ";
}
cout << endl;
}
}
int construct(int p[MAXT][MAXT]) {
int t;
cin >> t;
// Check for each pair of towers
for (int i = 0; i < t; ++i) {
for (int j = 0; j < t; ++j) {
// Check if the number of paths is valid
if (p[i][j] != p[j][i]) {
return -1; // Invalid input
}
if (i != j && p[i][j] == 0) {
return -1; // Invalid input
}
if (i != j && p[i][j] > 1) {
return -1; // Invalid input
}
}
}
vector<vector<int>> bridges(t, vector<int>(t, 0));
for (int i = 0; i < t; ++i) {
for (int j = i + 1; j < t; ++j) {
if (p[i][j] == 1) {
// Construct a bridge
bridges[i][j] = 1;
bridges[j][i] = 1;
}
}
}
// Call the build function to output the constructed bridges
build(bridges);
return 0;
}
int main() {
int result = construct(p);
if (result == -1) {
cout << "Invalid input" << endl;
}
return 0;
}