#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3+5;
int n ;
int a[N][N];
int dad[N];
bool vs[N];
bool act[N];
struct UnionFind {
int ran;
int da;
};
UnionFind uf[N];
vector<std::vector<int>> answer;
vector<int> g[N];
int bus(int u)
{
if (uf[u].da != u) uf[u].da = bus(uf[u].da);
return uf[u].da;
}
void unir(int u,int v)
{
u = bus(u);
v = bus(v);
if (u != v) {
if (uf[u].ran > uf[v].ran) uf[v].da = u;
else if (uf[u].ran < uf[v].ran) uf[u].da = v;
else {
uf[u].ran++;
uf[v].da = u;
}
}
return;
}
void checar(int no,int p)
{
}
int construct(std::vector<std::vector<int>> _p) {
n = _p.size();
for (int i = 0; i < n; i++) {
std::vector<int> row;
row.resize(n);
answer.push_back(row);
}
for (int i=0;i<n;i++) for (int j=0;j<n;j++) a[i][j] = _p[i][j];
for (int i=0;i<n;i++) for (int j=0;j<n;j++) if (a[i][j] > 2)
return 0;
for (int i=0;i<n;i++) {
uf[i].ran = 0;
uf[i].da = i;
}
for (int i=0;i<n;i++) for (int j=0;j<n;j++) if (a[i][j]>0) unir(i,j);
for (int i=0;i<n;i++) for (int j=0;j<n;j++) if (a[i][j] == 0) if (bus(i) == bus(j)) {
return 0;
}
for (int i=0;i<n;i++) g[bus(i)].push_back(i);
for (int x=0;x<n;x++) {
uf[x].da = x;
uf[x].ran = 0;
}
for (int i=0;i<n;i++) {
// for (int j=0;j<(int)g[i].size();j++) act[g[i][j]] = true;
for (int j=0;j<(int)g[i].size();j++) {
int x = g[i][j];
for (int k=0;k<(int)g[i].size();k++) {
int y = g[i][k];
if (x != y) {
if (a[x][y] == 1) {
unir(x,y);
}
}
}
}
vector<int> gg;
set<int> s;
for (int j=0;j<(int)g[i].size();j++) s.insert(bus(g[i][j]));
for (int u : s) gg.push_back(u);
for (int j=1;j<(int)gg.size();j++) {
answer[gg[j]][gg[j-1]] = answer[gg[j-1]][gg[j]] = 1;
}
int pp = gg.size();
if (pp==2) {
return 0;
}
if (pp>1) answer[gg[0]][gg[pp-1]] = answer[gg[pp-1]][gg[0]] = 1;
for (int j=0;j<(int)g[i].size();j++) if (g[i][j] != bus(g[i][j])) {
int x = g[i][j];
answer[x][bus(x)] = answer[bus(x)][x] = 1;
}
}
build(answer);
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
10 ms |
1992 KB |
Output is correct |
7 |
Correct |
232 ms |
25960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
10 ms |
1992 KB |
Output is correct |
7 |
Correct |
232 ms |
25960 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
10 ms |
1936 KB |
Output is correct |
13 |
Correct |
218 ms |
26008 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
5 ms |
1484 KB |
Output is correct |
17 |
Correct |
109 ms |
16040 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
58 ms |
7736 KB |
Output is correct |
21 |
Correct |
228 ms |
25924 KB |
Output is correct |
22 |
Correct |
225 ms |
26128 KB |
Output is correct |
23 |
Correct |
241 ms |
26024 KB |
Output is correct |
24 |
Correct |
222 ms |
26012 KB |
Output is correct |
25 |
Correct |
97 ms |
16036 KB |
Output is correct |
26 |
Correct |
94 ms |
16024 KB |
Output is correct |
27 |
Correct |
244 ms |
26016 KB |
Output is correct |
28 |
Correct |
220 ms |
25924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
10 ms |
1996 KB |
Output is correct |
9 |
Correct |
220 ms |
28000 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
10 ms |
1996 KB |
Output is correct |
13 |
Correct |
228 ms |
27976 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
5 ms |
1588 KB |
Output is correct |
17 |
Correct |
108 ms |
18052 KB |
Output is correct |
18 |
Correct |
1 ms |
324 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
57 ms |
8172 KB |
Output is correct |
22 |
Correct |
229 ms |
27948 KB |
Output is correct |
23 |
Correct |
230 ms |
27972 KB |
Output is correct |
24 |
Correct |
245 ms |
27924 KB |
Output is correct |
25 |
Correct |
99 ms |
17988 KB |
Output is correct |
26 |
Correct |
98 ms |
18068 KB |
Output is correct |
27 |
Correct |
225 ms |
27880 KB |
Output is correct |
28 |
Correct |
238 ms |
27972 KB |
Output is correct |
29 |
Correct |
94 ms |
17988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
57 ms |
7676 KB |
Output is correct |
5 |
Correct |
225 ms |
26020 KB |
Output is correct |
6 |
Correct |
227 ms |
25948 KB |
Output is correct |
7 |
Correct |
252 ms |
25916 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
58 ms |
7708 KB |
Output is correct |
10 |
Correct |
227 ms |
26016 KB |
Output is correct |
11 |
Correct |
223 ms |
25924 KB |
Output is correct |
12 |
Correct |
259 ms |
26052 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
57 ms |
7744 KB |
Output is correct |
17 |
Correct |
250 ms |
26084 KB |
Output is correct |
18 |
Correct |
226 ms |
25924 KB |
Output is correct |
19 |
Correct |
229 ms |
25968 KB |
Output is correct |
20 |
Correct |
220 ms |
26008 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
10 ms |
1992 KB |
Output is correct |
7 |
Correct |
232 ms |
25960 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
10 ms |
1936 KB |
Output is correct |
13 |
Correct |
218 ms |
26008 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
5 ms |
1484 KB |
Output is correct |
17 |
Correct |
109 ms |
16040 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
58 ms |
7736 KB |
Output is correct |
21 |
Correct |
228 ms |
25924 KB |
Output is correct |
22 |
Correct |
225 ms |
26128 KB |
Output is correct |
23 |
Correct |
241 ms |
26024 KB |
Output is correct |
24 |
Correct |
222 ms |
26012 KB |
Output is correct |
25 |
Correct |
97 ms |
16036 KB |
Output is correct |
26 |
Correct |
94 ms |
16024 KB |
Output is correct |
27 |
Correct |
244 ms |
26016 KB |
Output is correct |
28 |
Correct |
220 ms |
25924 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
204 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
1 ms |
332 KB |
Output is correct |
36 |
Correct |
10 ms |
1996 KB |
Output is correct |
37 |
Correct |
220 ms |
28000 KB |
Output is correct |
38 |
Correct |
1 ms |
332 KB |
Output is correct |
39 |
Correct |
1 ms |
332 KB |
Output is correct |
40 |
Correct |
10 ms |
1996 KB |
Output is correct |
41 |
Correct |
228 ms |
27976 KB |
Output is correct |
42 |
Correct |
1 ms |
332 KB |
Output is correct |
43 |
Correct |
1 ms |
332 KB |
Output is correct |
44 |
Correct |
5 ms |
1588 KB |
Output is correct |
45 |
Correct |
108 ms |
18052 KB |
Output is correct |
46 |
Correct |
1 ms |
324 KB |
Output is correct |
47 |
Correct |
1 ms |
332 KB |
Output is correct |
48 |
Correct |
1 ms |
332 KB |
Output is correct |
49 |
Correct |
57 ms |
8172 KB |
Output is correct |
50 |
Correct |
229 ms |
27948 KB |
Output is correct |
51 |
Correct |
230 ms |
27972 KB |
Output is correct |
52 |
Correct |
245 ms |
27924 KB |
Output is correct |
53 |
Correct |
99 ms |
17988 KB |
Output is correct |
54 |
Correct |
98 ms |
18068 KB |
Output is correct |
55 |
Correct |
225 ms |
27880 KB |
Output is correct |
56 |
Correct |
238 ms |
27972 KB |
Output is correct |
57 |
Correct |
94 ms |
17988 KB |
Output is correct |
58 |
Correct |
1 ms |
332 KB |
Output is correct |
59 |
Correct |
1 ms |
332 KB |
Output is correct |
60 |
Correct |
5 ms |
1612 KB |
Output is correct |
61 |
Correct |
108 ms |
17988 KB |
Output is correct |
62 |
Correct |
1 ms |
332 KB |
Output is correct |
63 |
Correct |
1 ms |
332 KB |
Output is correct |
64 |
Correct |
1 ms |
332 KB |
Output is correct |
65 |
Correct |
57 ms |
8204 KB |
Output is correct |
66 |
Correct |
101 ms |
17960 KB |
Output is correct |
67 |
Correct |
103 ms |
18124 KB |
Output is correct |
68 |
Correct |
98 ms |
17944 KB |
Output is correct |
69 |
Correct |
95 ms |
18064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
10 ms |
1992 KB |
Output is correct |
7 |
Correct |
232 ms |
25960 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
10 ms |
1936 KB |
Output is correct |
13 |
Correct |
218 ms |
26008 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
5 ms |
1484 KB |
Output is correct |
17 |
Correct |
109 ms |
16040 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
58 ms |
7736 KB |
Output is correct |
21 |
Correct |
228 ms |
25924 KB |
Output is correct |
22 |
Correct |
225 ms |
26128 KB |
Output is correct |
23 |
Correct |
241 ms |
26024 KB |
Output is correct |
24 |
Correct |
222 ms |
26012 KB |
Output is correct |
25 |
Correct |
97 ms |
16036 KB |
Output is correct |
26 |
Correct |
94 ms |
16024 KB |
Output is correct |
27 |
Correct |
244 ms |
26016 KB |
Output is correct |
28 |
Correct |
220 ms |
25924 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
204 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
1 ms |
332 KB |
Output is correct |
36 |
Correct |
10 ms |
1996 KB |
Output is correct |
37 |
Correct |
220 ms |
28000 KB |
Output is correct |
38 |
Correct |
1 ms |
332 KB |
Output is correct |
39 |
Correct |
1 ms |
332 KB |
Output is correct |
40 |
Correct |
10 ms |
1996 KB |
Output is correct |
41 |
Correct |
228 ms |
27976 KB |
Output is correct |
42 |
Correct |
1 ms |
332 KB |
Output is correct |
43 |
Correct |
1 ms |
332 KB |
Output is correct |
44 |
Correct |
5 ms |
1588 KB |
Output is correct |
45 |
Correct |
108 ms |
18052 KB |
Output is correct |
46 |
Correct |
1 ms |
324 KB |
Output is correct |
47 |
Correct |
1 ms |
332 KB |
Output is correct |
48 |
Correct |
1 ms |
332 KB |
Output is correct |
49 |
Correct |
57 ms |
8172 KB |
Output is correct |
50 |
Correct |
229 ms |
27948 KB |
Output is correct |
51 |
Correct |
230 ms |
27972 KB |
Output is correct |
52 |
Correct |
245 ms |
27924 KB |
Output is correct |
53 |
Correct |
99 ms |
17988 KB |
Output is correct |
54 |
Correct |
98 ms |
18068 KB |
Output is correct |
55 |
Correct |
225 ms |
27880 KB |
Output is correct |
56 |
Correct |
238 ms |
27972 KB |
Output is correct |
57 |
Correct |
94 ms |
17988 KB |
Output is correct |
58 |
Correct |
1 ms |
332 KB |
Output is correct |
59 |
Correct |
0 ms |
332 KB |
Output is correct |
60 |
Correct |
1 ms |
384 KB |
Output is correct |
61 |
Correct |
57 ms |
7676 KB |
Output is correct |
62 |
Correct |
225 ms |
26020 KB |
Output is correct |
63 |
Correct |
227 ms |
25948 KB |
Output is correct |
64 |
Correct |
252 ms |
25916 KB |
Output is correct |
65 |
Correct |
1 ms |
332 KB |
Output is correct |
66 |
Correct |
58 ms |
7708 KB |
Output is correct |
67 |
Correct |
227 ms |
26016 KB |
Output is correct |
68 |
Correct |
223 ms |
25924 KB |
Output is correct |
69 |
Correct |
259 ms |
26052 KB |
Output is correct |
70 |
Correct |
1 ms |
332 KB |
Output is correct |
71 |
Correct |
1 ms |
332 KB |
Output is correct |
72 |
Correct |
1 ms |
332 KB |
Output is correct |
73 |
Correct |
57 ms |
7744 KB |
Output is correct |
74 |
Correct |
250 ms |
26084 KB |
Output is correct |
75 |
Correct |
226 ms |
25924 KB |
Output is correct |
76 |
Correct |
229 ms |
25968 KB |
Output is correct |
77 |
Correct |
220 ms |
26008 KB |
Output is correct |
78 |
Correct |
1 ms |
332 KB |
Output is correct |
79 |
Correct |
1 ms |
332 KB |
Output is correct |
80 |
Correct |
5 ms |
1612 KB |
Output is correct |
81 |
Correct |
108 ms |
17988 KB |
Output is correct |
82 |
Correct |
1 ms |
332 KB |
Output is correct |
83 |
Correct |
1 ms |
332 KB |
Output is correct |
84 |
Correct |
1 ms |
332 KB |
Output is correct |
85 |
Correct |
57 ms |
8204 KB |
Output is correct |
86 |
Correct |
101 ms |
17960 KB |
Output is correct |
87 |
Correct |
103 ms |
18124 KB |
Output is correct |
88 |
Correct |
98 ms |
17944 KB |
Output is correct |
89 |
Correct |
95 ms |
18064 KB |
Output is correct |
90 |
Correct |
1 ms |
332 KB |
Output is correct |
91 |
Correct |
1 ms |
320 KB |
Output is correct |
92 |
Correct |
5 ms |
1612 KB |
Output is correct |
93 |
Correct |
100 ms |
18064 KB |
Output is correct |
94 |
Correct |
1 ms |
332 KB |
Output is correct |
95 |
Correct |
1 ms |
320 KB |
Output is correct |
96 |
Correct |
1 ms |
328 KB |
Output is correct |
97 |
Correct |
24 ms |
5780 KB |
Output is correct |
98 |
Correct |
94 ms |
18064 KB |
Output is correct |
99 |
Correct |
92 ms |
17988 KB |
Output is correct |
100 |
Correct |
93 ms |
18068 KB |
Output is correct |
101 |
Correct |
92 ms |
18064 KB |
Output is correct |
102 |
Correct |
94 ms |
17944 KB |
Output is correct |
103 |
Correct |
92 ms |
18060 KB |
Output is correct |
104 |
Correct |
90 ms |
17948 KB |
Output is correct |
105 |
Correct |
97 ms |
17988 KB |
Output is correct |