Submission #1007441

# Submission time Handle Problem Language Result Execution time Memory
1007441 2024-06-24T23:50:53 Z u_suck_o Connecting Supertrees (IOI20_supertrees) C++17
19 / 100
117 ms 22100 KB
#include "supertrees.h"
#include "bits/stdc++.h"
#define MAXN 1005

using namespace std;

int N;
int sizes[MAXN], par[MAXN];
vector<int> comps[MAXN];
vector<vector<int>> answer;

int find(int u) {
    if (u != par[u])
        par[u] = find(par[u]);
    return par[u];
}

void join(int u, int v) {
    u = find(u);
    v = find(v);
    if (u == v) return;
    //answer[u][v] = 1;
    //answer[v][u] = 1;
    if (sizes[u] > sizes[v]) {
        par[v] = u;
        sizes[u] += sizes[v];
    } else {
        par[u] = v;
        sizes[v] += sizes[u];
    }
}

int construct(vector<vector<int>> p) {
    N = p.size();
    answer = vector<vector<int>>(N, vector<int>(N, 0));
    
    for (int i = 0; i < N; i++) {
        par[i] = i;
        sizes[i] = 1;
    }
    
    for (int i = 0; i < N; i++) {
        for (int j = i+1; j < N; j++) {
            if (p[i][j])
                join(i, j);
        }
    }
    
    //build components
    for (int i = 0; i < N; i++)
        comps[find(i)].push_back(i);
    for (int i = 0; i < N; i++) {
        if (comps[i].size() == 2)
            return 0;
        for (int j = 0; j < ((int) comps[i].size())-1; j++) {
            answer[comps[i][j]][comps[i][j+1]] = 1;
            answer[comps[i][j+1]][comps[i][j]] = 1;
        }
        if (comps[i].size() >= 3) {
            answer[comps[i][0]][comps[i][comps[i].size()-1]] = 1;
            answer[comps[i][comps[i].size()-1]][comps[i][0]] = 1;
        }
    }
    
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (p[i][j] && find(i) != find(j))
                return 0;
            if (!p[i][j] && find(i) == find(j))
                return 0;
        }
    }
    build(answer);
    return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Answer gives possible 0 while actual possible 1
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Answer gives possible 0 while actual possible 1
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 5 ms 1116 KB Output is correct
9 Correct 102 ms 22100 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 4 ms 1116 KB Output is correct
13 Correct 117 ms 22028 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 860 KB Output is correct
17 Correct 54 ms 12084 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 27 ms 5804 KB Output is correct
22 Correct 109 ms 22064 KB Output is correct
23 Correct 99 ms 22096 KB Output is correct
24 Correct 115 ms 22096 KB Output is correct
25 Correct 47 ms 12116 KB Output is correct
26 Correct 46 ms 12116 KB Output is correct
27 Correct 99 ms 22100 KB Output is correct
28 Correct 105 ms 22096 KB Output is correct
29 Correct 41 ms 12116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Too many ways to get from 1 to 4, should be 1 found no less than 2
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Answer gives possible 0 while actual possible 1
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Answer gives possible 0 while actual possible 1
3 Halted 0 ms 0 KB -