#include <bits/stdc++.h>
#include "supertrees.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
int m;
struct UF{
vi e;
vi con;
UF(int n){ e.assign(n,-1); con.assign(n,0);}
int find(int x){ return (e[x] < 0 ? x : find(e[x])); }
void _union(int a, int b){
int x = find(a);
int y = find(b);
if(x == y) return;
if(e[x] > e[y]) swap(x,y);
e[x] += e[y];
e[y] = x;
}
};
int construct(vvi p){
m = (int)p.size();
int ban=0;
UF fu(m);
vvi ans(m, vi(m,0));
vector<set<int>> coneect(m, set<int>());
vvi conect(m, vi());
for(int i=0; i<m; i++){
for(int j=i; j<m; j++){
if(i==j) continue;
if(p[i][j]==1 && ban==0){
ban=1;
}
if(p[i][j]==2 && ban==0){
ban=2;
}
if(p[i][j]!=0){
fu._union(i, j);
}
}
}
for(int i=0; i<m; i++){
for(int j=i; j<m; j++){
if(p[i][j]==0){
if(fu.find(i)==fu.find(j)){
return 0;
}
}else{
int t = fu.find(i);
int size=(int)coneect[t].size();
coneect[t].insert(i);
if((int)coneect[t].size() > size) {conect[t].push_back(i); size++;}
coneect[t].insert(j);
if((int)coneect[t].size() > size) {conect[t].push_back(j); size++;}
}
}
}
for(int i=0; i<m; i++){
if(ban==2 && (int)conect[i].size()==2){
return 0;
}
for(int j=0; j<(int)conect[i].size()-1; j++){
ans[conect[i][j+1]][conect[i][j]]=1;
ans[conect[i][j]][conect[i][j+1]]=1;
}
if(ban==2){
ans[conect[i][(int)conect.size()-1]][conect[i][0]]=1;
ans[conect[i][0]][conect[i][(int)conect.size()-1]]=1;
}
}
for(int i=0; i<m; i++){
ans[i][i]=0;
}
build(ans);
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
436 KB |
Output is correct |
6 |
Correct |
6 ms |
1372 KB |
Output is correct |
7 |
Correct |
142 ms |
24148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
436 KB |
Output is correct |
6 |
Correct |
6 ms |
1372 KB |
Output is correct |
7 |
Correct |
142 ms |
24148 KB |
Output is correct |
8 |
Correct |
0 ms |
600 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
5 ms |
1372 KB |
Output is correct |
13 |
Correct |
129 ms |
24144 KB |
Output is correct |
14 |
Correct |
0 ms |
436 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
860 KB |
Output is correct |
17 |
Correct |
57 ms |
14076 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 |
6312 KB |
Output is correct |
21 |
Correct |
154 ms |
24148 KB |
Output is correct |
22 |
Correct |
158 ms |
24148 KB |
Output is correct |
23 |
Correct |
131 ms |
24144 KB |
Output is correct |
24 |
Correct |
146 ms |
24080 KB |
Output is correct |
25 |
Correct |
50 ms |
14220 KB |
Output is correct |
26 |
Correct |
48 ms |
14092 KB |
Output is correct |
27 |
Correct |
139 ms |
24148 KB |
Output is correct |
28 |
Correct |
129 ms |
24076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Runtime error |
0 ms |
348 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
436 KB |
Output is correct |
6 |
Correct |
6 ms |
1372 KB |
Output is correct |
7 |
Correct |
142 ms |
24148 KB |
Output is correct |
8 |
Correct |
0 ms |
600 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
5 ms |
1372 KB |
Output is correct |
13 |
Correct |
129 ms |
24144 KB |
Output is correct |
14 |
Correct |
0 ms |
436 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
860 KB |
Output is correct |
17 |
Correct |
57 ms |
14076 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 |
6312 KB |
Output is correct |
21 |
Correct |
154 ms |
24148 KB |
Output is correct |
22 |
Correct |
158 ms |
24148 KB |
Output is correct |
23 |
Correct |
131 ms |
24144 KB |
Output is correct |
24 |
Correct |
146 ms |
24080 KB |
Output is correct |
25 |
Correct |
50 ms |
14220 KB |
Output is correct |
26 |
Correct |
48 ms |
14092 KB |
Output is correct |
27 |
Correct |
139 ms |
24148 KB |
Output is correct |
28 |
Correct |
129 ms |
24076 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
344 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
34 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
436 KB |
Output is correct |
6 |
Correct |
6 ms |
1372 KB |
Output is correct |
7 |
Correct |
142 ms |
24148 KB |
Output is correct |
8 |
Correct |
0 ms |
600 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
5 ms |
1372 KB |
Output is correct |
13 |
Correct |
129 ms |
24144 KB |
Output is correct |
14 |
Correct |
0 ms |
436 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
860 KB |
Output is correct |
17 |
Correct |
57 ms |
14076 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 |
6312 KB |
Output is correct |
21 |
Correct |
154 ms |
24148 KB |
Output is correct |
22 |
Correct |
158 ms |
24148 KB |
Output is correct |
23 |
Correct |
131 ms |
24144 KB |
Output is correct |
24 |
Correct |
146 ms |
24080 KB |
Output is correct |
25 |
Correct |
50 ms |
14220 KB |
Output is correct |
26 |
Correct |
48 ms |
14092 KB |
Output is correct |
27 |
Correct |
139 ms |
24148 KB |
Output is correct |
28 |
Correct |
129 ms |
24076 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
344 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
34 |
Halted |
0 ms |
0 KB |
- |