Submission #720649

# Submission time Handle Problem Language Result Execution time Memory
720649 2023-04-08T18:41:38 Z Toxtaq Connecting Supertrees (IOI20_supertrees) C++17
40 / 100
192 ms 26196 KB
#ifndef SUPERTREES_H_INCLUDED
#define SUPERTREES_H_INCLUDED
#include "supertrees.h"
#include<bits/stdc++.h>
using namespace std;
struct DSU{
    vector<int>par;
    DSU(int n){
        par.assign(n, -1);
    }
    int FindRep(int u){
        if(par[u] < 0)return u;
        return par[u] = FindRep(par[u]);
    }
    void Union(int u, int v){
        u = FindRep(u);
        v = FindRep(v);
        if(u == v)return;
        if(par[u] > par[v])swap(u, v);
        par[u] += par[v];
        par[v] = u;
    }
    bool IsConnected(int u, int v){
        u = FindRep(u);
        v = FindRep(v);
        return (u == v);
    }
};
int N;
void build(vector<vector<int>>b);
vector<bool>vis;
vector<vector<int>>B;
vector<int>components;
void dfs(int u){
    components.push_back(u);
    vis[u] = 1;
    for(int i = 0;i < N;++i){
        if(B[u][i] && !vis[i]){
            dfs(i);
        }
    }
}
bool Check(vector<vector<int>>p){
    for(int i = 0;i < N;++i){
        for(int j = 0;j < N;++j){
            if(p[i][j] == 2)return 1;
        }
    }
    return 0;
}
int construct(vector<vector<int>>p){
    N = p.size();
    bool ch = Check(p);
    if(ch){
        DSU dsu1(N);
        vis.resize(N);
        B.assign(N, vector<int>(N));
        vector<vector<int>>ans(N, vector<int>(N));
        for(int i = 0;i < N;++i){
            for(int j = 0;j < N;++j){
                if(p[i][j] && i != j){
                    if(dsu1.IsConnected(i, j))continue;
                    dsu1.Union(i, j);
                    B[i][j] = B[j][i] = 1;
                }
            }
        }
        for(int i = 0;i < N;++i){
            for(int j = 0;j < N;++j){
                if(i != j && !p[i][j] && dsu1.IsConnected(i, j))return 0;
            }
        }
        for(int i = 0;i < N;++i){
            int p = dsu1.FindRep(i);
            if(dsu1.par[p] == -2)return 0;
        }
        for(int i = 0;i < N;++i){
            if(!vis[i]){
                dfs(i);
                if(components.size() > 2){
                    for(int j = 1;j < components.size();++j){
                        ans[components[j]][components[j - 1]] = ans[components[j - 1]][components[j]] = 1;
                    }
                    ans[components.back()][components[0]] = ans[components[0]][components.back()] = 1;
                }
                components.clear();
            }
        }
        build(ans);
    }
    else{
        int n = N;
        DSU dsu1(n);
        vector<vector<int>>b(n, vector<int>(n));
        for(int i = 0;i < n;++i){
            for(int j = 0;j < n;++j){
                if(p[i][j] && i != j){
                    if(dsu1.IsConnected(i, j))continue;
                    dsu1.Union(i, j);
                    b[i][j] = b[j][i] = 1;
                }
            }
        }
        for(int i = 0;i < n;++i){
            for(int j = 0;j < n;++j){
                if(i != j && !p[i][j] && dsu1.IsConnected(i, j))return 0;
            }
        }
        build(b);
    }
    return 1;
}


#endif // SUPERTREES_H_INCLUDED

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:81:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |                     for(int j = 1;j < components.size();++j){
      |                                   ~~^~~~~~~~~~~~~~~~~~~
# 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 0 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 8 ms 1148 KB Output is correct
7 Correct 173 ms 22180 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 0 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 8 ms 1148 KB Output is correct
7 Correct 173 ms 22180 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 7 ms 1180 KB Output is correct
13 Correct 175 ms 22096 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 296 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 83 ms 12260 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 49 ms 5836 KB Output is correct
21 Correct 179 ms 22060 KB Output is correct
22 Correct 172 ms 22108 KB Output is correct
23 Correct 189 ms 22160 KB Output is correct
24 Correct 175 ms 22068 KB Output is correct
25 Correct 71 ms 12212 KB Output is correct
26 Correct 69 ms 12260 KB Output is correct
27 Correct 187 ms 22068 KB Output is correct
28 Correct 174 ms 22324 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 296 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 296 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 8 ms 1212 KB Output is correct
9 Correct 173 ms 22132 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 8 ms 1420 KB Output is correct
13 Correct 183 ms 26032 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 304 KB Output is correct
16 Correct 4 ms 956 KB Output is correct
17 Correct 86 ms 16156 KB Output is correct
18 Correct 1 ms 300 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 296 KB Output is correct
21 Correct 46 ms 6832 KB Output is correct
22 Correct 179 ms 26092 KB Output is correct
23 Correct 185 ms 26068 KB Output is correct
24 Correct 192 ms 26196 KB Output is correct
25 Correct 78 ms 16100 KB Output is correct
26 Correct 77 ms 16112 KB Output is correct
27 Correct 177 ms 26040 KB Output is correct
28 Correct 187 ms 26064 KB Output is correct
29 Correct 72 ms 16124 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 48 ms 5892 KB Output is correct
5 Correct 187 ms 22100 KB Output is correct
6 Correct 174 ms 22124 KB Output is correct
7 Correct 189 ms 22180 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 46 ms 6796 KB Output is correct
10 Correct 182 ms 26016 KB Output is correct
11 Correct 179 ms 26128 KB Output is correct
12 Correct 189 ms 26076 KB Output is correct
13 Correct 1 ms 296 KB Output is correct
14 Incorrect 1 ms 212 KB Too many ways to get from 4 to 8, should be 1 found no less than 2
15 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 0 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 8 ms 1148 KB Output is correct
7 Correct 173 ms 22180 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 7 ms 1180 KB Output is correct
13 Correct 175 ms 22096 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 296 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 83 ms 12260 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 49 ms 5836 KB Output is correct
21 Correct 179 ms 22060 KB Output is correct
22 Correct 172 ms 22108 KB Output is correct
23 Correct 189 ms 22160 KB Output is correct
24 Correct 175 ms 22068 KB Output is correct
25 Correct 71 ms 12212 KB Output is correct
26 Correct 69 ms 12260 KB Output is correct
27 Correct 187 ms 22068 KB Output is correct
28 Correct 174 ms 22324 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 296 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 296 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 8 ms 1212 KB Output is correct
37 Correct 173 ms 22132 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 8 ms 1420 KB Output is correct
41 Correct 183 ms 26032 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 304 KB Output is correct
44 Correct 4 ms 956 KB Output is correct
45 Correct 86 ms 16156 KB Output is correct
46 Correct 1 ms 300 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 296 KB Output is correct
49 Correct 46 ms 6832 KB Output is correct
50 Correct 179 ms 26092 KB Output is correct
51 Correct 185 ms 26068 KB Output is correct
52 Correct 192 ms 26196 KB Output is correct
53 Correct 78 ms 16100 KB Output is correct
54 Correct 77 ms 16112 KB Output is correct
55 Correct 177 ms 26040 KB Output is correct
56 Correct 187 ms 26064 KB Output is correct
57 Correct 72 ms 16124 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 1 ms 300 KB Output is correct
60 Correct 5 ms 956 KB Output is correct
61 Correct 83 ms 16320 KB Output is correct
62 Correct 1 ms 212 KB Output is correct
63 Incorrect 1 ms 212 KB Too many ways to get from 0 to 9, should be 1 found no less than 2
64 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 0 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 8 ms 1148 KB Output is correct
7 Correct 173 ms 22180 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 7 ms 1180 KB Output is correct
13 Correct 175 ms 22096 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 296 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 83 ms 12260 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 49 ms 5836 KB Output is correct
21 Correct 179 ms 22060 KB Output is correct
22 Correct 172 ms 22108 KB Output is correct
23 Correct 189 ms 22160 KB Output is correct
24 Correct 175 ms 22068 KB Output is correct
25 Correct 71 ms 12212 KB Output is correct
26 Correct 69 ms 12260 KB Output is correct
27 Correct 187 ms 22068 KB Output is correct
28 Correct 174 ms 22324 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 296 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 296 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 8 ms 1212 KB Output is correct
37 Correct 173 ms 22132 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 8 ms 1420 KB Output is correct
41 Correct 183 ms 26032 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 304 KB Output is correct
44 Correct 4 ms 956 KB Output is correct
45 Correct 86 ms 16156 KB Output is correct
46 Correct 1 ms 300 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 296 KB Output is correct
49 Correct 46 ms 6832 KB Output is correct
50 Correct 179 ms 26092 KB Output is correct
51 Correct 185 ms 26068 KB Output is correct
52 Correct 192 ms 26196 KB Output is correct
53 Correct 78 ms 16100 KB Output is correct
54 Correct 77 ms 16112 KB Output is correct
55 Correct 177 ms 26040 KB Output is correct
56 Correct 187 ms 26064 KB Output is correct
57 Correct 72 ms 16124 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 1 ms 212 KB Output is correct
61 Correct 48 ms 5892 KB Output is correct
62 Correct 187 ms 22100 KB Output is correct
63 Correct 174 ms 22124 KB Output is correct
64 Correct 189 ms 22180 KB Output is correct
65 Correct 0 ms 212 KB Output is correct
66 Correct 46 ms 6796 KB Output is correct
67 Correct 182 ms 26016 KB Output is correct
68 Correct 179 ms 26128 KB Output is correct
69 Correct 189 ms 26076 KB Output is correct
70 Correct 1 ms 296 KB Output is correct
71 Incorrect 1 ms 212 KB Too many ways to get from 4 to 8, should be 1 found no less than 2
72 Halted 0 ms 0 KB -