#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] >= 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;
map<int , vector<int>> trees;
for(auto i : c)
{
int par = maker.get(i);
trees[par].push_back(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 |
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 |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
5 ms |
1420 KB |
Output is correct |
7 |
Correct |
100 ms |
27900 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 |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
5 ms |
1420 KB |
Output is correct |
7 |
Correct |
100 ms |
27900 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
432 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
4 ms |
1372 KB |
Output is correct |
13 |
Correct |
118 ms |
28040 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
936 KB |
Output is correct |
17 |
Correct |
53 ms |
18056 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
27 ms |
7256 KB |
Output is correct |
21 |
Correct |
106 ms |
27912 KB |
Output is correct |
22 |
Correct |
108 ms |
27984 KB |
Output is correct |
23 |
Correct |
109 ms |
27984 KB |
Output is correct |
24 |
Correct |
101 ms |
27916 KB |
Output is correct |
25 |
Correct |
48 ms |
18000 KB |
Output is correct |
26 |
Correct |
43 ms |
18184 KB |
Output is correct |
27 |
Correct |
105 ms |
27988 KB |
Output is correct |
28 |
Correct |
107 ms |
27984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
432 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
5 ms |
1396 KB |
Output is correct |
9 |
Correct |
104 ms |
27280 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 |
101 ms |
27408 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
1116 KB |
Output is correct |
17 |
Correct |
57 ms |
17272 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
436 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
26 ms |
7252 KB |
Output is correct |
22 |
Correct |
106 ms |
27396 KB |
Output is correct |
23 |
Correct |
99 ms |
27220 KB |
Output is correct |
24 |
Correct |
110 ms |
27216 KB |
Output is correct |
25 |
Correct |
51 ms |
17488 KB |
Output is correct |
26 |
Correct |
46 ms |
17336 KB |
Output is correct |
27 |
Correct |
100 ms |
27212 KB |
Output is correct |
28 |
Correct |
110 ms |
27220 KB |
Output is correct |
29 |
Correct |
49 ms |
17492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
25 ms |
7372 KB |
Output is correct |
5 |
Correct |
103 ms |
27908 KB |
Output is correct |
6 |
Correct |
98 ms |
28032 KB |
Output is correct |
7 |
Correct |
105 ms |
27984 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
25 ms |
7368 KB |
Output is correct |
10 |
Correct |
99 ms |
28040 KB |
Output is correct |
11 |
Correct |
103 ms |
27984 KB |
Output is correct |
12 |
Correct |
114 ms |
27912 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
31 ms |
7292 KB |
Output is correct |
17 |
Correct |
111 ms |
27988 KB |
Output is correct |
18 |
Correct |
109 ms |
27984 KB |
Output is correct |
19 |
Correct |
100 ms |
27988 KB |
Output is correct |
20 |
Correct |
99 ms |
27912 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 |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
5 ms |
1420 KB |
Output is correct |
7 |
Correct |
100 ms |
27900 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
432 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
4 ms |
1372 KB |
Output is correct |
13 |
Correct |
118 ms |
28040 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
936 KB |
Output is correct |
17 |
Correct |
53 ms |
18056 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
27 ms |
7256 KB |
Output is correct |
21 |
Correct |
106 ms |
27912 KB |
Output is correct |
22 |
Correct |
108 ms |
27984 KB |
Output is correct |
23 |
Correct |
109 ms |
27984 KB |
Output is correct |
24 |
Correct |
101 ms |
27916 KB |
Output is correct |
25 |
Correct |
48 ms |
18000 KB |
Output is correct |
26 |
Correct |
43 ms |
18184 KB |
Output is correct |
27 |
Correct |
105 ms |
27988 KB |
Output is correct |
28 |
Correct |
107 ms |
27984 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
432 KB |
Output is correct |
31 |
Correct |
0 ms |
344 KB |
Output is correct |
32 |
Correct |
0 ms |
344 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
5 ms |
1396 KB |
Output is correct |
37 |
Correct |
104 ms |
27280 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
5 ms |
1372 KB |
Output is correct |
41 |
Correct |
101 ms |
27408 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
3 ms |
1116 KB |
Output is correct |
45 |
Correct |
57 ms |
17272 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
0 ms |
436 KB |
Output is correct |
48 |
Correct |
1 ms |
348 KB |
Output is correct |
49 |
Correct |
26 ms |
7252 KB |
Output is correct |
50 |
Correct |
106 ms |
27396 KB |
Output is correct |
51 |
Correct |
99 ms |
27220 KB |
Output is correct |
52 |
Correct |
110 ms |
27216 KB |
Output is correct |
53 |
Correct |
51 ms |
17488 KB |
Output is correct |
54 |
Correct |
46 ms |
17336 KB |
Output is correct |
55 |
Correct |
100 ms |
27212 KB |
Output is correct |
56 |
Correct |
110 ms |
27220 KB |
Output is correct |
57 |
Correct |
49 ms |
17492 KB |
Output is correct |
58 |
Correct |
1 ms |
348 KB |
Output is correct |
59 |
Correct |
0 ms |
348 KB |
Output is correct |
60 |
Correct |
2 ms |
1116 KB |
Output is correct |
61 |
Correct |
56 ms |
17928 KB |
Output is correct |
62 |
Correct |
1 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 |
26 ms |
7212 KB |
Output is correct |
66 |
Correct |
46 ms |
18040 KB |
Output is correct |
67 |
Correct |
52 ms |
17960 KB |
Output is correct |
68 |
Correct |
45 ms |
18004 KB |
Output is correct |
69 |
Correct |
48 ms |
18000 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 |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
5 ms |
1420 KB |
Output is correct |
7 |
Correct |
100 ms |
27900 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
432 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
4 ms |
1372 KB |
Output is correct |
13 |
Correct |
118 ms |
28040 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
936 KB |
Output is correct |
17 |
Correct |
53 ms |
18056 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
27 ms |
7256 KB |
Output is correct |
21 |
Correct |
106 ms |
27912 KB |
Output is correct |
22 |
Correct |
108 ms |
27984 KB |
Output is correct |
23 |
Correct |
109 ms |
27984 KB |
Output is correct |
24 |
Correct |
101 ms |
27916 KB |
Output is correct |
25 |
Correct |
48 ms |
18000 KB |
Output is correct |
26 |
Correct |
43 ms |
18184 KB |
Output is correct |
27 |
Correct |
105 ms |
27988 KB |
Output is correct |
28 |
Correct |
107 ms |
27984 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
432 KB |
Output is correct |
31 |
Correct |
0 ms |
344 KB |
Output is correct |
32 |
Correct |
0 ms |
344 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
5 ms |
1396 KB |
Output is correct |
37 |
Correct |
104 ms |
27280 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
5 ms |
1372 KB |
Output is correct |
41 |
Correct |
101 ms |
27408 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
3 ms |
1116 KB |
Output is correct |
45 |
Correct |
57 ms |
17272 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
0 ms |
436 KB |
Output is correct |
48 |
Correct |
1 ms |
348 KB |
Output is correct |
49 |
Correct |
26 ms |
7252 KB |
Output is correct |
50 |
Correct |
106 ms |
27396 KB |
Output is correct |
51 |
Correct |
99 ms |
27220 KB |
Output is correct |
52 |
Correct |
110 ms |
27216 KB |
Output is correct |
53 |
Correct |
51 ms |
17488 KB |
Output is correct |
54 |
Correct |
46 ms |
17336 KB |
Output is correct |
55 |
Correct |
100 ms |
27212 KB |
Output is correct |
56 |
Correct |
110 ms |
27220 KB |
Output is correct |
57 |
Correct |
49 ms |
17492 KB |
Output is correct |
58 |
Correct |
1 ms |
348 KB |
Output is correct |
59 |
Correct |
0 ms |
348 KB |
Output is correct |
60 |
Correct |
0 ms |
348 KB |
Output is correct |
61 |
Correct |
25 ms |
7372 KB |
Output is correct |
62 |
Correct |
103 ms |
27908 KB |
Output is correct |
63 |
Correct |
98 ms |
28032 KB |
Output is correct |
64 |
Correct |
105 ms |
27984 KB |
Output is correct |
65 |
Correct |
0 ms |
344 KB |
Output is correct |
66 |
Correct |
25 ms |
7368 KB |
Output is correct |
67 |
Correct |
99 ms |
28040 KB |
Output is correct |
68 |
Correct |
103 ms |
27984 KB |
Output is correct |
69 |
Correct |
114 ms |
27912 KB |
Output is correct |
70 |
Correct |
1 ms |
344 KB |
Output is correct |
71 |
Correct |
0 ms |
348 KB |
Output is correct |
72 |
Correct |
0 ms |
348 KB |
Output is correct |
73 |
Correct |
31 ms |
7292 KB |
Output is correct |
74 |
Correct |
111 ms |
27988 KB |
Output is correct |
75 |
Correct |
109 ms |
27984 KB |
Output is correct |
76 |
Correct |
100 ms |
27988 KB |
Output is correct |
77 |
Correct |
99 ms |
27912 KB |
Output is correct |
78 |
Correct |
1 ms |
348 KB |
Output is correct |
79 |
Correct |
0 ms |
348 KB |
Output is correct |
80 |
Correct |
2 ms |
1116 KB |
Output is correct |
81 |
Correct |
56 ms |
17928 KB |
Output is correct |
82 |
Correct |
1 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 |
26 ms |
7212 KB |
Output is correct |
86 |
Correct |
46 ms |
18040 KB |
Output is correct |
87 |
Correct |
52 ms |
17960 KB |
Output is correct |
88 |
Correct |
45 ms |
18004 KB |
Output is correct |
89 |
Correct |
48 ms |
18000 KB |
Output is correct |
90 |
Correct |
0 ms |
348 KB |
Output is correct |
91 |
Correct |
0 ms |
348 KB |
Output is correct |
92 |
Correct |
3 ms |
1116 KB |
Output is correct |
93 |
Correct |
52 ms |
18008 KB |
Output is correct |
94 |
Incorrect |
0 ms |
348 KB |
Answer gives possible 1 while actual possible 0 |
95 |
Halted |
0 ms |
0 KB |
- |