Submission #894671

# Submission time Handle Problem Language Result Execution time Memory
894671 2023-12-28T16:24:26 Z carla73 Connecting Supertrees (IOI20_supertrees) C++14
Compilation error
0 ms 0 KB
#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;
}

Compilation message

supertrees.cpp: In function 'void build(std::vector<std::vector<int> >&)':
supertrees.cpp:13:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |     for (int i = 0; i < b.size(); ++i) {
      |                     ~~^~~~~~~~~~
supertrees.cpp:14:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |         for (int j = 0; j < b[i].size(); ++j) {
      |                         ~~^~~~~~~~~~~~~
/usr/bin/ld: /tmp/ccXr9FKx.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccIelLRv.o:supertrees.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccXr9FKx.o: in function `main':
grader.cpp:(.text.startup+0x38a): undefined reference to `construct(std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >)'
collect2: error: ld returned 1 exit status