| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 300159 | model_code | Connecting Supertrees (IOI20_supertrees) | C++17 | 254 ms | 22256 KiB | 
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// limli-always-possible-st4
#include <bits/stdc++.h>
#include "supertrees.h"
using namespace std;
int construct(vector<vector<int>> p) {
    int n = p.size();
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (p[i][j] == 3) return 0;
        }
    }
    vector<vector<int>> answer;
    for (int i = 0; i < n; i++) {
        vector<int> row;
        row.resize(n);
        answer.push_back(row);
    }
    vector<bool> visited(n);
    vector<int> componentIndex(n);
    vector<int> lineIndex(n);
    for (int aa = 0; aa < n; aa++) {
        if (visited[aa]) continue;
        queue<int> qcomponent;
        qcomponent.push(aa);
        vector<int> cycle;
        while (!qcomponent.empty()) {
            int x = qcomponent.front();
            qcomponent.pop();
            if (visited[x]) continue;
            vector<int> curline;
            queue<int> qline;
            qline.push(x);
            cycle.push_back(x);
            while (!qline.empty()) {
                int y = qline.front();
                qline.pop();
                if (visited[y]) continue;
                curline.push_back(y);
                visited[y] = true;
                componentIndex[y] = aa;
                lineIndex[y] = x;
                for (int i = 0; i < n; i++) {
                    if (p[y][i] == 2)
                        qcomponent.push(i);
                    else if (p[y][i] == 1)
                        qline.push(i);
                }
            }
            // for (int i : curline) printf("%d ", i); printf("\n");
            if (curline.size() > 1) {
                for (int i = 0; i < curline.size() - 1; i++) {
                    int a = curline[i];
                    int b = curline[i + 1];
                    answer[a][b] = answer[b][a] = 1;
                }
            }
        }
        if (cycle.size() == 2) return 0;
        if (cycle.size() == 1) continue;
        for (int i = 0; i < cycle.size(); i++) {
            int a = cycle[i];
            int b = cycle[(i + 1) % cycle.size()];
            answer[a][b] = answer[b][a] = 1;
        }
    }
    build(answer);
    return 1;
}
Compilation message (stderr)
| # | 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... | ||||
