Submission #479901

# Submission time Handle Problem Language Result Execution time Memory
479901 2021-10-13T19:51:14 Z couplefire Connecting Supertrees (IOI20_supertrees) C++17
100 / 100
282 ms 24752 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;

struct DSU{
    int n; vector<int> fa, siz;
    vector<vector<int>> comps;
    void init(int _n){
        n = _n;
        fa.resize(n); siz.assign(n, 1);
        iota(fa.begin(), fa.end(), 0);
        comps.resize(n);
        for(int i = 0; i<n; ++i)
            comps[i].push_back(i);
    }
    int find(int v){return v==fa[v]?v:fa[v]=find(fa[v]);}
    void unite(int u, int v){
        u = find(u), v =find(v);
        if(u==v) return;
        if(siz[u]>siz[v]) swap(u, v);
        for(auto x : comps[u])
            comps[v].push_back(x);
        comps[u].clear(); fa[u] = v;
    }
};

int construct(vector<vector<int>> paths){
    int n = paths.size();
    DSU d1; d1.init(n);
    for(int i = 0; i<n; ++i)
        for(int j = i+1; j<n; ++j)
            if(paths[i][j]==3) return 0;
    for(int i = 0; i<n; ++i)
        for(int j = i+1; j<n; ++j)
            if(paths[i][j]) d1.unite(i, j);
    vector<vector<int>> res(n, vector<int>(n, 0));
    for(auto c : d1.comps){
        if(c.empty()) continue;
        int m = c.size();
        for(int i = 0; i<m; ++i)
            for(int j = i+1; j<m; ++j)
                if(!paths[c[i]][c[j]]) return 0;
        DSU d2; d2.init(m);
        for(int i = 0; i<m; ++i)
            for(int j = i+1; j<m; ++j)
                if(paths[c[i]][c[j]]==1) d2.unite(i, j);
        for(auto x : d2.comps)
            for(int i = 0; i<x.size(); ++i)
                for(int j = i+1; j<x.size(); ++j)
                    if(paths[c[x[i]]][c[x[j]]]!=1) return 0;
        vector<int> good;
        for(auto x : d2.comps){
            if(!x.size()) continue;
            good.push_back(c[x[0]]);
            for(int i = 0; i<(int)x.size()-1; ++i)
                res[c[x[i]]][c[x[i+1]]] = res[c[x[i+1]]][c[x[i]]] = 1;
        }
        if((int)good.size()==1) continue;
        if((int)good.size()==2) return 0;
        good.push_back(good[0]);
        for(int i = 0; i<(int)good.size()-1; ++i)
            res[good[i]][good[i+1]] = res[good[i+1]][good[i]] = 1;
    }
    build(res); return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:48:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |             for(int i = 0; i<x.size(); ++i)
      |                            ~^~~~~~~~~
supertrees.cpp:49:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |                 for(int j = i+1; j<x.size(); ++j)
      |                                  ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 10 ms 1228 KB Output is correct
7 Correct 282 ms 24664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 10 ms 1228 KB Output is correct
7 Correct 282 ms 24664 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 8 ms 1156 KB Output is correct
13 Correct 186 ms 22076 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 4 ms 844 KB Output is correct
17 Correct 90 ms 14716 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 50 ms 5792 KB Output is correct
21 Correct 219 ms 22340 KB Output is correct
22 Correct 180 ms 22092 KB Output is correct
23 Correct 202 ms 23472 KB Output is correct
24 Correct 176 ms 22084 KB Output is correct
25 Correct 86 ms 12612 KB Output is correct
26 Correct 83 ms 12148 KB Output is correct
27 Correct 202 ms 23456 KB Output is correct
28 Correct 192 ms 22252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 11 ms 1216 KB Output is correct
9 Correct 203 ms 22012 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 10 ms 1304 KB Output is correct
13 Correct 202 ms 24752 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 5 ms 844 KB Output is correct
17 Correct 101 ms 14724 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 49 ms 5760 KB Output is correct
22 Correct 211 ms 22280 KB Output is correct
23 Correct 177 ms 22020 KB Output is correct
24 Correct 194 ms 23432 KB Output is correct
25 Correct 70 ms 12152 KB Output is correct
26 Correct 77 ms 12484 KB Output is correct
27 Correct 179 ms 22084 KB Output is correct
28 Correct 202 ms 23356 KB Output is correct
29 Correct 72 ms 12072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 60 ms 5756 KB Output is correct
5 Correct 185 ms 22348 KB Output is correct
6 Correct 182 ms 22028 KB Output is correct
7 Correct 201 ms 23340 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 46 ms 5700 KB Output is correct
10 Correct 201 ms 22280 KB Output is correct
11 Correct 196 ms 22084 KB Output is correct
12 Correct 200 ms 23336 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 55 ms 5720 KB Output is correct
17 Correct 215 ms 22292 KB Output is correct
18 Correct 203 ms 22340 KB Output is correct
19 Correct 207 ms 22112 KB Output is correct
20 Correct 188 ms 22084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 10 ms 1228 KB Output is correct
7 Correct 282 ms 24664 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 8 ms 1156 KB Output is correct
13 Correct 186 ms 22076 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 4 ms 844 KB Output is correct
17 Correct 90 ms 14716 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 50 ms 5792 KB Output is correct
21 Correct 219 ms 22340 KB Output is correct
22 Correct 180 ms 22092 KB Output is correct
23 Correct 202 ms 23472 KB Output is correct
24 Correct 176 ms 22084 KB Output is correct
25 Correct 86 ms 12612 KB Output is correct
26 Correct 83 ms 12148 KB Output is correct
27 Correct 202 ms 23456 KB Output is correct
28 Correct 192 ms 22252 KB Output is correct
29 Correct 0 ms 204 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 0 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 11 ms 1216 KB Output is correct
37 Correct 203 ms 22012 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 0 ms 204 KB Output is correct
40 Correct 10 ms 1304 KB Output is correct
41 Correct 202 ms 24752 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 0 ms 204 KB Output is correct
44 Correct 5 ms 844 KB Output is correct
45 Correct 101 ms 14724 KB Output is correct
46 Correct 0 ms 204 KB Output is correct
47 Correct 0 ms 204 KB Output is correct
48 Correct 0 ms 204 KB Output is correct
49 Correct 49 ms 5760 KB Output is correct
50 Correct 211 ms 22280 KB Output is correct
51 Correct 177 ms 22020 KB Output is correct
52 Correct 194 ms 23432 KB Output is correct
53 Correct 70 ms 12152 KB Output is correct
54 Correct 77 ms 12484 KB Output is correct
55 Correct 179 ms 22084 KB Output is correct
56 Correct 202 ms 23356 KB Output is correct
57 Correct 72 ms 12072 KB Output is correct
58 Correct 0 ms 204 KB Output is correct
59 Correct 0 ms 204 KB Output is correct
60 Correct 4 ms 844 KB Output is correct
61 Correct 92 ms 14712 KB Output is correct
62 Correct 1 ms 204 KB Output is correct
63 Correct 0 ms 204 KB Output is correct
64 Correct 1 ms 204 KB Output is correct
65 Correct 62 ms 5740 KB Output is correct
66 Correct 90 ms 12484 KB Output is correct
67 Correct 97 ms 12424 KB Output is correct
68 Correct 75 ms 12300 KB Output is correct
69 Correct 73 ms 12168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 10 ms 1228 KB Output is correct
7 Correct 282 ms 24664 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 8 ms 1156 KB Output is correct
13 Correct 186 ms 22076 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 4 ms 844 KB Output is correct
17 Correct 90 ms 14716 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 50 ms 5792 KB Output is correct
21 Correct 219 ms 22340 KB Output is correct
22 Correct 180 ms 22092 KB Output is correct
23 Correct 202 ms 23472 KB Output is correct
24 Correct 176 ms 22084 KB Output is correct
25 Correct 86 ms 12612 KB Output is correct
26 Correct 83 ms 12148 KB Output is correct
27 Correct 202 ms 23456 KB Output is correct
28 Correct 192 ms 22252 KB Output is correct
29 Correct 0 ms 204 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 0 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 11 ms 1216 KB Output is correct
37 Correct 203 ms 22012 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 0 ms 204 KB Output is correct
40 Correct 10 ms 1304 KB Output is correct
41 Correct 202 ms 24752 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 0 ms 204 KB Output is correct
44 Correct 5 ms 844 KB Output is correct
45 Correct 101 ms 14724 KB Output is correct
46 Correct 0 ms 204 KB Output is correct
47 Correct 0 ms 204 KB Output is correct
48 Correct 0 ms 204 KB Output is correct
49 Correct 49 ms 5760 KB Output is correct
50 Correct 211 ms 22280 KB Output is correct
51 Correct 177 ms 22020 KB Output is correct
52 Correct 194 ms 23432 KB Output is correct
53 Correct 70 ms 12152 KB Output is correct
54 Correct 77 ms 12484 KB Output is correct
55 Correct 179 ms 22084 KB Output is correct
56 Correct 202 ms 23356 KB Output is correct
57 Correct 72 ms 12072 KB Output is correct
58 Correct 0 ms 204 KB Output is correct
59 Correct 1 ms 204 KB Output is correct
60 Correct 0 ms 204 KB Output is correct
61 Correct 60 ms 5756 KB Output is correct
62 Correct 185 ms 22348 KB Output is correct
63 Correct 182 ms 22028 KB Output is correct
64 Correct 201 ms 23340 KB Output is correct
65 Correct 1 ms 204 KB Output is correct
66 Correct 46 ms 5700 KB Output is correct
67 Correct 201 ms 22280 KB Output is correct
68 Correct 196 ms 22084 KB Output is correct
69 Correct 200 ms 23336 KB Output is correct
70 Correct 0 ms 204 KB Output is correct
71 Correct 1 ms 204 KB Output is correct
72 Correct 1 ms 204 KB Output is correct
73 Correct 55 ms 5720 KB Output is correct
74 Correct 215 ms 22292 KB Output is correct
75 Correct 203 ms 22340 KB Output is correct
76 Correct 207 ms 22112 KB Output is correct
77 Correct 188 ms 22084 KB Output is correct
78 Correct 0 ms 204 KB Output is correct
79 Correct 0 ms 204 KB Output is correct
80 Correct 4 ms 844 KB Output is correct
81 Correct 92 ms 14712 KB Output is correct
82 Correct 1 ms 204 KB Output is correct
83 Correct 0 ms 204 KB Output is correct
84 Correct 1 ms 204 KB Output is correct
85 Correct 62 ms 5740 KB Output is correct
86 Correct 90 ms 12484 KB Output is correct
87 Correct 97 ms 12424 KB Output is correct
88 Correct 75 ms 12300 KB Output is correct
89 Correct 73 ms 12168 KB Output is correct
90 Correct 0 ms 204 KB Output is correct
91 Correct 0 ms 204 KB Output is correct
92 Correct 3 ms 588 KB Output is correct
93 Correct 82 ms 8184 KB Output is correct
94 Correct 1 ms 204 KB Output is correct
95 Correct 0 ms 204 KB Output is correct
96 Correct 1 ms 204 KB Output is correct
97 Correct 18 ms 2764 KB Output is correct
98 Correct 77 ms 10092 KB Output is correct
99 Correct 88 ms 10092 KB Output is correct
100 Correct 87 ms 10180 KB Output is correct
101 Correct 78 ms 10108 KB Output is correct
102 Correct 76 ms 10092 KB Output is correct
103 Correct 87 ms 10092 KB Output is correct
104 Correct 76 ms 10092 KB Output is correct
105 Correct 97 ms 10104 KB Output is correct