Submission #550685

# Submission time Handle Problem Language Result Execution time Memory
550685 2022-04-18T19:59:58 Z Bogdan1110 Connecting Supertrees (IOI20_supertrees) C++14
100 / 100
228 ms 24140 KB
#include <bits/stdc++.h>
#include "supertrees.h"
#define FAST {ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
#define ll long long
#define ull unsigned long long
#define pb push_back
#define fi first
#define se second
#define ld long double
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(a) (a).begin(), (a).end()
#define mp make_pair 
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key -> # less than k
// find_by_order -> k-th element
// pq max element


const double eps = 0.00000001;
const int NMAX = 200010;
const ll inf = LLONG_MAX/2;
const ll modi = 1e9+7;

int rod[NMAX], sz[NMAX], odlican[NMAX];

int par(int n) { while(rod[n] != n) n = rod[n]; return n; }

bool isti(int a, int b) { return par(a) == par(b) ;}

void spoj(int a, int b) {
    if ( isti(a,b) ) return;
    int p1 = par(a);
    int p2 = par(b);
    if ( sz[p1] < sz[p2] || odlican[p2] ) {
        swap(p1,p2);
    }
    rod[p2] = p1;
    sz[p1]+=sz[p2];
}

int construct(vector<vector<int>>v) {
    int n = v.size();
    for (int i = 0 ; i < n ; i++ ) {
        sz[i] = 1;
        rod[i] = i;
        for (int j = 0 ; j < n ; j++ ) {
            if ( v[i][j] != v[j][i] || (i==j && v[i][i]!= 1) || v[i][j] == 3 ) return 0;
        }
    }
    for (int i = 0 ; i < n ; i++ ) {
        for (int j = 0 ; j < n ; j++ ) {
            if ( v[i][j] ) {
                spoj(i,j);
            }
            else {
                if ( isti(i,j) ) return 0;
            }
        }
    }

    for (int i = 0 ; i < n ; i++ ) {
        for (int j = 0 ; j < n ; j++ ) {
            if ( v[i][j] == 2 ) {
                odlican[i] = odlican[j] = 1;
            }
        }
    }

    map<int,vector<int>>mapa;
    vector<vector<int>>res(n,vector<int>(n,0));
    for (int i = 0 ; i < n ; i++ ) {
        mapa[par(i)].pb(i);
    }
    for (int i = 0 ; i < n ; i++ ){
        sz[i] = 1;
        rod[i] = i;
    }
    for (auto u : mapa) {
        vector<int>temp = u.se;
        if ( temp.size() == 1 ) continue;
        bool ima2 = false;
        for (auto e : temp) {
            for (int i = 0 ; i < n ; i++ ) {
                if ( i == e ) continue;
                if ( v[i][e] == 1 ) spoj(e,i);
                else if ( v[i][e] == 2 ) ima2 = true;
            }
        }
        if ( ima2 ) {
            set<int>razliciti;
            for (auto e:temp) {
                razliciti.insert(par(e));
            }
            //for (auto ran:razliciti) cout << ran << ' '; cout << endl;
            if ( razliciti.size() < 3 ) return 0;
            vector<int>temp2;
            for (auto e : razliciti) temp2.pb(e);
            int k = temp2.size();
            for (int i = 0; i < k ; i++ ) {
                int pov = (i+k-1)%k;
                res[temp2[i]][temp2[pov]] = res[temp2[pov]][temp2[i]] = 1;
            }
        }
        map<int,vector<int>>mapa2;

        for (auto e : temp) {
            mapa2[par(e)].pb(e);
        }
        for (auto e : mapa2) {
            vector<int>temp2 = e.se;
            for (auto k:temp2) {
                for (auto r:temp2) {
                    if ( k != r && v[k][r] != 1 ) return 0;
                }
            }
            int k = temp2.size();
            for (int i = 1 ; i < k ; i++ ) {
                int pov = (i-1)%n;
                res[temp2[i]][temp2[pov]] = res[temp2[pov]][temp2[i]] = 1;
            }
        }
    }

    build(res);

    return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 9 ms 1280 KB Output is correct
7 Correct 183 ms 23932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 9 ms 1280 KB Output is correct
7 Correct 183 ms 23932 KB Output is correct
8 Correct 1 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 10 ms 1236 KB Output is correct
13 Correct 189 ms 24028 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 5 ms 596 KB Output is correct
17 Correct 80 ms 10156 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 45 ms 6180 KB Output is correct
21 Correct 179 ms 23928 KB Output is correct
22 Correct 176 ms 23988 KB Output is correct
23 Correct 219 ms 23976 KB Output is correct
24 Correct 169 ms 24124 KB Output is correct
25 Correct 76 ms 10060 KB Output is correct
26 Correct 98 ms 10108 KB Output is correct
27 Correct 195 ms 23936 KB Output is correct
28 Correct 176 ms 24112 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 1 ms 308 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 1 ms 308 KB Output is correct
8 Correct 8 ms 1312 KB Output is correct
9 Correct 174 ms 24044 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 9 ms 1216 KB Output is correct
13 Correct 184 ms 23968 KB Output is correct
14 Correct 1 ms 308 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 5 ms 724 KB Output is correct
17 Correct 83 ms 10124 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 46 ms 6220 KB Output is correct
22 Correct 179 ms 24056 KB Output is correct
23 Correct 176 ms 24008 KB Output is correct
24 Correct 203 ms 23940 KB Output is correct
25 Correct 71 ms 14228 KB Output is correct
26 Correct 69 ms 10108 KB Output is correct
27 Correct 184 ms 24040 KB Output is correct
28 Correct 192 ms 24140 KB Output is correct
29 Correct 69 ms 14128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 304 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 45 ms 6224 KB Output is correct
5 Correct 201 ms 24072 KB Output is correct
6 Correct 195 ms 24024 KB Output is correct
7 Correct 198 ms 23944 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 52 ms 6284 KB Output is correct
10 Correct 179 ms 24080 KB Output is correct
11 Correct 185 ms 24012 KB Output is correct
12 Correct 190 ms 24012 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 44 ms 6256 KB Output is correct
17 Correct 181 ms 23980 KB Output is correct
18 Correct 228 ms 24048 KB Output is correct
19 Correct 177 ms 24044 KB Output is correct
20 Correct 173 ms 24116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 9 ms 1280 KB Output is correct
7 Correct 183 ms 23932 KB Output is correct
8 Correct 1 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 10 ms 1236 KB Output is correct
13 Correct 189 ms 24028 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 5 ms 596 KB Output is correct
17 Correct 80 ms 10156 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 45 ms 6180 KB Output is correct
21 Correct 179 ms 23928 KB Output is correct
22 Correct 176 ms 23988 KB Output is correct
23 Correct 219 ms 23976 KB Output is correct
24 Correct 169 ms 24124 KB Output is correct
25 Correct 76 ms 10060 KB Output is correct
26 Correct 98 ms 10108 KB Output is correct
27 Correct 195 ms 23936 KB Output is correct
28 Correct 176 ms 24112 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 308 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 304 KB Output is correct
35 Correct 1 ms 308 KB Output is correct
36 Correct 8 ms 1312 KB Output is correct
37 Correct 174 ms 24044 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 9 ms 1216 KB Output is correct
41 Correct 184 ms 23968 KB Output is correct
42 Correct 1 ms 308 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 5 ms 724 KB Output is correct
45 Correct 83 ms 10124 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 46 ms 6220 KB Output is correct
50 Correct 179 ms 24056 KB Output is correct
51 Correct 176 ms 24008 KB Output is correct
52 Correct 203 ms 23940 KB Output is correct
53 Correct 71 ms 14228 KB Output is correct
54 Correct 69 ms 10108 KB Output is correct
55 Correct 184 ms 24040 KB Output is correct
56 Correct 192 ms 24140 KB Output is correct
57 Correct 69 ms 14128 KB Output is correct
58 Correct 0 ms 300 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 4 ms 596 KB Output is correct
61 Correct 83 ms 10104 KB Output is correct
62 Correct 1 ms 212 KB Output is correct
63 Correct 1 ms 212 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
65 Correct 52 ms 6288 KB Output is correct
66 Correct 69 ms 10104 KB Output is correct
67 Correct 70 ms 10112 KB Output is correct
68 Correct 71 ms 10104 KB Output is correct
69 Correct 77 ms 14156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 9 ms 1280 KB Output is correct
7 Correct 183 ms 23932 KB Output is correct
8 Correct 1 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 10 ms 1236 KB Output is correct
13 Correct 189 ms 24028 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 5 ms 596 KB Output is correct
17 Correct 80 ms 10156 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 45 ms 6180 KB Output is correct
21 Correct 179 ms 23928 KB Output is correct
22 Correct 176 ms 23988 KB Output is correct
23 Correct 219 ms 23976 KB Output is correct
24 Correct 169 ms 24124 KB Output is correct
25 Correct 76 ms 10060 KB Output is correct
26 Correct 98 ms 10108 KB Output is correct
27 Correct 195 ms 23936 KB Output is correct
28 Correct 176 ms 24112 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 308 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 304 KB Output is correct
35 Correct 1 ms 308 KB Output is correct
36 Correct 8 ms 1312 KB Output is correct
37 Correct 174 ms 24044 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 9 ms 1216 KB Output is correct
41 Correct 184 ms 23968 KB Output is correct
42 Correct 1 ms 308 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 5 ms 724 KB Output is correct
45 Correct 83 ms 10124 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 46 ms 6220 KB Output is correct
50 Correct 179 ms 24056 KB Output is correct
51 Correct 176 ms 24008 KB Output is correct
52 Correct 203 ms 23940 KB Output is correct
53 Correct 71 ms 14228 KB Output is correct
54 Correct 69 ms 10108 KB Output is correct
55 Correct 184 ms 24040 KB Output is correct
56 Correct 192 ms 24140 KB Output is correct
57 Correct 69 ms 14128 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 0 ms 304 KB Output is correct
60 Correct 1 ms 212 KB Output is correct
61 Correct 45 ms 6224 KB Output is correct
62 Correct 201 ms 24072 KB Output is correct
63 Correct 195 ms 24024 KB Output is correct
64 Correct 198 ms 23944 KB Output is correct
65 Correct 1 ms 304 KB Output is correct
66 Correct 52 ms 6284 KB Output is correct
67 Correct 179 ms 24080 KB Output is correct
68 Correct 185 ms 24012 KB Output is correct
69 Correct 190 ms 24012 KB Output is correct
70 Correct 1 ms 212 KB Output is correct
71 Correct 1 ms 212 KB Output is correct
72 Correct 1 ms 212 KB Output is correct
73 Correct 44 ms 6256 KB Output is correct
74 Correct 181 ms 23980 KB Output is correct
75 Correct 228 ms 24048 KB Output is correct
76 Correct 177 ms 24044 KB Output is correct
77 Correct 173 ms 24116 KB Output is correct
78 Correct 0 ms 300 KB Output is correct
79 Correct 1 ms 212 KB Output is correct
80 Correct 4 ms 596 KB Output is correct
81 Correct 83 ms 10104 KB Output is correct
82 Correct 1 ms 212 KB Output is correct
83 Correct 1 ms 212 KB Output is correct
84 Correct 1 ms 340 KB Output is correct
85 Correct 52 ms 6288 KB Output is correct
86 Correct 69 ms 10104 KB Output is correct
87 Correct 70 ms 10112 KB Output is correct
88 Correct 71 ms 10104 KB Output is correct
89 Correct 77 ms 14156 KB Output is correct
90 Correct 1 ms 212 KB Output is correct
91 Correct 1 ms 212 KB Output is correct
92 Correct 3 ms 672 KB Output is correct
93 Correct 70 ms 10108 KB Output is correct
94 Correct 1 ms 212 KB Output is correct
95 Correct 0 ms 212 KB Output is correct
96 Correct 1 ms 212 KB Output is correct
97 Correct 20 ms 2764 KB Output is correct
98 Correct 71 ms 10108 KB Output is correct
99 Correct 72 ms 10108 KB Output is correct
100 Correct 67 ms 10084 KB Output is correct
101 Correct 67 ms 10120 KB Output is correct
102 Correct 64 ms 10104 KB Output is correct
103 Correct 68 ms 10108 KB Output is correct
104 Correct 71 ms 10108 KB Output is correct
105 Correct 80 ms 10104 KB Output is correct