Submission #411077

# Submission time Handle Problem Language Result Execution time Memory
411077 2021-05-24T09:34:48 Z kwongweng Connecting Supertrees (IOI20_supertrees) C++17
100 / 100
289 ms 24036 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long double ld;
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define ROF(i, a, b) for(int i = a; i >= b; i--)
#define ms memset
#define pb push_back
#define F first
#define S second

vi p1(1001), p2(1001), sz1(1001, 1), sz2(1001, 1);
int get1(int a){
    if (p1[a] == a) return a;
    p1[a] = get1(p1[a]);
    return p1[a];
}

void Union1(int a, int b){
    int c = get1(a); int d = get1(b);
    if (c == d) return;
    if (sz1[c] >= sz1[d]){
        p1[d] = c;
        sz1[c] += sz1[d];
    }else{
        p1[c] = d;
        sz1[d] += sz1[c];
    }
}

int get2(int a){
    if (p2[a] == a) return a;
    p2[a] = get2(p2[a]);
    return p2[a];
}
void Union2(int a, int b){
    int c = get2(a); int d = get2(b);
    if (c == d) return;
    if (sz2[c] >= sz2[d]){
        p2[d] = c;
        sz2[c] += sz2[d];
    }else{
        p2[c] = d;
        sz2[d] += sz2[c];
    }
}
int construct(vector<vi> p) {
	int n = p.size();
	FOR(i, 0, n){
	    FOR(j, 0, n){
	        if (p[i][j] == 3) return 0;
	    }
	}
	FOR(i, 0, n){
	    p1[i] = i;
	    p2[i] = i;
	}
	FOR(i, 0, n){
	    FOR(j, 0, n){
	        if (p[i][j] == 1) Union1(i, j);
	    }
	}
	FOR(i, 0, n){
	    FOR(j, 0, n){
	        if (i == get1(i) && j == get1(j)){
	            if (p[i][j] == 2) Union2(i, j);
	        }
	    }
	}
	FOR(i, 0, n){
	    if (sz2[i] == 2) return 0;
	}
	vector<vi> ans;
	FOR(i, 0, n){
	    vi row(n);
	    ans.pb(row);
	}
	FOR(i, 0, n){
	    FOR(j, 0, n){
	        if (p[i][j] == 0){
	            if (get2(get1(i)) == get2(get1(j))) return 0;
	        }
	        if (p[i][j] == 2){
	            if (get1(i) == get1(j) || get2(get1(i)) != get2(get1(j))) return 0;
	        }
	    }
	}
	vi g[n];
	FOR(i, 0, n){
	    ans[get1(i)][i] = 1;
	    ans[i][get1(i)] = 1;
	    if (i == get1(i)){
	        g[get2(i)].pb(i);
	    }
	}
	FOR(i, 0, n){
	    if (get1(i) == i && get2(i) == i){
	        FOR(j, 0, sz2[i]){
	            ans[g[i][j]][g[i][(j+1)%sz2[i]]] = 1;
	            ans[g[i][(j+1)%sz2[i]]][g[i][j]] = 1;
	        }
	    }
	}
	FOR(i, 0, n){
	    ans[i][i] = 0;
	}
	build(ans);
	return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 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 11 ms 1116 KB Output is correct
7 Correct 244 ms 22032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 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 11 ms 1116 KB Output is correct
7 Correct 244 ms 22032 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 10 ms 1100 KB Output is correct
13 Correct 243 ms 22096 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 8 ms 716 KB Output is correct
17 Correct 118 ms 12052 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 62 ms 5684 KB Output is correct
21 Correct 250 ms 22096 KB Output is correct
22 Correct 255 ms 22008 KB Output is correct
23 Correct 266 ms 22048 KB Output is correct
24 Correct 235 ms 22024 KB Output is correct
25 Correct 104 ms 12052 KB Output is correct
26 Correct 97 ms 12052 KB Output is correct
27 Correct 262 ms 22012 KB Output is correct
28 Correct 235 ms 22012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 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 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 12 ms 1100 KB Output is correct
9 Correct 242 ms 22000 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 12 ms 1100 KB Output is correct
13 Correct 268 ms 22072 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 6 ms 720 KB Output is correct
17 Correct 120 ms 12028 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 64 ms 5700 KB Output is correct
22 Correct 264 ms 22028 KB Output is correct
23 Correct 253 ms 21968 KB Output is correct
24 Correct 284 ms 22004 KB Output is correct
25 Correct 95 ms 8132 KB Output is correct
26 Correct 103 ms 12024 KB Output is correct
27 Correct 251 ms 22040 KB Output is correct
28 Correct 283 ms 21976 KB Output is correct
29 Correct 97 ms 8084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 78 ms 5772 KB Output is correct
5 Correct 266 ms 22084 KB Output is correct
6 Correct 253 ms 22164 KB Output is correct
7 Correct 261 ms 22044 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 73 ms 5724 KB Output is correct
10 Correct 256 ms 22024 KB Output is correct
11 Correct 264 ms 22024 KB Output is correct
12 Correct 289 ms 22004 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 312 KB Output is correct
16 Correct 65 ms 6404 KB Output is correct
17 Correct 275 ms 23952 KB Output is correct
18 Correct 283 ms 24036 KB Output is correct
19 Correct 271 ms 23960 KB Output is correct
20 Correct 249 ms 24004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 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 11 ms 1116 KB Output is correct
7 Correct 244 ms 22032 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 10 ms 1100 KB Output is correct
13 Correct 243 ms 22096 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 8 ms 716 KB Output is correct
17 Correct 118 ms 12052 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 62 ms 5684 KB Output is correct
21 Correct 250 ms 22096 KB Output is correct
22 Correct 255 ms 22008 KB Output is correct
23 Correct 266 ms 22048 KB Output is correct
24 Correct 235 ms 22024 KB Output is correct
25 Correct 104 ms 12052 KB Output is correct
26 Correct 97 ms 12052 KB Output is correct
27 Correct 262 ms 22012 KB Output is correct
28 Correct 235 ms 22012 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 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 12 ms 1100 KB Output is correct
37 Correct 242 ms 22000 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 12 ms 1100 KB Output is correct
41 Correct 268 ms 22072 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 6 ms 720 KB Output is correct
45 Correct 120 ms 12028 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 1 ms 204 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 64 ms 5700 KB Output is correct
50 Correct 264 ms 22028 KB Output is correct
51 Correct 253 ms 21968 KB Output is correct
52 Correct 284 ms 22004 KB Output is correct
53 Correct 95 ms 8132 KB Output is correct
54 Correct 103 ms 12024 KB Output is correct
55 Correct 251 ms 22040 KB Output is correct
56 Correct 283 ms 21976 KB Output is correct
57 Correct 97 ms 8084 KB Output is correct
58 Correct 1 ms 204 KB Output is correct
59 Correct 1 ms 204 KB Output is correct
60 Correct 5 ms 716 KB Output is correct
61 Correct 115 ms 12028 KB Output is correct
62 Correct 1 ms 204 KB Output is correct
63 Correct 1 ms 204 KB Output is correct
64 Correct 1 ms 204 KB Output is correct
65 Correct 64 ms 6212 KB Output is correct
66 Correct 104 ms 14088 KB Output is correct
67 Correct 121 ms 14088 KB Output is correct
68 Correct 126 ms 14076 KB Output is correct
69 Correct 98 ms 10108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 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 11 ms 1116 KB Output is correct
7 Correct 244 ms 22032 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 10 ms 1100 KB Output is correct
13 Correct 243 ms 22096 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 8 ms 716 KB Output is correct
17 Correct 118 ms 12052 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 62 ms 5684 KB Output is correct
21 Correct 250 ms 22096 KB Output is correct
22 Correct 255 ms 22008 KB Output is correct
23 Correct 266 ms 22048 KB Output is correct
24 Correct 235 ms 22024 KB Output is correct
25 Correct 104 ms 12052 KB Output is correct
26 Correct 97 ms 12052 KB Output is correct
27 Correct 262 ms 22012 KB Output is correct
28 Correct 235 ms 22012 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 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 12 ms 1100 KB Output is correct
37 Correct 242 ms 22000 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 12 ms 1100 KB Output is correct
41 Correct 268 ms 22072 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 6 ms 720 KB Output is correct
45 Correct 120 ms 12028 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 1 ms 204 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 64 ms 5700 KB Output is correct
50 Correct 264 ms 22028 KB Output is correct
51 Correct 253 ms 21968 KB Output is correct
52 Correct 284 ms 22004 KB Output is correct
53 Correct 95 ms 8132 KB Output is correct
54 Correct 103 ms 12024 KB Output is correct
55 Correct 251 ms 22040 KB Output is correct
56 Correct 283 ms 21976 KB Output is correct
57 Correct 97 ms 8084 KB Output is correct
58 Correct 1 ms 204 KB Output is correct
59 Correct 1 ms 204 KB Output is correct
60 Correct 1 ms 204 KB Output is correct
61 Correct 78 ms 5772 KB Output is correct
62 Correct 266 ms 22084 KB Output is correct
63 Correct 253 ms 22164 KB Output is correct
64 Correct 261 ms 22044 KB Output is correct
65 Correct 1 ms 204 KB Output is correct
66 Correct 73 ms 5724 KB Output is correct
67 Correct 256 ms 22024 KB Output is correct
68 Correct 264 ms 22024 KB Output is correct
69 Correct 289 ms 22004 KB Output is correct
70 Correct 1 ms 204 KB Output is correct
71 Correct 1 ms 204 KB Output is correct
72 Correct 1 ms 312 KB Output is correct
73 Correct 65 ms 6404 KB Output is correct
74 Correct 275 ms 23952 KB Output is correct
75 Correct 283 ms 24036 KB Output is correct
76 Correct 271 ms 23960 KB Output is correct
77 Correct 249 ms 24004 KB Output is correct
78 Correct 1 ms 204 KB Output is correct
79 Correct 1 ms 204 KB Output is correct
80 Correct 5 ms 716 KB Output is correct
81 Correct 115 ms 12028 KB Output is correct
82 Correct 1 ms 204 KB Output is correct
83 Correct 1 ms 204 KB Output is correct
84 Correct 1 ms 204 KB Output is correct
85 Correct 64 ms 6212 KB Output is correct
86 Correct 104 ms 14088 KB Output is correct
87 Correct 121 ms 14088 KB Output is correct
88 Correct 126 ms 14076 KB Output is correct
89 Correct 98 ms 10108 KB Output is correct
90 Correct 1 ms 204 KB Output is correct
91 Correct 1 ms 204 KB Output is correct
92 Correct 5 ms 588 KB Output is correct
93 Correct 113 ms 10032 KB Output is correct
94 Correct 1 ms 204 KB Output is correct
95 Correct 1 ms 204 KB Output is correct
96 Correct 1 ms 204 KB Output is correct
97 Correct 24 ms 2680 KB Output is correct
98 Correct 94 ms 10108 KB Output is correct
99 Correct 94 ms 10120 KB Output is correct
100 Correct 92 ms 10052 KB Output is correct
101 Correct 95 ms 10116 KB Output is correct
102 Correct 99 ms 10052 KB Output is correct
103 Correct 99 ms 10124 KB Output is correct
104 Correct 97 ms 10116 KB Output is correct
105 Correct 105 ms 10108 KB Output is correct