Submission #772862

# Submission time Handle Problem Language Result Execution time Memory
772862 2023-07-04T12:00:41 Z fve5 Connecting Supertrees (IOI20_supertrees) C++17
56 / 100
187 ms 28016 KB
#include <bits/stdc++.h>
#include "supertrees.h"
using namespace std;

struct DSU {
    vector<int> nodes;

    int find(int node) {
        if (nodes[node] < 0) return node;
        return nodes[node] = find(nodes[node]);
    }

    void join(int u, int v) {
        u = find(u), v = find(v);
        if (u == v) return;

        if (nodes[u] > nodes[v]) swap(u, v);
        nodes[u] += nodes[v];
        nodes[v] = u;
    }

    map<int, vector<int>> get_cc() {
        map<int, vector<int>> ans;
        for (int i = 0; i < nodes.size(); i++) {
            ans[find(i)].push_back(i);
        }
        return ans;
    }

    DSU(int size) : nodes(size, -1) { }
};

int construct(vector<vector<int>> p) {
    int n = p.size();
    
    vector adj(n, vector(n, 0));
    vector act_p(n, vector(n, 0));
    DSU dsu(n);
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (p[i][j]) dsu.join(i, j);
        }
    }

    auto ccs = dsu.get_cc();
    for (auto [_, cc]: ccs) {
        DSU dsu2(cc.size());
        for (auto x: cc) {
            for (auto y: cc) {
                act_p[x][y] = 2;
            }
        }
        for (int i = 0; i < cc.size(); i++) {
            for (int j = 0; j < cc.size(); j++) {
                if (p[cc[i]][cc[j]] == 1) dsu2.join(i, j);
            }
        }
        auto ccs2 = dsu2.get_cc();
        vector<int> cycle;
        for (auto [r, cc2]: ccs2) {
            for (auto x: cc2) {
                for (auto y: cc2) {
                    act_p[cc[x]][cc[y]] = 1;
                }
            }
            cycle.push_back(cc[r]);
            for (int i = 1; i < cc2.size(); i++) {
                adj[cc[cc2[i]]][cc[cc2[i - 1]]] = adj[cc[cc2[i - 1]]][cc[cc2[i]]] = 1;
            }
        }
        if (cycle.size() < 3) continue;
        for (int i = 0; i < cycle.size(); i++) {
            adj[cycle[i]][cycle[(i + 1) % cycle.size()]] = adj[cycle[(i + 1) % cycle.size()]][cycle[i]] = 1;
        }
    }
    if (p == act_p) {
        build(adj);
        return 1;
    } else {
        return 0;
    }
}

Compilation message

supertrees.cpp: In member function 'std::map<int, std::vector<int> > DSU::get_cc()':
supertrees.cpp:24:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |         for (int i = 0; i < nodes.size(); i++) {
      |                         ~~^~~~~~~~~~~~~~
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:53:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |         for (int i = 0; i < cc.size(); i++) {
      |                         ~~^~~~~~~~~~~
supertrees.cpp:54:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |             for (int j = 0; j < cc.size(); j++) {
      |                             ~~^~~~~~~~~~~
supertrees.cpp:67:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |             for (int i = 1; i < cc2.size(); i++) {
      |                             ~~^~~~~~~~~~~~
supertrees.cpp:72:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |         for (int i = 0; i < cycle.size(); i++) {
      |                         ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1364 KB Output is correct
7 Correct 156 ms 26460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1364 KB Output is correct
7 Correct 156 ms 26460 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 6 ms 1464 KB Output is correct
13 Correct 148 ms 26776 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 952 KB Output is correct
17 Correct 79 ms 18048 KB Output is correct
18 Correct 1 ms 300 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 37 ms 7256 KB Output is correct
21 Correct 148 ms 27980 KB Output is correct
22 Correct 145 ms 27980 KB Output is correct
23 Correct 156 ms 27944 KB Output is correct
24 Correct 159 ms 28016 KB Output is correct
25 Correct 61 ms 18000 KB Output is correct
26 Correct 62 ms 18036 KB Output is correct
27 Correct 155 ms 27908 KB Output is correct
28 Correct 151 ms 28016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Incorrect 0 ms 296 KB Answer gives possible 1 while actual possible 0
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 37 ms 7084 KB Output is correct
5 Correct 149 ms 26444 KB Output is correct
6 Correct 155 ms 26488 KB Output is correct
7 Correct 187 ms 26464 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 41 ms 7116 KB Output is correct
10 Correct 157 ms 26520 KB Output is correct
11 Correct 146 ms 26496 KB Output is correct
12 Correct 155 ms 26736 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 37 ms 7132 KB Output is correct
17 Correct 150 ms 26588 KB Output is correct
18 Correct 150 ms 26488 KB Output is correct
19 Correct 147 ms 26556 KB Output is correct
20 Correct 154 ms 26700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1364 KB Output is correct
7 Correct 156 ms 26460 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 6 ms 1464 KB Output is correct
13 Correct 148 ms 26776 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 952 KB Output is correct
17 Correct 79 ms 18048 KB Output is correct
18 Correct 1 ms 300 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 37 ms 7256 KB Output is correct
21 Correct 148 ms 27980 KB Output is correct
22 Correct 145 ms 27980 KB Output is correct
23 Correct 156 ms 27944 KB Output is correct
24 Correct 159 ms 28016 KB Output is correct
25 Correct 61 ms 18000 KB Output is correct
26 Correct 62 ms 18036 KB Output is correct
27 Correct 155 ms 27908 KB Output is correct
28 Correct 151 ms 28016 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Incorrect 0 ms 296 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1364 KB Output is correct
7 Correct 156 ms 26460 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 6 ms 1464 KB Output is correct
13 Correct 148 ms 26776 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 952 KB Output is correct
17 Correct 79 ms 18048 KB Output is correct
18 Correct 1 ms 300 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 37 ms 7256 KB Output is correct
21 Correct 148 ms 27980 KB Output is correct
22 Correct 145 ms 27980 KB Output is correct
23 Correct 156 ms 27944 KB Output is correct
24 Correct 159 ms 28016 KB Output is correct
25 Correct 61 ms 18000 KB Output is correct
26 Correct 62 ms 18036 KB Output is correct
27 Correct 155 ms 27908 KB Output is correct
28 Correct 151 ms 28016 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Incorrect 0 ms 296 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -