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 "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 5;
int parent[maxn];
vector<int> comp[maxn];
int get(int x) {
    return parent[x] == x ? x : parent[x] = get(parent[x]);
}
bool merge(int x, int y) {
    int xroot = get(x), yroot = get(y);
    if (comp[xroot].size() < comp[yroot].size()) {
        swap(xroot, yroot);
    }
    if (xroot != yroot) {
        parent[xroot] = yroot;
        comp[yroot].insert(comp[yroot].end(), comp[xroot].begin(), comp[xroot].end());
        comp[xroot].clear();
        return true;
    }
    return false;
}
bool same(int x, int y) {
    return get(x) == get(y);
}
int construct(vector<vector<int>> p) {
    int n = p.size();
    for (int i = 0; i < n; ++i) {
        parent[i] = i;
        comp[i].push_back(i);
    }
    vector<vector<int>> sol(n, vector<int>(n));
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            if (p[i][j]) {
                merge(i, j);
            }
        }
    }
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            if (!p[i][j] && same(i, j)) {
                return 0;
            }
        }
    }
    for (int i = 0; i < n; i++) {
        if (!comp[i].empty()) {
            for (int j = 0; j < comp[i].size() - 1; ++j) {
                sol[comp[i][j]][comp[i][j + 1]] = 1;
                sol[comp[i][j + 1]][comp[i][j]] = 1;
            }
        }
    }
    build(sol);
    return 1;
}
#ifdef DEBUG
int main() {
    freopen("1.in", "r", stdin);
    int n;
    cin >> n;
    vector<vector<int>> a(n, vector<int>(n));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            cin >> a[i][j];
        }
    }
    cout << construct(a) << "\n";
}
#endif
Compilation message (stderr)
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:55:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |             for (int j = 0; j < comp[i].size() - 1; ++j) {
      |                             ~~^~~~~~~~~~~~~~~~~~~~| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |