#include "supertrees.h"
#include <vector>
#include<bits/stdc++.h>
using namespace std;
vector<vector<int>> pp;
vector<vector<int>> adj;
int nn;
struct DSU
{
vector<int> e;
DSU(int _n)
{
e.assign(_n , -1);
}
int get(int u )
{
return (e[u] < 0 ? u : e[u] = get(e[u]));
}
bool same(int u , int v)
{
return get(u) == get(v);
}
void unite(int u , int v)
{
u = get(u) , v = get(v);
if(u == v)
return;
if(e[u] > e[v])
swap(u , v);
e[u]+=e[v];
e[v] = u;
}
};
bool check_conn()
{
DSU dsu(nn);
for(int i = 0 ; i < nn ;i++)
{
for(int j = 0 ; j < nn ; j++)
{
if(pp[i][j])
{
dsu.unite(i , j);
}
}
}
for(int i = 0 ; i < nn ; i++)
{
for(int j = 0 ; j < nn; j++)
{
if(pp[i][j] == 0 && dsu.same(i , j))
{
return 0;
}
}
}
DSU maker(nn);
for(int i = 0 ; i < nn ;i++)
{
for(int j = 0 ; j < nn ;j++)
{
if(pp[i][j] == 1)
{
maker.unite(i , j);
}
}
}
for(int i = 0 ; i < nn ; i++)
{
for(int j = 0 ; j < nn ; j++)
{
if(pp[i][j] == 3)
return 0;
if(pp[i][j] >= 2 && maker.same(i , j))
{
return 0;
}
}
}
vector<vector<int>> comp(nn);
for(int i = 0 ; i < nn ; i++)
{
comp[dsu.get(i)].push_back(i);
}
for(auto c : comp)
{
vector<int> v;
for(auto i : c)
{
int par = maker.get(i);
if(i == par)
{
v.push_back(i);
continue;
}
adj[par][i] = 1;
adj[i][par] = 1;
}
if((int)v.size() == 1)
continue;
if((int)v.size() == 2)
{
return 0;
}
for(int i = 0 ; i < (int)v.size() ; i++)
{
adj[v[i]][v[(i + 1)%((int)v.size())]] = 1;
adj[v[(i + 1)%((int)v.size())]][v[i]] = 1;
}
}
build(adj);
return 1;
}
int construct(std::vector<std::vector<int>> P) {
pp = P;
nn = (int)pp.size();
adj.assign(nn , vector<int>(nn));
return check_conn();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
436 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
5 ms |
1372 KB |
Output is correct |
7 |
Correct |
111 ms |
27220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
436 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
5 ms |
1372 KB |
Output is correct |
7 |
Correct |
111 ms |
27220 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
4 ms |
1372 KB |
Output is correct |
13 |
Correct |
104 ms |
27268 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
1116 KB |
Output is correct |
17 |
Correct |
63 ms |
17384 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
25 ms |
7180 KB |
Output is correct |
21 |
Correct |
111 ms |
27216 KB |
Output is correct |
22 |
Correct |
117 ms |
27232 KB |
Output is correct |
23 |
Correct |
139 ms |
27216 KB |
Output is correct |
24 |
Correct |
99 ms |
27476 KB |
Output is correct |
25 |
Correct |
49 ms |
17492 KB |
Output is correct |
26 |
Correct |
44 ms |
17488 KB |
Output is correct |
27 |
Correct |
110 ms |
27448 KB |
Output is correct |
28 |
Correct |
105 ms |
27420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
440 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
8 ms |
1372 KB |
Output is correct |
9 |
Correct |
112 ms |
27472 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
4 ms |
1372 KB |
Output is correct |
13 |
Correct |
101 ms |
27556 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
1116 KB |
Output is correct |
17 |
Correct |
67 ms |
17580 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
25 ms |
7240 KB |
Output is correct |
22 |
Correct |
109 ms |
27584 KB |
Output is correct |
23 |
Correct |
116 ms |
27472 KB |
Output is correct |
24 |
Correct |
117 ms |
27412 KB |
Output is correct |
25 |
Correct |
46 ms |
17720 KB |
Output is correct |
26 |
Correct |
46 ms |
17492 KB |
Output is correct |
27 |
Correct |
103 ms |
27504 KB |
Output is correct |
28 |
Correct |
117 ms |
27472 KB |
Output is correct |
29 |
Correct |
60 ms |
17700 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 |
428 KB |
Output is correct |
4 |
Correct |
29 ms |
7216 KB |
Output is correct |
5 |
Correct |
110 ms |
27308 KB |
Output is correct |
6 |
Correct |
142 ms |
27360 KB |
Output is correct |
7 |
Correct |
115 ms |
27260 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
28 ms |
7252 KB |
Output is correct |
10 |
Correct |
107 ms |
27216 KB |
Output is correct |
11 |
Correct |
106 ms |
27216 KB |
Output is correct |
12 |
Correct |
109 ms |
27220 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
26 ms |
7348 KB |
Output is correct |
17 |
Correct |
106 ms |
27464 KB |
Output is correct |
18 |
Correct |
106 ms |
27216 KB |
Output is correct |
19 |
Correct |
149 ms |
27220 KB |
Output is correct |
20 |
Correct |
139 ms |
27404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
436 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
5 ms |
1372 KB |
Output is correct |
7 |
Correct |
111 ms |
27220 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
4 ms |
1372 KB |
Output is correct |
13 |
Correct |
104 ms |
27268 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
1116 KB |
Output is correct |
17 |
Correct |
63 ms |
17384 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
25 ms |
7180 KB |
Output is correct |
21 |
Correct |
111 ms |
27216 KB |
Output is correct |
22 |
Correct |
117 ms |
27232 KB |
Output is correct |
23 |
Correct |
139 ms |
27216 KB |
Output is correct |
24 |
Correct |
99 ms |
27476 KB |
Output is correct |
25 |
Correct |
49 ms |
17492 KB |
Output is correct |
26 |
Correct |
44 ms |
17488 KB |
Output is correct |
27 |
Correct |
110 ms |
27448 KB |
Output is correct |
28 |
Correct |
105 ms |
27420 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
0 ms |
344 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
440 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
8 ms |
1372 KB |
Output is correct |
37 |
Correct |
112 ms |
27472 KB |
Output is correct |
38 |
Correct |
0 ms |
344 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
4 ms |
1372 KB |
Output is correct |
41 |
Correct |
101 ms |
27556 KB |
Output is correct |
42 |
Correct |
1 ms |
600 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
2 ms |
1116 KB |
Output is correct |
45 |
Correct |
67 ms |
17580 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
25 ms |
7240 KB |
Output is correct |
50 |
Correct |
109 ms |
27584 KB |
Output is correct |
51 |
Correct |
116 ms |
27472 KB |
Output is correct |
52 |
Correct |
117 ms |
27412 KB |
Output is correct |
53 |
Correct |
46 ms |
17720 KB |
Output is correct |
54 |
Correct |
46 ms |
17492 KB |
Output is correct |
55 |
Correct |
103 ms |
27504 KB |
Output is correct |
56 |
Correct |
117 ms |
27472 KB |
Output is correct |
57 |
Correct |
60 ms |
17700 KB |
Output is correct |
58 |
Correct |
0 ms |
344 KB |
Output is correct |
59 |
Correct |
0 ms |
348 KB |
Output is correct |
60 |
Correct |
2 ms |
1116 KB |
Output is correct |
61 |
Correct |
53 ms |
17372 KB |
Output is correct |
62 |
Correct |
0 ms |
348 KB |
Output is correct |
63 |
Correct |
0 ms |
348 KB |
Output is correct |
64 |
Correct |
0 ms |
348 KB |
Output is correct |
65 |
Correct |
28 ms |
7364 KB |
Output is correct |
66 |
Correct |
47 ms |
17488 KB |
Output is correct |
67 |
Correct |
45 ms |
17488 KB |
Output is correct |
68 |
Correct |
48 ms |
17500 KB |
Output is correct |
69 |
Correct |
49 ms |
17488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
436 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
5 ms |
1372 KB |
Output is correct |
7 |
Correct |
111 ms |
27220 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
4 ms |
1372 KB |
Output is correct |
13 |
Correct |
104 ms |
27268 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
1116 KB |
Output is correct |
17 |
Correct |
63 ms |
17384 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
25 ms |
7180 KB |
Output is correct |
21 |
Correct |
111 ms |
27216 KB |
Output is correct |
22 |
Correct |
117 ms |
27232 KB |
Output is correct |
23 |
Correct |
139 ms |
27216 KB |
Output is correct |
24 |
Correct |
99 ms |
27476 KB |
Output is correct |
25 |
Correct |
49 ms |
17492 KB |
Output is correct |
26 |
Correct |
44 ms |
17488 KB |
Output is correct |
27 |
Correct |
110 ms |
27448 KB |
Output is correct |
28 |
Correct |
105 ms |
27420 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
0 ms |
344 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
440 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
8 ms |
1372 KB |
Output is correct |
37 |
Correct |
112 ms |
27472 KB |
Output is correct |
38 |
Correct |
0 ms |
344 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
4 ms |
1372 KB |
Output is correct |
41 |
Correct |
101 ms |
27556 KB |
Output is correct |
42 |
Correct |
1 ms |
600 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
2 ms |
1116 KB |
Output is correct |
45 |
Correct |
67 ms |
17580 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
25 ms |
7240 KB |
Output is correct |
50 |
Correct |
109 ms |
27584 KB |
Output is correct |
51 |
Correct |
116 ms |
27472 KB |
Output is correct |
52 |
Correct |
117 ms |
27412 KB |
Output is correct |
53 |
Correct |
46 ms |
17720 KB |
Output is correct |
54 |
Correct |
46 ms |
17492 KB |
Output is correct |
55 |
Correct |
103 ms |
27504 KB |
Output is correct |
56 |
Correct |
117 ms |
27472 KB |
Output is correct |
57 |
Correct |
60 ms |
17700 KB |
Output is correct |
58 |
Correct |
0 ms |
348 KB |
Output is correct |
59 |
Correct |
0 ms |
348 KB |
Output is correct |
60 |
Correct |
0 ms |
428 KB |
Output is correct |
61 |
Correct |
29 ms |
7216 KB |
Output is correct |
62 |
Correct |
110 ms |
27308 KB |
Output is correct |
63 |
Correct |
142 ms |
27360 KB |
Output is correct |
64 |
Correct |
115 ms |
27260 KB |
Output is correct |
65 |
Correct |
1 ms |
348 KB |
Output is correct |
66 |
Correct |
28 ms |
7252 KB |
Output is correct |
67 |
Correct |
107 ms |
27216 KB |
Output is correct |
68 |
Correct |
106 ms |
27216 KB |
Output is correct |
69 |
Correct |
109 ms |
27220 KB |
Output is correct |
70 |
Correct |
0 ms |
348 KB |
Output is correct |
71 |
Correct |
0 ms |
348 KB |
Output is correct |
72 |
Correct |
0 ms |
348 KB |
Output is correct |
73 |
Correct |
26 ms |
7348 KB |
Output is correct |
74 |
Correct |
106 ms |
27464 KB |
Output is correct |
75 |
Correct |
106 ms |
27216 KB |
Output is correct |
76 |
Correct |
149 ms |
27220 KB |
Output is correct |
77 |
Correct |
139 ms |
27404 KB |
Output is correct |
78 |
Correct |
0 ms |
344 KB |
Output is correct |
79 |
Correct |
0 ms |
348 KB |
Output is correct |
80 |
Correct |
2 ms |
1116 KB |
Output is correct |
81 |
Correct |
53 ms |
17372 KB |
Output is correct |
82 |
Correct |
0 ms |
348 KB |
Output is correct |
83 |
Correct |
0 ms |
348 KB |
Output is correct |
84 |
Correct |
0 ms |
348 KB |
Output is correct |
85 |
Correct |
28 ms |
7364 KB |
Output is correct |
86 |
Correct |
47 ms |
17488 KB |
Output is correct |
87 |
Correct |
45 ms |
17488 KB |
Output is correct |
88 |
Correct |
48 ms |
17500 KB |
Output is correct |
89 |
Correct |
49 ms |
17488 KB |
Output is correct |
90 |
Correct |
0 ms |
348 KB |
Output is correct |
91 |
Correct |
0 ms |
432 KB |
Output is correct |
92 |
Correct |
2 ms |
1116 KB |
Output is correct |
93 |
Correct |
47 ms |
17440 KB |
Output is correct |
94 |
Correct |
0 ms |
344 KB |
Output is correct |
95 |
Correct |
0 ms |
348 KB |
Output is correct |
96 |
Correct |
0 ms |
348 KB |
Output is correct |
97 |
Correct |
12 ms |
4736 KB |
Output is correct |
98 |
Correct |
44 ms |
17376 KB |
Output is correct |
99 |
Correct |
46 ms |
17164 KB |
Output is correct |
100 |
Correct |
61 ms |
17232 KB |
Output is correct |
101 |
Correct |
51 ms |
17272 KB |
Output is correct |
102 |
Correct |
46 ms |
17236 KB |
Output is correct |
103 |
Correct |
46 ms |
17236 KB |
Output is correct |
104 |
Correct |
51 ms |
17236 KB |
Output is correct |
105 |
Correct |
58 ms |
17232 KB |
Output is correct |