# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
894671 | carla73 | Connecting Supertrees (IOI20_supertrees) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}