Submission #1119104

#TimeUsernameProblemLanguageResultExecution timeMemory
1119104adaawfConnecting Supertrees (IOI20_supertrees)C++17
Compilation error
0 ms0 KiB
#include <iostream>
#include <vector>
//#include "supertrees.h"
using namespace std;
vector<int> v[1005], vv[1005];
int p[1005];
vector<vector<int>> res;
int Find(int x) {
    if (x == p[x]) return x;
    return p[x] = Find(p[x]);
}
void Merge(int x, int y, int fl) {
    x = Find(x);
    y = Find(y);
    if (x == y) return;
    if (v[x].size() < v[y].size()) {
        swap(x, y);
    }
    for (int w : v[y]) v[x].push_back(w);
    v[y].clear();
    if (fl == 0) res[x][y] = res[y][x] = 1;
    p[y] = x;
    if (fl == 1) {
        for (int w : vv[y]) vv[x].push_back(w);
    }
}
void build(vector<vector<int>> b) {
    for (int i = 0; i < b.size(); i++) {
        for (int j = 0; j < b.size(); j++) {
            cout << b[i][j] << " ";
        }
        cout << '\n';
    }
}
int construct(vector<vector<int>> a) {
    int n = a.size();
    res = vector<vector<int>>(n, vector<int>(n, 0));
    for (int i = 0; i < n; i++) {
        p[i] = i;
        v[i].clear(); vv[i].clear();
        v[i].push_back(i);
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (a[i][j] == 1) {
                Merge(i, j, 0);
            }
            if (a[i][j] == 3) return 0;
        }
    }
    for (int i = 0; i < n; i++) {
        if (Find(i) == i) {
            for (int w : v[i]) {
                for (int ww : v[i]) {
                    if (a[w][ww] != 1) return 0;
                }
            }
            vv[i].push_back(i);
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (a[i][j] == 2) {
                Merge(i, j, 1);
            }
        }
    }
    for (int i = 0; i < n; i++) {
        if (Find(i) == i) {
            for (int j = 0; j < vv[i].size() - 1; j++) {
                res[vv[i][j]][vv[i][j + 1]] = res[vv[i][j + 1]][vv[i][j]] = 1;
            }
            if (vv[i].size() != 1) res[vv[i][0]][vv[i].back()] = res[vv[i].back()][vv[i][0]] = 1;
            if (vv[i].size() == 2) return 0;
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (a[i][j] && Find(i) != Find(j)) return 0;
            if (a[i][j] == 0 && Find(i) == Find(j)) return 0;
        }
    }
    build(res);
    return 1;
}
int main() {
    construct({{1, 2}, {2, 1}});
}

Compilation message (stderr)

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