#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
const int mxN = 1005;
int par[mxN], siz[mxN];
/*
void build(vector<vector<int> > b) {
int n = int(b.size());
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++)
cout << b[i][j] << " ";
cout << "\n";
}
}
*/
void make_set(int x) {
par[x] = x, siz[x] = 1;
}
int find_set(int x) {
return x == par[x] ? x : par[x] = find_set(par[x]);
}
void union_sets(int a, int b) {
a = find_set(a), b = find_set(b);
if(a == b) return;
if(siz[a] < siz[b])
swap(a, b);
par[b] = a, siz[a] += siz[b];
}
int construct(vector<vector<int> > p) {
int n = int(p.size());
for(int i = 0; i < n; i++)
make_set(i);
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
if(p[i][j] == 1) {
union_sets(i, j);
// cout << i << " " << j << "\n";
}
}
}
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
if(p[i][j] == 0 && find_set(i) == find_set(j))
return 0;
}
}
vector<vector<int> > b(n, vector<int>(n, 0));
for(int i = 0; i < n; i++) {
int parent = find_set(i);
if(parent == i) continue;
b[i][parent] = b[parent][i] = 1;
}
build(b);
return 1;
}
/*
int main() {
int n;
scanf("%d", &n);
vector<vector<int> > p(n, vector<int>(n));
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++)
scanf("%d", &p[i][j]);
}
cout << "\n";
printf("%d\n", construct(p));
return 0;
}
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 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 |
1228 KB |
Output is correct |
7 |
Correct |
235 ms |
23884 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 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 |
1228 KB |
Output is correct |
7 |
Correct |
235 ms |
23884 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
12 ms |
1228 KB |
Output is correct |
13 |
Correct |
237 ms |
23964 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
5 ms |
588 KB |
Output is correct |
17 |
Correct |
108 ms |
10108 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
57 ms |
6212 KB |
Output is correct |
21 |
Correct |
232 ms |
24004 KB |
Output is correct |
22 |
Correct |
229 ms |
23876 KB |
Output is correct |
23 |
Correct |
269 ms |
23992 KB |
Output is correct |
24 |
Correct |
227 ms |
23904 KB |
Output is correct |
25 |
Correct |
91 ms |
10052 KB |
Output is correct |
26 |
Correct |
96 ms |
10024 KB |
Output is correct |
27 |
Correct |
243 ms |
23928 KB |
Output is correct |
28 |
Correct |
226 ms |
24004 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
Incorrect |
1 ms |
204 KB |
Answer gives possible 1 while actual possible 0 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Too few ways to get from 0 to 1, should be 2 found 0 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 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 |
1228 KB |
Output is correct |
7 |
Correct |
235 ms |
23884 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
12 ms |
1228 KB |
Output is correct |
13 |
Correct |
237 ms |
23964 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
5 ms |
588 KB |
Output is correct |
17 |
Correct |
108 ms |
10108 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
57 ms |
6212 KB |
Output is correct |
21 |
Correct |
232 ms |
24004 KB |
Output is correct |
22 |
Correct |
229 ms |
23876 KB |
Output is correct |
23 |
Correct |
269 ms |
23992 KB |
Output is correct |
24 |
Correct |
227 ms |
23904 KB |
Output is correct |
25 |
Correct |
91 ms |
10052 KB |
Output is correct |
26 |
Correct |
96 ms |
10024 KB |
Output is correct |
27 |
Correct |
243 ms |
23928 KB |
Output is correct |
28 |
Correct |
226 ms |
24004 KB |
Output is correct |
29 |
Correct |
0 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 |
Incorrect |
1 ms |
204 KB |
Answer gives possible 1 while actual possible 0 |
33 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 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 |
1228 KB |
Output is correct |
7 |
Correct |
235 ms |
23884 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
12 ms |
1228 KB |
Output is correct |
13 |
Correct |
237 ms |
23964 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
5 ms |
588 KB |
Output is correct |
17 |
Correct |
108 ms |
10108 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
57 ms |
6212 KB |
Output is correct |
21 |
Correct |
232 ms |
24004 KB |
Output is correct |
22 |
Correct |
229 ms |
23876 KB |
Output is correct |
23 |
Correct |
269 ms |
23992 KB |
Output is correct |
24 |
Correct |
227 ms |
23904 KB |
Output is correct |
25 |
Correct |
91 ms |
10052 KB |
Output is correct |
26 |
Correct |
96 ms |
10024 KB |
Output is correct |
27 |
Correct |
243 ms |
23928 KB |
Output is correct |
28 |
Correct |
226 ms |
24004 KB |
Output is correct |
29 |
Correct |
0 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 |
Incorrect |
1 ms |
204 KB |
Answer gives possible 1 while actual possible 0 |
33 |
Halted |
0 ms |
0 KB |
- |