Submission #576213

# Submission time Handle Problem Language Result Execution time Memory
576213 2022-06-12T14:01:13 Z MadokaMagicaFan Connecting Supertrees (IOI20_supertrees) C++14
100 / 100
224 ms 24084 KB
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vi = vector<int>;
using pi = pair<int,int>;

#define all(v)          v.begin(),v.end()
#define sort(v)         sort(all(v))
#define endl            '\n'
#define forn(i,n)       for(int i = 0; i < n; ++i)
#define forbe(i,b,e)    for(int i = b; i < e; ++i)
#define forr(i,n)       for(int i = n-1; i >= 0; --i)
#define sz(v)           ((int)v.size())
#define pb              push_back
#define f               first
#define s               second

void build(vector<vi> b);

const int N = 1e3;
int par[N];
int lst[N];
int siz[N];

int lastpar[N];

vi adj[N];

int getp(int x) { return par[x] = (par[x] == x ? x : getp(par[x])); }
int getl(int x) { return lst[x] = (lst[x] == x ? x : getl(lst[x])); }

int uni(int a, int b) {
    a = getp(a);
    b = getp(b);
    int c = getl(a);
    int d = getl(b);
    if (a == b) return 0;

    adj[a].pb(d);
    adj[d].pb(a);

    par[a] = b;
    lst[d] = c;
    siz[b] += siz[a];
    return 1;
}

int construct(vector<vi> p) {
    int n = sz(p);

    bool t0, t1, t2;
    t0 = t1 = t2 = 0;
    int task = 0;
    forn(i,n) {
        forn(j,n) {
            if (i == j) continue;
            if (p[i][j] == 0) t0 = 1;
            if (p[i][j] == 1) t1 = 1;
            if (p[i][j] == 2) t2 = 1;
            if (p[i][j] == 3) return 0;
        }
    }

    if (t1 && !t2)  task = 1;
    if (t2 && !t1)  task = 2;
    if (t2 && t1)   task = 3;

    forn(i,n) par[i] = i;
    forn(i,n) lst[i] = i;
    forn(i,n) siz[i] = 1;

    vector<vi> ans(n);
    forn(i,n)
        ans[i].assign(n,0);
    if (task < 3) {
        forn(i,n) {
            forn(j,n) {
                if (i == j) continue;

                if (p[i][j])
                    uni(i,j);
            }
        }

        forn(i,n) {
            forn(j,n) {
                if (i == j) continue;

                if (p[i][j] == 0 && getp(i) == getp(j))
                    return 0;
            }
        }


        if (task == 2) {
            forn (i, n) {
                if (getp(i) != i) continue;
                if (siz[i] == 2) return 0;
                if (siz[i] == 1) continue;
                adj[i].pb(getl(i));
                adj[getl(i)].pb(i);
            }
        }
    } else {
        forn(i,n) {
            forn(j,n) {
                if (i == j) continue;
                if (p[i][j] == 1) uni(i,j);
            }
        }

        forn(i,n) {
            lastpar[i] = getp(i);
            if (getp(i) != i) continue;
            lst[i] = i;
            siz[i] = 1;
        }

        forn(i,n) {
            forn(j,n) {
                if (i == j) continue;
                if (p[i][j] == 2) uni(i,j);
            }
        }

        forn (i, n) {
            if (getp(i) != i) continue;
            if (siz[i] == 2) return 0;
            if (siz[i] == 1) continue;
            adj[i].pb(getl(i));
            adj[getl(i)].pb(i);
        }

        forn(i,n) {
            forn(j,n) {
                if (p[lastpar[i]][lastpar[j]] == 2 && p[i][j] != 2) return 0;
                if (i == j) continue;

                if (p[i][j] == 0 && getp(i) == getp(j)) return 0;
                if (p[i][j] >= 1 && getp(i) != getp(j)) return 0;
            }
        }
    }

    forn (i,n) {
        for (int u : adj[i])
            ans[i][u] = 1;
    }

    build(ans);

    return 1;
}

#ifdef ONPC
void build(vector<vi> b) {
    
}

void solve() {
}

int main() {
//    freopen("in", "r", stdin);
//    ios_base::sync_with_stdio(0);cin.tie(0);
    solve();
}
#endif

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:53:10: warning: variable 't0' set but not used [-Wunused-but-set-variable]
   53 |     bool t0, t1, t2;
      |          ^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 324 KB Output is correct
6 Correct 9 ms 1240 KB Output is correct
7 Correct 181 ms 24076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 324 KB Output is correct
6 Correct 9 ms 1240 KB Output is correct
7 Correct 181 ms 24076 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 7 ms 1208 KB Output is correct
13 Correct 167 ms 23952 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 328 KB Output is correct
16 Correct 5 ms 852 KB Output is correct
17 Correct 102 ms 14096 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 44 ms 6272 KB Output is correct
21 Correct 196 ms 23956 KB Output is correct
22 Correct 171 ms 24016 KB Output is correct
23 Correct 203 ms 23956 KB Output is correct
24 Correct 182 ms 24012 KB Output is correct
25 Correct 101 ms 14112 KB Output is correct
26 Correct 77 ms 14096 KB Output is correct
27 Correct 194 ms 24076 KB Output is correct
28 Correct 168 ms 23968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 244 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 8 ms 1288 KB Output is correct
9 Correct 163 ms 23936 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 10 ms 1248 KB Output is correct
13 Correct 188 ms 24072 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 5 ms 848 KB Output is correct
17 Correct 107 ms 14104 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 380 KB Output is correct
21 Correct 44 ms 6216 KB Output is correct
22 Correct 213 ms 23956 KB Output is correct
23 Correct 170 ms 23996 KB Output is correct
24 Correct 200 ms 23984 KB Output is correct
25 Correct 69 ms 14108 KB Output is correct
26 Correct 84 ms 14096 KB Output is correct
27 Correct 172 ms 23988 KB Output is correct
28 Correct 224 ms 24020 KB Output is correct
29 Correct 71 ms 14108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 49 ms 6256 KB Output is correct
5 Correct 187 ms 24028 KB Output is correct
6 Correct 178 ms 23956 KB Output is correct
7 Correct 202 ms 24032 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 46 ms 6284 KB Output is correct
10 Correct 185 ms 24008 KB Output is correct
11 Correct 187 ms 23952 KB Output is correct
12 Correct 206 ms 24084 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 45 ms 6296 KB Output is correct
17 Correct 178 ms 23964 KB Output is correct
18 Correct 177 ms 23960 KB Output is correct
19 Correct 175 ms 24068 KB Output is correct
20 Correct 176 ms 23956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 324 KB Output is correct
6 Correct 9 ms 1240 KB Output is correct
7 Correct 181 ms 24076 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 7 ms 1208 KB Output is correct
13 Correct 167 ms 23952 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 328 KB Output is correct
16 Correct 5 ms 852 KB Output is correct
17 Correct 102 ms 14096 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 44 ms 6272 KB Output is correct
21 Correct 196 ms 23956 KB Output is correct
22 Correct 171 ms 24016 KB Output is correct
23 Correct 203 ms 23956 KB Output is correct
24 Correct 182 ms 24012 KB Output is correct
25 Correct 101 ms 14112 KB Output is correct
26 Correct 77 ms 14096 KB Output is correct
27 Correct 194 ms 24076 KB Output is correct
28 Correct 168 ms 23968 KB Output is correct
29 Correct 1 ms 324 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 244 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 8 ms 1288 KB Output is correct
37 Correct 163 ms 23936 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 10 ms 1248 KB Output is correct
41 Correct 188 ms 24072 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 5 ms 848 KB Output is correct
45 Correct 107 ms 14104 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 0 ms 340 KB Output is correct
48 Correct 1 ms 380 KB Output is correct
49 Correct 44 ms 6216 KB Output is correct
50 Correct 213 ms 23956 KB Output is correct
51 Correct 170 ms 23996 KB Output is correct
52 Correct 200 ms 23984 KB Output is correct
53 Correct 69 ms 14108 KB Output is correct
54 Correct 84 ms 14096 KB Output is correct
55 Correct 172 ms 23988 KB Output is correct
56 Correct 224 ms 24020 KB Output is correct
57 Correct 71 ms 14108 KB Output is correct
58 Correct 1 ms 328 KB Output is correct
59 Correct 0 ms 340 KB Output is correct
60 Correct 5 ms 852 KB Output is correct
61 Correct 103 ms 14232 KB Output is correct
62 Correct 1 ms 324 KB Output is correct
63 Correct 1 ms 340 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
65 Correct 61 ms 6272 KB Output is correct
66 Correct 73 ms 14156 KB Output is correct
67 Correct 74 ms 14160 KB Output is correct
68 Correct 70 ms 14096 KB Output is correct
69 Correct 74 ms 14028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 324 KB Output is correct
6 Correct 9 ms 1240 KB Output is correct
7 Correct 181 ms 24076 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 7 ms 1208 KB Output is correct
13 Correct 167 ms 23952 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 328 KB Output is correct
16 Correct 5 ms 852 KB Output is correct
17 Correct 102 ms 14096 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 44 ms 6272 KB Output is correct
21 Correct 196 ms 23956 KB Output is correct
22 Correct 171 ms 24016 KB Output is correct
23 Correct 203 ms 23956 KB Output is correct
24 Correct 182 ms 24012 KB Output is correct
25 Correct 101 ms 14112 KB Output is correct
26 Correct 77 ms 14096 KB Output is correct
27 Correct 194 ms 24076 KB Output is correct
28 Correct 168 ms 23968 KB Output is correct
29 Correct 1 ms 324 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 244 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 8 ms 1288 KB Output is correct
37 Correct 163 ms 23936 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 10 ms 1248 KB Output is correct
41 Correct 188 ms 24072 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 5 ms 848 KB Output is correct
45 Correct 107 ms 14104 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 0 ms 340 KB Output is correct
48 Correct 1 ms 380 KB Output is correct
49 Correct 44 ms 6216 KB Output is correct
50 Correct 213 ms 23956 KB Output is correct
51 Correct 170 ms 23996 KB Output is correct
52 Correct 200 ms 23984 KB Output is correct
53 Correct 69 ms 14108 KB Output is correct
54 Correct 84 ms 14096 KB Output is correct
55 Correct 172 ms 23988 KB Output is correct
56 Correct 224 ms 24020 KB Output is correct
57 Correct 71 ms 14108 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 0 ms 340 KB Output is correct
61 Correct 49 ms 6256 KB Output is correct
62 Correct 187 ms 24028 KB Output is correct
63 Correct 178 ms 23956 KB Output is correct
64 Correct 202 ms 24032 KB Output is correct
65 Correct 1 ms 332 KB Output is correct
66 Correct 46 ms 6284 KB Output is correct
67 Correct 185 ms 24008 KB Output is correct
68 Correct 187 ms 23952 KB Output is correct
69 Correct 206 ms 24084 KB Output is correct
70 Correct 1 ms 340 KB Output is correct
71 Correct 1 ms 340 KB Output is correct
72 Correct 1 ms 212 KB Output is correct
73 Correct 45 ms 6296 KB Output is correct
74 Correct 178 ms 23964 KB Output is correct
75 Correct 177 ms 23960 KB Output is correct
76 Correct 175 ms 24068 KB Output is correct
77 Correct 176 ms 23956 KB Output is correct
78 Correct 1 ms 328 KB Output is correct
79 Correct 0 ms 340 KB Output is correct
80 Correct 5 ms 852 KB Output is correct
81 Correct 103 ms 14232 KB Output is correct
82 Correct 1 ms 324 KB Output is correct
83 Correct 1 ms 340 KB Output is correct
84 Correct 1 ms 340 KB Output is correct
85 Correct 61 ms 6272 KB Output is correct
86 Correct 73 ms 14156 KB Output is correct
87 Correct 74 ms 14160 KB Output is correct
88 Correct 70 ms 14096 KB Output is correct
89 Correct 74 ms 14028 KB Output is correct
90 Correct 1 ms 212 KB Output is correct
91 Correct 1 ms 328 KB Output is correct
92 Correct 3 ms 720 KB Output is correct
93 Correct 72 ms 10136 KB Output is correct
94 Correct 0 ms 324 KB Output is correct
95 Correct 1 ms 212 KB Output is correct
96 Correct 1 ms 212 KB Output is correct
97 Correct 17 ms 2704 KB Output is correct
98 Correct 68 ms 10128 KB Output is correct
99 Correct 74 ms 10124 KB Output is correct
100 Correct 67 ms 10188 KB Output is correct
101 Correct 65 ms 10132 KB Output is correct
102 Correct 72 ms 10128 KB Output is correct
103 Correct 66 ms 10060 KB Output is correct
104 Correct 67 ms 10132 KB Output is correct
105 Correct 77 ms 10056 KB Output is correct