#include "supertrees.h"
#include<bits/stdc++.h>
using namespace std;
#define in insert
#define all(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
// #define int long long
typedef long long ll;
typedef vector<int> vi;
typedef set<int> si;
typedef multiset<int> msi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
const int mxn = 1010;
int par[mxn];
int get(int x) {
return (x == par[x] ? x : par[x] = get(par[x]));
}
void unite(int x, int y) {
x = get(x); y = get(y);
if(x == y) return;
par[y] = x;
}
int construct(vector<vector<int>> p) {
int n = p.size();
vector<vector<int>> answer(n, vector<int>(n));
for(int i = 0; i < n; i++) {
par[i] = i;
}
int mx = 0;
for (int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
if(p[i][j] > 0) {
unite(i, j);
mx = max(mx, p[i][j]);
}
}
}
if(mx == 0) {
build(answer);
return 1;
}
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
if(p[i][j] == 0 && get(i) == get(j)) {
return 0;
}
}
}
vector<int> vis(n);
for(int i = 0; i < n; i++) {
if(vis[i]) continue;
int ls = i, cnt = 1;
for(int j = i + 1; j < n; j++) {
if(get(j) == get(i)) {
answer[ls][j] = answer[j][ls] = 1;
ls = j;
vis[j] = 1;
cnt++;
}
}
if(cnt == 1) continue;
if(mx == 2) {
if(cnt == 2) return 0;
answer[i][ls] = answer[ls][i] = 1;
}
}
build(answer);
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
312 KB |
Output is correct |
6 |
Correct |
9 ms |
1236 KB |
Output is correct |
7 |
Correct |
159 ms |
22456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
312 KB |
Output is correct |
6 |
Correct |
9 ms |
1236 KB |
Output is correct |
7 |
Correct |
159 ms |
22456 KB |
Output is correct |
8 |
Correct |
1 ms |
320 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 |
7 ms |
1212 KB |
Output is correct |
13 |
Correct |
172 ms |
22544 KB |
Output is correct |
14 |
Correct |
1 ms |
308 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
852 KB |
Output is correct |
17 |
Correct |
73 ms |
12656 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
39 ms |
6212 KB |
Output is correct |
21 |
Correct |
161 ms |
22456 KB |
Output is correct |
22 |
Correct |
154 ms |
22476 KB |
Output is correct |
23 |
Correct |
177 ms |
22452 KB |
Output is correct |
24 |
Correct |
160 ms |
22500 KB |
Output is correct |
25 |
Correct |
66 ms |
12552 KB |
Output is correct |
26 |
Correct |
68 ms |
12680 KB |
Output is correct |
27 |
Correct |
184 ms |
22544 KB |
Output is correct |
28 |
Correct |
160 ms |
22508 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 |
0 ms |
304 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
8 ms |
1236 KB |
Output is correct |
9 |
Correct |
161 ms |
22740 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1236 KB |
Output is correct |
13 |
Correct |
154 ms |
22596 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
852 KB |
Output is correct |
17 |
Correct |
73 ms |
12584 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
304 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
38 ms |
6216 KB |
Output is correct |
22 |
Correct |
164 ms |
23912 KB |
Output is correct |
23 |
Correct |
176 ms |
23904 KB |
Output is correct |
24 |
Correct |
157 ms |
24012 KB |
Output is correct |
25 |
Correct |
78 ms |
14072 KB |
Output is correct |
26 |
Correct |
67 ms |
14028 KB |
Output is correct |
27 |
Correct |
153 ms |
23928 KB |
Output is correct |
28 |
Correct |
162 ms |
23964 KB |
Output is correct |
29 |
Correct |
66 ms |
13992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
40 ms |
5824 KB |
Output is correct |
5 |
Correct |
180 ms |
22128 KB |
Output is correct |
6 |
Correct |
152 ms |
21964 KB |
Output is correct |
7 |
Correct |
156 ms |
21964 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
50 ms |
6264 KB |
Output is correct |
10 |
Correct |
194 ms |
24012 KB |
Output is correct |
11 |
Correct |
157 ms |
24108 KB |
Output is correct |
12 |
Correct |
159 ms |
23948 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Incorrect |
0 ms |
212 KB |
Too many ways to get from 4 to 8, should be 1 found no less than 2 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
312 KB |
Output is correct |
6 |
Correct |
9 ms |
1236 KB |
Output is correct |
7 |
Correct |
159 ms |
22456 KB |
Output is correct |
8 |
Correct |
1 ms |
320 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 |
7 ms |
1212 KB |
Output is correct |
13 |
Correct |
172 ms |
22544 KB |
Output is correct |
14 |
Correct |
1 ms |
308 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
852 KB |
Output is correct |
17 |
Correct |
73 ms |
12656 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
39 ms |
6212 KB |
Output is correct |
21 |
Correct |
161 ms |
22456 KB |
Output is correct |
22 |
Correct |
154 ms |
22476 KB |
Output is correct |
23 |
Correct |
177 ms |
22452 KB |
Output is correct |
24 |
Correct |
160 ms |
22500 KB |
Output is correct |
25 |
Correct |
66 ms |
12552 KB |
Output is correct |
26 |
Correct |
68 ms |
12680 KB |
Output is correct |
27 |
Correct |
184 ms |
22544 KB |
Output is correct |
28 |
Correct |
160 ms |
22508 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 |
0 ms |
304 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
8 ms |
1236 KB |
Output is correct |
37 |
Correct |
161 ms |
22740 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
7 ms |
1236 KB |
Output is correct |
41 |
Correct |
154 ms |
22596 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
4 ms |
852 KB |
Output is correct |
45 |
Correct |
73 ms |
12584 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
0 ms |
304 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
38 ms |
6216 KB |
Output is correct |
50 |
Correct |
164 ms |
23912 KB |
Output is correct |
51 |
Correct |
176 ms |
23904 KB |
Output is correct |
52 |
Correct |
157 ms |
24012 KB |
Output is correct |
53 |
Correct |
78 ms |
14072 KB |
Output is correct |
54 |
Correct |
67 ms |
14028 KB |
Output is correct |
55 |
Correct |
153 ms |
23928 KB |
Output is correct |
56 |
Correct |
162 ms |
23964 KB |
Output is correct |
57 |
Correct |
66 ms |
13992 KB |
Output is correct |
58 |
Correct |
1 ms |
304 KB |
Output is correct |
59 |
Correct |
0 ms |
212 KB |
Output is correct |
60 |
Correct |
4 ms |
852 KB |
Output is correct |
61 |
Correct |
77 ms |
14068 KB |
Output is correct |
62 |
Correct |
0 ms |
212 KB |
Output is correct |
63 |
Incorrect |
1 ms |
212 KB |
Too many ways to get from 0 to 9, should be 1 found no less than 2 |
64 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
312 KB |
Output is correct |
6 |
Correct |
9 ms |
1236 KB |
Output is correct |
7 |
Correct |
159 ms |
22456 KB |
Output is correct |
8 |
Correct |
1 ms |
320 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 |
7 ms |
1212 KB |
Output is correct |
13 |
Correct |
172 ms |
22544 KB |
Output is correct |
14 |
Correct |
1 ms |
308 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
852 KB |
Output is correct |
17 |
Correct |
73 ms |
12656 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
39 ms |
6212 KB |
Output is correct |
21 |
Correct |
161 ms |
22456 KB |
Output is correct |
22 |
Correct |
154 ms |
22476 KB |
Output is correct |
23 |
Correct |
177 ms |
22452 KB |
Output is correct |
24 |
Correct |
160 ms |
22500 KB |
Output is correct |
25 |
Correct |
66 ms |
12552 KB |
Output is correct |
26 |
Correct |
68 ms |
12680 KB |
Output is correct |
27 |
Correct |
184 ms |
22544 KB |
Output is correct |
28 |
Correct |
160 ms |
22508 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 |
0 ms |
304 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
8 ms |
1236 KB |
Output is correct |
37 |
Correct |
161 ms |
22740 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
7 ms |
1236 KB |
Output is correct |
41 |
Correct |
154 ms |
22596 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
4 ms |
852 KB |
Output is correct |
45 |
Correct |
73 ms |
12584 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
0 ms |
304 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
38 ms |
6216 KB |
Output is correct |
50 |
Correct |
164 ms |
23912 KB |
Output is correct |
51 |
Correct |
176 ms |
23904 KB |
Output is correct |
52 |
Correct |
157 ms |
24012 KB |
Output is correct |
53 |
Correct |
78 ms |
14072 KB |
Output is correct |
54 |
Correct |
67 ms |
14028 KB |
Output is correct |
55 |
Correct |
153 ms |
23928 KB |
Output is correct |
56 |
Correct |
162 ms |
23964 KB |
Output is correct |
57 |
Correct |
66 ms |
13992 KB |
Output is correct |
58 |
Correct |
1 ms |
212 KB |
Output is correct |
59 |
Correct |
1 ms |
304 KB |
Output is correct |
60 |
Correct |
0 ms |
212 KB |
Output is correct |
61 |
Correct |
40 ms |
5824 KB |
Output is correct |
62 |
Correct |
180 ms |
22128 KB |
Output is correct |
63 |
Correct |
152 ms |
21964 KB |
Output is correct |
64 |
Correct |
156 ms |
21964 KB |
Output is correct |
65 |
Correct |
0 ms |
212 KB |
Output is correct |
66 |
Correct |
50 ms |
6264 KB |
Output is correct |
67 |
Correct |
194 ms |
24012 KB |
Output is correct |
68 |
Correct |
157 ms |
24108 KB |
Output is correct |
69 |
Correct |
159 ms |
23948 KB |
Output is correct |
70 |
Correct |
0 ms |
212 KB |
Output is correct |
71 |
Incorrect |
0 ms |
212 KB |
Too many ways to get from 4 to 8, should be 1 found no less than 2 |
72 |
Halted |
0 ms |
0 KB |
- |