Submission #800217

# Submission time Handle Problem Language Result Execution time Memory
800217 2023-08-01T12:10:44 Z TimDee Connecting Supertrees (IOI20_supertrees) C++17
100 / 100
207 ms 22140 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for(int i=0;i<n;++i)
#define all(x) x.begin(),x.end()
#define pb push_back
#define pi pair<int,int>
#define f first
#define s second
using ll = long long;

struct DSU {
    vector<int> p,sz;
    DSU(int n) {
        forn(i,n) p.pb(i), sz.pb(1);
    }
    int get(int u) {
        return p[u]==u?u:get(p[u]);
    }
    void uni(int u, int v) {
        u=get(u), v=get(v);
        if (u==v) return;
        if (sz[u]<sz[v]) swap(u,v);
        sz[u]+=sz[v];
        p[v]=u;
    }
};

int construct(vector<vector<int>> p) {
    int n=p.size();
    DSU dsu(n);
    forn(i,n) forn(j,n) if (p[i][j]) dsu.uni(i,j);
    vector<vector<int>> v(n);
    forn(i,n) v[dsu.get(i)].pb(i);

    vector<vector<int>> ans(n,vector<int>(n,0));

    forn(i,n) {
        if (!v[i].size()) continue;
        if (v[i].size()==1) continue;
        DSU dsu2(n);
        for(auto&x:v[i]) {
            for(auto&y:v[i]) {
                if (p[x][y]==1) dsu2.uni(x,y);
                if (p[x][y]==0) return 0;
            }
        }
        for(auto&x:v[i]) {
            for(auto&y:v[i]) {
                if (dsu2.get(x)==dsu2.get(y)) {
                    if (p[x][y]!=1) return 0;
                }
            }
        }
        vector<vector<int>> u(n);
        for(auto&x:v[i]) u[dsu2.get(x)].pb(x);

        forn(j,n) {
            if (!u[j].size()) continue;
            if (u[j].size()==1) continue;
            forn(k,u[j].size()-1) ans[u[j][k]][u[j][k+1]]=ans[u[j][k+1]][u[j][k]]=1;
        }

        vector<int> two;
        for(auto&x:v[i]) {
            if (x!=u[dsu2.get(x)].back()) continue;
            int z=3;
            for(auto&y:v[i]) {
                if (dsu2.get(x)==dsu2.get(y)) continue;
                if (p[x][y]!=2) return 0;
                z&=p[x][y]==2;
            }
            if (z==1) two.pb(x);
        }
        if (two.size()>0 && two.size()<3) return 0;
        forn(j,two.size()) {
            ans[two[j]][two[(j+1)%two.size()]]=ans[two[(j+1)%two.size()]][two[j]]=1;
        }
    }

    build(ans);

    return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:4:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define forn(i,n) for(int i=0;i<n;++i)
......
   61 |             forn(k,u[j].size()-1) ans[u[j][k]][u[j][k+1]]=ans[u[j][k+1]][u[j][k]]=1;
      |                  ~~~~~~~~~~~~~~~
supertrees.cpp:61:13: note: in expansion of macro 'forn'
   61 |             forn(k,u[j].size()-1) ans[u[j][k]][u[j][k+1]]=ans[u[j][k+1]][u[j][k]]=1;
      |             ^~~~
supertrees.cpp:4:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define forn(i,n) for(int i=0;i<n;++i)
......
   76 |         forn(j,two.size()) {
      |              ~~~~~~~~~~~~       
supertrees.cpp:76:9: note: in expansion of macro 'forn'
   76 |         forn(j,two.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 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1100 KB Output is correct
7 Correct 174 ms 22072 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 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1100 KB Output is correct
7 Correct 174 ms 22072 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 8 ms 1108 KB Output is correct
13 Correct 167 ms 22016 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 712 KB Output is correct
17 Correct 77 ms 12164 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 52 ms 5736 KB Output is correct
21 Correct 174 ms 22068 KB Output is correct
22 Correct 171 ms 22020 KB Output is correct
23 Correct 187 ms 22052 KB Output is correct
24 Correct 175 ms 22032 KB Output is correct
25 Correct 71 ms 12108 KB Output is correct
26 Correct 70 ms 12164 KB Output is correct
27 Correct 174 ms 21996 KB Output is correct
28 Correct 166 ms 22024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 0 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 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 7 ms 1108 KB Output is correct
9 Correct 171 ms 22076 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 170 ms 22028 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 724 KB Output is correct
17 Correct 78 ms 12164 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 42 ms 5732 KB Output is correct
22 Correct 182 ms 22020 KB Output is correct
23 Correct 207 ms 22092 KB Output is correct
24 Correct 174 ms 22004 KB Output is correct
25 Correct 70 ms 12164 KB Output is correct
26 Correct 73 ms 12172 KB Output is correct
27 Correct 169 ms 22092 KB Output is correct
28 Correct 172 ms 21984 KB Output is correct
29 Correct 71 ms 12164 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 42 ms 5708 KB Output is correct
5 Correct 169 ms 22016 KB Output is correct
6 Correct 185 ms 22140 KB Output is correct
7 Correct 182 ms 22020 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 42 ms 5764 KB Output is correct
10 Correct 171 ms 22108 KB Output is correct
11 Correct 168 ms 22040 KB Output is correct
12 Correct 172 ms 22016 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 42 ms 5760 KB Output is correct
17 Correct 169 ms 22028 KB Output is correct
18 Correct 168 ms 22092 KB Output is correct
19 Correct 171 ms 21992 KB Output is correct
20 Correct 172 ms 22052 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 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1100 KB Output is correct
7 Correct 174 ms 22072 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 8 ms 1108 KB Output is correct
13 Correct 167 ms 22016 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 712 KB Output is correct
17 Correct 77 ms 12164 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 52 ms 5736 KB Output is correct
21 Correct 174 ms 22068 KB Output is correct
22 Correct 171 ms 22020 KB Output is correct
23 Correct 187 ms 22052 KB Output is correct
24 Correct 175 ms 22032 KB Output is correct
25 Correct 71 ms 12108 KB Output is correct
26 Correct 70 ms 12164 KB Output is correct
27 Correct 174 ms 21996 KB Output is correct
28 Correct 166 ms 22024 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 2 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 7 ms 1108 KB Output is correct
37 Correct 171 ms 22076 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 7 ms 1108 KB Output is correct
41 Correct 170 ms 22028 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 4 ms 724 KB Output is correct
45 Correct 78 ms 12164 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 42 ms 5732 KB Output is correct
50 Correct 182 ms 22020 KB Output is correct
51 Correct 207 ms 22092 KB Output is correct
52 Correct 174 ms 22004 KB Output is correct
53 Correct 70 ms 12164 KB Output is correct
54 Correct 73 ms 12172 KB Output is correct
55 Correct 169 ms 22092 KB Output is correct
56 Correct 172 ms 21984 KB Output is correct
57 Correct 71 ms 12164 KB Output is correct
58 Correct 0 ms 212 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 3 ms 724 KB Output is correct
61 Correct 75 ms 12176 KB Output is correct
62 Correct 0 ms 212 KB Output is correct
63 Correct 0 ms 212 KB Output is correct
64 Correct 0 ms 212 KB Output is correct
65 Correct 42 ms 5756 KB Output is correct
66 Correct 71 ms 12172 KB Output is correct
67 Correct 71 ms 12172 KB Output is correct
68 Correct 71 ms 12164 KB Output is correct
69 Correct 70 ms 12172 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 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1100 KB Output is correct
7 Correct 174 ms 22072 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 8 ms 1108 KB Output is correct
13 Correct 167 ms 22016 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 712 KB Output is correct
17 Correct 77 ms 12164 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 52 ms 5736 KB Output is correct
21 Correct 174 ms 22068 KB Output is correct
22 Correct 171 ms 22020 KB Output is correct
23 Correct 187 ms 22052 KB Output is correct
24 Correct 175 ms 22032 KB Output is correct
25 Correct 71 ms 12108 KB Output is correct
26 Correct 70 ms 12164 KB Output is correct
27 Correct 174 ms 21996 KB Output is correct
28 Correct 166 ms 22024 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 2 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 7 ms 1108 KB Output is correct
37 Correct 171 ms 22076 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 7 ms 1108 KB Output is correct
41 Correct 170 ms 22028 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 4 ms 724 KB Output is correct
45 Correct 78 ms 12164 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 42 ms 5732 KB Output is correct
50 Correct 182 ms 22020 KB Output is correct
51 Correct 207 ms 22092 KB Output is correct
52 Correct 174 ms 22004 KB Output is correct
53 Correct 70 ms 12164 KB Output is correct
54 Correct 73 ms 12172 KB Output is correct
55 Correct 169 ms 22092 KB Output is correct
56 Correct 172 ms 21984 KB Output is correct
57 Correct 71 ms 12164 KB Output is correct
58 Correct 0 ms 212 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 0 ms 212 KB Output is correct
61 Correct 42 ms 5708 KB Output is correct
62 Correct 169 ms 22016 KB Output is correct
63 Correct 185 ms 22140 KB Output is correct
64 Correct 182 ms 22020 KB Output is correct
65 Correct 0 ms 212 KB Output is correct
66 Correct 42 ms 5764 KB Output is correct
67 Correct 171 ms 22108 KB Output is correct
68 Correct 168 ms 22040 KB Output is correct
69 Correct 172 ms 22016 KB Output is correct
70 Correct 0 ms 212 KB Output is correct
71 Correct 0 ms 212 KB Output is correct
72 Correct 0 ms 212 KB Output is correct
73 Correct 42 ms 5760 KB Output is correct
74 Correct 169 ms 22028 KB Output is correct
75 Correct 168 ms 22092 KB Output is correct
76 Correct 171 ms 21992 KB Output is correct
77 Correct 172 ms 22052 KB Output is correct
78 Correct 0 ms 212 KB Output is correct
79 Correct 0 ms 212 KB Output is correct
80 Correct 3 ms 724 KB Output is correct
81 Correct 75 ms 12176 KB Output is correct
82 Correct 0 ms 212 KB Output is correct
83 Correct 0 ms 212 KB Output is correct
84 Correct 0 ms 212 KB Output is correct
85 Correct 42 ms 5756 KB Output is correct
86 Correct 71 ms 12172 KB Output is correct
87 Correct 71 ms 12172 KB Output is correct
88 Correct 71 ms 12164 KB Output is correct
89 Correct 70 ms 12172 KB Output is correct
90 Correct 0 ms 212 KB Output is correct
91 Correct 0 ms 212 KB Output is correct
92 Correct 3 ms 724 KB Output is correct
93 Correct 74 ms 12164 KB Output is correct
94 Correct 0 ms 212 KB Output is correct
95 Correct 0 ms 212 KB Output is correct
96 Correct 0 ms 212 KB Output is correct
97 Correct 18 ms 3216 KB Output is correct
98 Correct 73 ms 12176 KB Output is correct
99 Correct 71 ms 12160 KB Output is correct
100 Correct 71 ms 12164 KB Output is correct
101 Correct 70 ms 12164 KB Output is correct
102 Correct 68 ms 12180 KB Output is correct
103 Correct 68 ms 12164 KB Output is correct
104 Correct 83 ms 12236 KB Output is correct
105 Correct 78 ms 12164 KB Output is correct