Submission #1071246

# Submission time Handle Problem Language Result Execution time Memory
1071246 2024-08-23T06:12:23 Z Ignut Connecting Supertrees (IOI20_supertrees) C++17
21 / 100
164 ms 24200 KB
// Ignut

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

void build(vector<vector<int>> b);

struct DSU {
    vector<int> p;
    vector<vector<int>> comp;
    void Init(int n) {
        p.clear(), comp.clear();
        for (int i = 0; i < n; i ++) p.push_back(i), comp.push_back({i});
    }
    int Get(int v) {
        return p[v] == v ? v : p[v] = Get(p[v]);
    }
    void Unite(int u, int v) {
        u = Get(u), v = Get(v);
        if (u == v) return;
        if (comp[u].size() > comp[v].size()) swap(u, v);
        p[u] = v;
        for (int val : comp[u]) comp[v].push_back(val);
    }
};

int construct(vector<vector<int>> p) {
    int n = p.size();
    DSU dsu; dsu.Init(n);
    for (int i = 0; i < n; i ++) {
        for (int j = 0; j < n; j ++) {
            if (p[i][j] == 1) {
                dsu.Unite(i, j);
            }
        }
    }
    for (int i = 0; i < n; i ++) {
        for (int j = 0; j < n; j ++) {
            bool f1 = p[i][j];
            bool f2 = (dsu.Get(i) == dsu.Get(j));
            if (f1 != f2)
                return 0;
        }
    }
    vector<vector<int>> b(n);
    for (int i = 0; i < n; i ++) b[i].assign(n, 0);
    for (int i = 0; i < n; i ++) {
        if (dsu.Get(i) != i) continue;
        for (int j = 0; j + 1 < dsu.comp[i].size(); j ++)
            b[dsu.comp[i][j]][dsu.comp[i][j + 1]] = b[dsu.comp[i][j + 1]][dsu.comp[i][j]] = 1;
    }
    build(b);
    return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:51:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |         for (int j = 0; j + 1 < dsu.comp[i].size(); j ++)
      |                         ~~~~~~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1356 KB Output is correct
7 Correct 164 ms 24056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1356 KB Output is correct
7 Correct 164 ms 24056 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1372 KB Output is correct
13 Correct 133 ms 24200 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
17 Correct 60 ms 10320 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 31 ms 6404 KB Output is correct
21 Correct 126 ms 24144 KB Output is correct
22 Correct 153 ms 23976 KB Output is correct
23 Correct 140 ms 23972 KB Output is correct
24 Correct 113 ms 24016 KB Output is correct
25 Correct 53 ms 10104 KB Output is correct
26 Correct 70 ms 10244 KB Output is correct
27 Correct 125 ms 24148 KB Output is correct
28 Correct 125 ms 23976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 436 KB Output is correct
5 Incorrect 0 ms 432 KB Answer gives possible 0 while actual possible 1
6 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 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1356 KB Output is correct
7 Correct 164 ms 24056 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1372 KB Output is correct
13 Correct 133 ms 24200 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
17 Correct 60 ms 10320 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 31 ms 6404 KB Output is correct
21 Correct 126 ms 24144 KB Output is correct
22 Correct 153 ms 23976 KB Output is correct
23 Correct 140 ms 23972 KB Output is correct
24 Correct 113 ms 24016 KB Output is correct
25 Correct 53 ms 10104 KB Output is correct
26 Correct 70 ms 10244 KB Output is correct
27 Correct 125 ms 24148 KB Output is correct
28 Correct 125 ms 23976 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 436 KB Output is correct
33 Incorrect 0 ms 432 KB Answer gives possible 0 while actual possible 1
34 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1356 KB Output is correct
7 Correct 164 ms 24056 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1372 KB Output is correct
13 Correct 133 ms 24200 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
17 Correct 60 ms 10320 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 31 ms 6404 KB Output is correct
21 Correct 126 ms 24144 KB Output is correct
22 Correct 153 ms 23976 KB Output is correct
23 Correct 140 ms 23972 KB Output is correct
24 Correct 113 ms 24016 KB Output is correct
25 Correct 53 ms 10104 KB Output is correct
26 Correct 70 ms 10244 KB Output is correct
27 Correct 125 ms 24148 KB Output is correct
28 Correct 125 ms 23976 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 436 KB Output is correct
33 Incorrect 0 ms 432 KB Answer gives possible 0 while actual possible 1
34 Halted 0 ms 0 KB -