Submission #591182

# Submission time Handle Problem Language Result Execution time Memory
591182 2022-07-07T01:16:06 Z SirCovidThe19th Connecting Supertrees (IOI20_supertrees) C++17
56 / 100
205 ms 22036 KB
#include <bits/stdc++.h>
#include "supertrees.h"
using namespace std;

#define FOR(i, x, y) for (int i = x; i < y; i++)

int construct(vector<vector<int>> p){
    int n = p.size();
    FOR(i, 0, n) FOR(j, 0, n) if (p[i][j] == 3) return 0;

    vector<vector<int>> ans(n, vector<int>(n, 0));
    bool vis[n] = {}; 
    int par[n]; iota(par, par + n, 0);

    function<int(int)> get = [&](int i){
        return i == par[i] ? i : par[i] = get(par[i]);
    };
    auto merge = [&](int a, int b){
        par[get(a)] = get(b);
    };
    FOR(src, 0, n) if (!vis[src]){
        bool incmp[n] = {}; vector<int> cmp; 
        FOR(i, 0, n) if (p[src][i])
            cmp.push_back(i), incmp[i] = 1;
    
        for (int i : cmp) for (int j : cmp) 
            if (p[i][j] == 1) merge(i, j);
            
        for (int i : cmp){ //check here
            if (vis[i]) return 0;
            FOR(j, 0, n)
                if (p[i][j] and !incmp[j]) return 0;
            for (int j : cmp)
                if (!((get(i) == get(j) and p[i][j] == 1) or (get(i) != get(j) and p[i][j] == 2)))
                    return 0;
        }
        for (int i : cmp) vis[i] = 1;

        bool use[n] = {}; vector<int> head;
        for (int i : cmp){
            int c = get(i);
            if (!use[c]) head.push_back(c), use[c] = 1;
            if (i != c) ans[i][c] = ans[c][i] = 1;
        }
        FOR(i, 0, head.size()){
            int a = head[i];
            int b = head[(i + 1) % head.size()];
            if (a != b) ans[a][b] = ans[b][a] = 1;
        }
    }
    build(ans);
    return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:5:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    5 | #define FOR(i, x, y) for (int i = x; i < y; i++)
......
   45 |         FOR(i, 0, head.size()){
      |             ~~~~~~~~~~~~~~~~~           
supertrees.cpp:45:9: note: in expansion of macro 'FOR'
   45 |         FOR(i, 0, head.size()){
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 224 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 8 ms 1100 KB Output is correct
7 Correct 205 ms 22028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 224 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 8 ms 1100 KB Output is correct
7 Correct 205 ms 22028 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1108 KB Output is correct
13 Correct 158 ms 21952 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 72 ms 12052 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 41 ms 5764 KB Output is correct
21 Correct 165 ms 22020 KB Output is correct
22 Correct 157 ms 21972 KB Output is correct
23 Correct 189 ms 22036 KB Output is correct
24 Correct 157 ms 21984 KB Output is correct
25 Correct 67 ms 12044 KB Output is correct
26 Correct 61 ms 12032 KB Output is correct
27 Correct 191 ms 22016 KB Output is correct
28 Correct 158 ms 21964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 0 ms 212 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 0 ms 212 KB Output is correct
4 Correct 41 ms 5768 KB Output is correct
5 Correct 197 ms 22016 KB Output is correct
6 Correct 159 ms 22020 KB Output is correct
7 Correct 188 ms 21984 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 40 ms 5740 KB Output is correct
10 Correct 164 ms 22024 KB Output is correct
11 Correct 163 ms 21980 KB Output is correct
12 Correct 194 ms 22024 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 41 ms 5676 KB Output is correct
17 Correct 161 ms 22032 KB Output is correct
18 Correct 165 ms 22032 KB Output is correct
19 Correct 158 ms 22020 KB Output is correct
20 Correct 159 ms 21956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 224 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 8 ms 1100 KB Output is correct
7 Correct 205 ms 22028 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1108 KB Output is correct
13 Correct 158 ms 21952 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 72 ms 12052 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 41 ms 5764 KB Output is correct
21 Correct 165 ms 22020 KB Output is correct
22 Correct 157 ms 21972 KB Output is correct
23 Correct 189 ms 22036 KB Output is correct
24 Correct 157 ms 21984 KB Output is correct
25 Correct 67 ms 12044 KB Output is correct
26 Correct 61 ms 12032 KB Output is correct
27 Correct 191 ms 22016 KB Output is correct
28 Correct 158 ms 21964 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Incorrect 0 ms 212 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 224 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 8 ms 1100 KB Output is correct
7 Correct 205 ms 22028 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1108 KB Output is correct
13 Correct 158 ms 21952 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 72 ms 12052 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 41 ms 5764 KB Output is correct
21 Correct 165 ms 22020 KB Output is correct
22 Correct 157 ms 21972 KB Output is correct
23 Correct 189 ms 22036 KB Output is correct
24 Correct 157 ms 21984 KB Output is correct
25 Correct 67 ms 12044 KB Output is correct
26 Correct 61 ms 12032 KB Output is correct
27 Correct 191 ms 22016 KB Output is correct
28 Correct 158 ms 21964 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Incorrect 0 ms 212 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -