Submission #428358

# Submission time Handle Problem Language Result Execution time Memory
428358 2021-06-15T10:50:09 Z MarcoMeijer Connecting Supertrees (IOI20_supertrees) C++14
100 / 100
315 ms 22236 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;

// macros
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> lll;
typedef tuple<int, int, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<lll> vlll;
#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define RE(a,c) REP(a,0,c)
#define RE1(a,c) REP(a,1,c+1)
#define REI(a,b,c) REP(a,b,c+1)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define FOR(a,b) for(auto& a : b)
#define all(a) a.begin(), a.end()
#define INF 1e9
#define EPS 1e-9
#define pb push_back
#define popb pop_back
#define fi first
#define se second
#define sz size()
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MX=2000;

int n;
struct DSU {
    int p[MX], r[MX];
    vi dif[MX];
    void build() {
        RE(i,n) p[i]=i, r[i]=0, dif[i]={i};
    }
    int get(int i) {return i==p[i] ? i : p[i]=get(p[i]);}
    bool isSame(int i, int j) {return get(i) == get(j);}
    void link(int i, int j) {
        i = get(i), j = get(j);
        if(dif[i].size() > dif[j].size()) swap(i,j);
        FOR(x,dif[i]) dif[j].pb(x);
        if(i != j) {
            if(r[i] > r[j]) {
                p[j] = i;
                swap(dif[i],dif[j]);
            } else {
                p[i] = j;
                if(r[i] == r[j]) r[j]++;
            }
        }
    }
} dsu1, dsu2;

int construct(vector<vi> p) {
	n = p.size();
    vector<vi> answer(n,vi(n,0));

    dsu1.build();
    RE(i,n) RE(j,n) {
        if(p[i][j] == 1 && !dsu1.isSame(i,j))
            dsu1.link(i,j), answer[i][j] = answer[j][i] = 1;
    }
    RE(i,n) RE(j,n) if(p[i][j] == 0 && dsu1.isSame(i,j)) return 0;
    
    dsu2.build();
    RE(i,n) RE(j,n) {
        if(p[i][j] == 2 && !dsu2.isSame(dsu1.get(i),dsu1.get(j)))
            dsu2.link(dsu1.get(i),dsu1.get(j));
    }

    RE(i,n) if(dsu2.get(i) == i) {
        if(dsu2.dif[i].size() == 1)
            continue;
        if(dsu2.dif[i].size() == 2)
            return 0;
        RE(u,dsu2.dif[i].size()) {
            int v = (u+1)%dsu2.dif[i].size();
            int x = dsu2.dif[i][u];
            int y = dsu2.dif[i][v];
            answer[x][y] = answer[y][x] = 1;
        }
    }

    RE(i,n) RE(j,n) if(p[i][j] == 0 && dsu2.isSame(dsu1.get(i),dsu1.get(j))) return 0;
    RE(i,n) RE(j,n) if(p[i][j] == 3) return 0;

	build(answer);
	return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 10 ms 1196 KB Output is correct
7 Correct 241 ms 22112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 10 ms 1196 KB Output is correct
7 Correct 241 ms 22112 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 10 ms 1296 KB Output is correct
13 Correct 244 ms 22184 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 5 ms 844 KB Output is correct
17 Correct 115 ms 12268 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 61 ms 5864 KB Output is correct
21 Correct 249 ms 22124 KB Output is correct
22 Correct 262 ms 22212 KB Output is correct
23 Correct 253 ms 22212 KB Output is correct
24 Correct 248 ms 22228 KB Output is correct
25 Correct 115 ms 12272 KB Output is correct
26 Correct 96 ms 12264 KB Output is correct
27 Correct 257 ms 22184 KB Output is correct
28 Correct 248 ms 22116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 10 ms 1268 KB Output is correct
9 Correct 234 ms 22132 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 10 ms 1228 KB Output is correct
13 Correct 288 ms 22116 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 7 ms 892 KB Output is correct
17 Correct 124 ms 12260 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 60 ms 5828 KB Output is correct
22 Correct 244 ms 22116 KB Output is correct
23 Correct 238 ms 22220 KB Output is correct
24 Correct 258 ms 22196 KB Output is correct
25 Correct 99 ms 12228 KB Output is correct
26 Correct 134 ms 12228 KB Output is correct
27 Correct 243 ms 22116 KB Output is correct
28 Correct 263 ms 22120 KB Output is correct
29 Correct 98 ms 12228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 60 ms 5828 KB Output is correct
5 Correct 249 ms 22112 KB Output is correct
6 Correct 256 ms 22132 KB Output is correct
7 Correct 315 ms 22212 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 63 ms 5860 KB Output is correct
10 Correct 238 ms 22128 KB Output is correct
11 Correct 275 ms 22212 KB Output is correct
12 Correct 251 ms 22236 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 59 ms 5856 KB Output is correct
17 Correct 235 ms 22152 KB Output is correct
18 Correct 252 ms 22212 KB Output is correct
19 Correct 252 ms 22124 KB Output is correct
20 Correct 307 ms 22124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 10 ms 1196 KB Output is correct
7 Correct 241 ms 22112 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 10 ms 1296 KB Output is correct
13 Correct 244 ms 22184 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 5 ms 844 KB Output is correct
17 Correct 115 ms 12268 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 61 ms 5864 KB Output is correct
21 Correct 249 ms 22124 KB Output is correct
22 Correct 262 ms 22212 KB Output is correct
23 Correct 253 ms 22212 KB Output is correct
24 Correct 248 ms 22228 KB Output is correct
25 Correct 115 ms 12272 KB Output is correct
26 Correct 96 ms 12264 KB Output is correct
27 Correct 257 ms 22184 KB Output is correct
28 Correct 248 ms 22116 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 10 ms 1268 KB Output is correct
37 Correct 234 ms 22132 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 10 ms 1228 KB Output is correct
41 Correct 288 ms 22116 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 7 ms 892 KB Output is correct
45 Correct 124 ms 12260 KB Output is correct
46 Correct 1 ms 332 KB Output is correct
47 Correct 1 ms 332 KB Output is correct
48 Correct 1 ms 332 KB Output is correct
49 Correct 60 ms 5828 KB Output is correct
50 Correct 244 ms 22116 KB Output is correct
51 Correct 238 ms 22220 KB Output is correct
52 Correct 258 ms 22196 KB Output is correct
53 Correct 99 ms 12228 KB Output is correct
54 Correct 134 ms 12228 KB Output is correct
55 Correct 243 ms 22116 KB Output is correct
56 Correct 263 ms 22120 KB Output is correct
57 Correct 98 ms 12228 KB Output is correct
58 Correct 1 ms 332 KB Output is correct
59 Correct 1 ms 332 KB Output is correct
60 Correct 5 ms 844 KB Output is correct
61 Correct 109 ms 12264 KB Output is correct
62 Correct 1 ms 332 KB Output is correct
63 Correct 1 ms 332 KB Output is correct
64 Correct 1 ms 332 KB Output is correct
65 Correct 78 ms 5816 KB Output is correct
66 Correct 124 ms 12268 KB Output is correct
67 Correct 96 ms 12228 KB Output is correct
68 Correct 108 ms 12264 KB Output is correct
69 Correct 122 ms 12256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 10 ms 1196 KB Output is correct
7 Correct 241 ms 22112 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 10 ms 1296 KB Output is correct
13 Correct 244 ms 22184 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 5 ms 844 KB Output is correct
17 Correct 115 ms 12268 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 61 ms 5864 KB Output is correct
21 Correct 249 ms 22124 KB Output is correct
22 Correct 262 ms 22212 KB Output is correct
23 Correct 253 ms 22212 KB Output is correct
24 Correct 248 ms 22228 KB Output is correct
25 Correct 115 ms 12272 KB Output is correct
26 Correct 96 ms 12264 KB Output is correct
27 Correct 257 ms 22184 KB Output is correct
28 Correct 248 ms 22116 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 10 ms 1268 KB Output is correct
37 Correct 234 ms 22132 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 10 ms 1228 KB Output is correct
41 Correct 288 ms 22116 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 7 ms 892 KB Output is correct
45 Correct 124 ms 12260 KB Output is correct
46 Correct 1 ms 332 KB Output is correct
47 Correct 1 ms 332 KB Output is correct
48 Correct 1 ms 332 KB Output is correct
49 Correct 60 ms 5828 KB Output is correct
50 Correct 244 ms 22116 KB Output is correct
51 Correct 238 ms 22220 KB Output is correct
52 Correct 258 ms 22196 KB Output is correct
53 Correct 99 ms 12228 KB Output is correct
54 Correct 134 ms 12228 KB Output is correct
55 Correct 243 ms 22116 KB Output is correct
56 Correct 263 ms 22120 KB Output is correct
57 Correct 98 ms 12228 KB Output is correct
58 Correct 1 ms 332 KB Output is correct
59 Correct 1 ms 332 KB Output is correct
60 Correct 1 ms 332 KB Output is correct
61 Correct 60 ms 5828 KB Output is correct
62 Correct 249 ms 22112 KB Output is correct
63 Correct 256 ms 22132 KB Output is correct
64 Correct 315 ms 22212 KB Output is correct
65 Correct 1 ms 332 KB Output is correct
66 Correct 63 ms 5860 KB Output is correct
67 Correct 238 ms 22128 KB Output is correct
68 Correct 275 ms 22212 KB Output is correct
69 Correct 251 ms 22236 KB Output is correct
70 Correct 1 ms 332 KB Output is correct
71 Correct 1 ms 332 KB Output is correct
72 Correct 1 ms 332 KB Output is correct
73 Correct 59 ms 5856 KB Output is correct
74 Correct 235 ms 22152 KB Output is correct
75 Correct 252 ms 22212 KB Output is correct
76 Correct 252 ms 22124 KB Output is correct
77 Correct 307 ms 22124 KB Output is correct
78 Correct 1 ms 332 KB Output is correct
79 Correct 1 ms 332 KB Output is correct
80 Correct 5 ms 844 KB Output is correct
81 Correct 109 ms 12264 KB Output is correct
82 Correct 1 ms 332 KB Output is correct
83 Correct 1 ms 332 KB Output is correct
84 Correct 1 ms 332 KB Output is correct
85 Correct 78 ms 5816 KB Output is correct
86 Correct 124 ms 12268 KB Output is correct
87 Correct 96 ms 12228 KB Output is correct
88 Correct 108 ms 12264 KB Output is correct
89 Correct 122 ms 12256 KB Output is correct
90 Correct 1 ms 332 KB Output is correct
91 Correct 1 ms 284 KB Output is correct
92 Correct 5 ms 812 KB Output is correct
93 Correct 105 ms 12268 KB Output is correct
94 Correct 1 ms 332 KB Output is correct
95 Correct 1 ms 332 KB Output is correct
96 Correct 1 ms 332 KB Output is correct
97 Correct 30 ms 3788 KB Output is correct
98 Correct 128 ms 14180 KB Output is correct
99 Correct 121 ms 14308 KB Output is correct
100 Correct 118 ms 14176 KB Output is correct
101 Correct 104 ms 14152 KB Output is correct
102 Correct 100 ms 14252 KB Output is correct
103 Correct 108 ms 14172 KB Output is correct
104 Correct 104 ms 14300 KB Output is correct
105 Correct 123 ms 14180 KB Output is correct