Submission #1061868

# Submission time Handle Problem Language Result Execution time Memory
1061868 2024-08-16T14:34:38 Z ArthuroWich Connecting Supertrees (IOI20_supertrees) C++17
0 / 100
1 ms 348 KB
#include "supertrees.h"
#include<bits/stdc++.h>
using namespace std;
vector<vector<int>> adj;
int n, vis[1005], used[1005], co = 0;
void dfs(int i) {
    if (vis[i] > 0) {
        return;
    }
    vis[i] = co;
    for (int j = 0; j < n; j++) {
        if (i == j || adj[i][j] == 0) {
            continue;
        }
        dfs(j);
    }
}
int construct(vector<vector<int>> p) {
    n = p.size();
    adj = p;
    vector<vector<int>> ans(n, vector<int>(n, 0));
    for (int i = 0; i < n; i++) {
        if (vis[i] > 0) {
            continue;
        }
        co++;
        dfs(i);
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (p[i][j] == 3) {
                return 0;
            }
            if (p[i][j] == 0) {
                if (vis[i] == vis[j]) {
                    return 0;
                }
            } else {
                if (vis[i] != vis[j]) {
                    return 0;
                }
            }
        }
    }
    for (int i = 1; i <= co; i++) {
        vector<int> root;
        for (int j = 0; j < n; j++) {
            if (vis[j] == i && !used[j]) {
                root.push_back(j);
                used[j] = 1;
                for (int k = 0; k < n; k++) {
                    if (p[j][k] == 1) {
                        used[k] = 1;
                        ans[j][k] = 1;
                        ans[k][j] = 1;
                    }
                }
            }
        }
        if (root.size() == 1) {
            continue;
        }
        if (root.size() < 3) {
            return 0;
        }
        for (int j = 1; j < n; j++) {
            ans[root[j]][root[j-1]] = 1;
            ans[root[j-1]][root[j]] = 1;
        }
        ans[root.front()][root.back()] = 1;
        ans[root.back()][root.front()] = 1;
    }
    build(ans);
    return 1;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB b[0][0] is not 0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB b[0][0] is not 0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB b[0][0] is not 0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB b[0][0] is not 0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB b[0][0] is not 0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB b[0][0] is not 0
2 Halted 0 ms 0 KB -