#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
class DSU {
vector<int> par;
vector<int> siz;
public:
DSU(int n) {
par.resize(n);
iota(par.begin(),par.end(),0);
siz.assign(n,1);
}
int find_set(int u) {
if (par[u]==u) return u;
return par[u]=find_set(par[u]);
}
bool is_same(int u, int v) {
return find_set(u)==find_set(v);
}
bool unite_set(int u, int v) {
u=find_set(u);
v=find_set(v);
if (u==v) return false;
if (siz[u]<siz[v]) swap(u,v);
par[v]=u;
siz[u]+=siz[v];
return true;
}
};
int construct(vector<vector<int>> p) {
int n = p.size();
vector<vector<int>> ans(n,vector<int>(n,0));
DSU dsu=DSU(n);
for (int i=0; i<n; i++) {
for (int j=0; j<n; j++) {
if (i==j) continue;
if (p[i][j]==1) {
if (dsu.unite_set(i,j)) {
ans[i][j]=1;
ans[j][i]=1;
}
}
}
}
for (int i=0; i<n; i++) {
for (int j=0; j<n; j++) {
if (p[i][j]==0&&dsu.is_same(i,j)) {
return 0;
}
}
}
build(ans);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
600 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
600 KB |
Output is correct |
6 |
Correct |
8 ms |
1372 KB |
Output is correct |
7 |
Correct |
163 ms |
23964 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
600 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
600 KB |
Output is correct |
6 |
Correct |
8 ms |
1372 KB |
Output is correct |
7 |
Correct |
163 ms |
23964 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
7 ms |
1372 KB |
Output is correct |
13 |
Correct |
154 ms |
24064 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
436 KB |
Output is correct |
16 |
Correct |
3 ms |
864 KB |
Output is correct |
17 |
Correct |
77 ms |
14080 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
39 ms |
6228 KB |
Output is correct |
21 |
Correct |
160 ms |
23908 KB |
Output is correct |
22 |
Correct |
157 ms |
24144 KB |
Output is correct |
23 |
Correct |
179 ms |
24092 KB |
Output is correct |
24 |
Correct |
170 ms |
23944 KB |
Output is correct |
25 |
Correct |
61 ms |
14164 KB |
Output is correct |
26 |
Correct |
73 ms |
14084 KB |
Output is correct |
27 |
Correct |
174 ms |
24060 KB |
Output is correct |
28 |
Correct |
192 ms |
23908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Answer gives possible 1 while actual possible 0 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 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 |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
600 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
600 KB |
Output is correct |
6 |
Correct |
8 ms |
1372 KB |
Output is correct |
7 |
Correct |
163 ms |
23964 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
7 ms |
1372 KB |
Output is correct |
13 |
Correct |
154 ms |
24064 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
436 KB |
Output is correct |
16 |
Correct |
3 ms |
864 KB |
Output is correct |
17 |
Correct |
77 ms |
14080 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
39 ms |
6228 KB |
Output is correct |
21 |
Correct |
160 ms |
23908 KB |
Output is correct |
22 |
Correct |
157 ms |
24144 KB |
Output is correct |
23 |
Correct |
179 ms |
24092 KB |
Output is correct |
24 |
Correct |
170 ms |
23944 KB |
Output is correct |
25 |
Correct |
61 ms |
14164 KB |
Output is correct |
26 |
Correct |
73 ms |
14084 KB |
Output is correct |
27 |
Correct |
174 ms |
24060 KB |
Output is correct |
28 |
Correct |
192 ms |
23908 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Incorrect |
0 ms |
348 KB |
Answer gives possible 1 while actual possible 0 |
33 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
600 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
600 KB |
Output is correct |
6 |
Correct |
8 ms |
1372 KB |
Output is correct |
7 |
Correct |
163 ms |
23964 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
7 ms |
1372 KB |
Output is correct |
13 |
Correct |
154 ms |
24064 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
436 KB |
Output is correct |
16 |
Correct |
3 ms |
864 KB |
Output is correct |
17 |
Correct |
77 ms |
14080 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
39 ms |
6228 KB |
Output is correct |
21 |
Correct |
160 ms |
23908 KB |
Output is correct |
22 |
Correct |
157 ms |
24144 KB |
Output is correct |
23 |
Correct |
179 ms |
24092 KB |
Output is correct |
24 |
Correct |
170 ms |
23944 KB |
Output is correct |
25 |
Correct |
61 ms |
14164 KB |
Output is correct |
26 |
Correct |
73 ms |
14084 KB |
Output is correct |
27 |
Correct |
174 ms |
24060 KB |
Output is correct |
28 |
Correct |
192 ms |
23908 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Incorrect |
0 ms |
348 KB |
Answer gives possible 1 while actual possible 0 |
33 |
Halted |
0 ms |
0 KB |
- |