Submission #928029

# Submission time Handle Problem Language Result Execution time Memory
928029 2024-02-15T18:22:14 Z EJIC_B_KEDAX Connecting Supertrees (IOI20_supertrees) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>

using ll = long long;

using namespace std;

const int N = 1010;
int dsu[N];

int get(int x) {
    return dsu[x] == x ? x : dsu[x] = get(dsu[x]);
}

void merge(int x, int y) {
    dsu[get(x)] = get(y);
}

int construct(vector<vector<int>> p) {
    int n = (int)p.size();
    for (int i = 0; i < n; i++) {
        dsu[i] = i;
    }
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (p[i][j] == 1) {
                merge(i, j);
            }
        }
    }
    vector<vector<int>> b(n, vector<int>(n, 0)), group(n);
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (p[i][j] == 0 && get(i) == get(j)) {
                return 0;
            }
        }
        group[get(i)].push_back(i);
    }
    vector<int> g;
    for (int i = 0; i < n; i++) {
        for (int j = 1; j < group[i].size(); j++) {
            b[group[i][j - 1]][group[i][j]] = 1;
            b[group[i][j]][group[i][j - 1]] = 1;
        }
        if (!group[i].empty()) {
            g.push_back(i);
        }
        group[i].clear();
    }
    for (int i : g) {
        for (int j : g) {
            if (p[i][j] == 2 && i < j) {
                merge(i, j);
            }
        }
    }
    for (int i : g) {
        for (int j : g) {
            if (p[i][j] < 2 && get(i) == get(j) && i < j) {
                return 0;
            }
        }
        group[get(i)].push_back(i);
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < group[i].size(); j++) {
            b[group[i][(j - 1 + group[i].size()) % group[i].size()]][group[i][j]] = 1;
            b[group[i][j]][group[i][(j - 1 + group[i].size()) % group[i].size()]] = 1;
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (p[i][j] == 3) {
                return 0;
            }
        }
    }
    build(b);
    return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:41:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |         for (int j = 1; j < group[i].size(); j++) {
      |                         ~~^~~~~~~~~~~~~~~~~
supertrees.cpp:66:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |         for (int j = 0; j < group[i].size(); j++) {
      |                         ~~^~~~~~~~~~~~~~~~~
supertrees.cpp:78:5: error: 'build' was not declared in this scope
   78 |     build(b);
      |     ^~~~~