#include "supertrees.h"
#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define pii pair<ll, ll>
const ll mod = 1e9 + 7;
const ll mxN = 1e6 + 5;
using namespace std;
int dsu[mxN];
int find(int x) { return dsu[x] == x ? x : dsu[x] = find(dsu[x]); }
void merge(int a, int b) { dsu[find(b)] = find(a); }
int construct(std::vector<std::vector<int>> p)
{
vector<vector<int>> b;
int n = p.size(), m = p.size();
b.resize(n);
for (int i = 0; i < n; i++)
dsu[i] = i;
for (int i = 0; i < n; i++)
b[i].resize(m);
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
if (i == j)
continue;
if (p[i][j] == 1)
{
if (find(i) != find(j))
{
merge(i, j);
b[i][j] = 1;
b[j][i] = 1;
}
}
}
}
vector<vector<int>> ty;
vector<set<int>> v;
v.resize(n);
ty.resize(n);
for (int i = 0; i < n; i++)
{
ty[i].resize(n);
for (int j = 0; j < m; j++)
{
ty[i][j] = -1;
}
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
if (i == j)
continue;
if (find(i) == find(j))
{
if (p[i][j] != 1)
return 0;
}
else
{
if (ty[i][j] != -1 && p[i][j] != ty[i][j])
return 0;
if (p[i][j] == 2)
v[find(i)].insert(find(j));
ty[i][j] = p[i][j];
}
}
}
vector<bool> vis(n);
for (int i = 0; i < n; i++)
{
int prv = -1;
if (vis[i])
continue;
if (v[i].size() == 1)
return 0;
v[i].insert(i);
for(auto x : v[i]){
for(int j = 0;j < n;j++){
if(x == j) continue;
if(v[i].find(j) != v[i].end() && p[x][j] != 2) return 0;
}
}
for (auto x : v[i])
{
vis[x] = 1;
if (prv != -1)
{
b[x][prv] = 1;
b[prv][x] = 1;
}
prv = x;
}
if (v[i].size() >= 2)
{
b[*v[i].begin()][*v[i].rbegin()] = 1;
b[*v[i].rbegin()][*v[i].begin()] = 1;
}
}
build(b);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
7 ms |
1368 KB |
Output is correct |
7 |
Correct |
155 ms |
26144 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 |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
7 ms |
1368 KB |
Output is correct |
7 |
Correct |
155 ms |
26144 KB |
Output is correct |
8 |
Correct |
1 ms |
344 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 |
7 ms |
1368 KB |
Output is correct |
13 |
Correct |
151 ms |
26196 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
4 ms |
864 KB |
Output is correct |
17 |
Correct |
71 ms |
16208 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
39 ms |
6736 KB |
Output is correct |
21 |
Correct |
155 ms |
26196 KB |
Output is correct |
22 |
Correct |
151 ms |
26040 KB |
Output is correct |
23 |
Correct |
160 ms |
26028 KB |
Output is correct |
24 |
Correct |
172 ms |
26128 KB |
Output is correct |
25 |
Correct |
61 ms |
16152 KB |
Output is correct |
26 |
Correct |
61 ms |
16164 KB |
Output is correct |
27 |
Correct |
164 ms |
26204 KB |
Output is correct |
28 |
Correct |
150 ms |
26192 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
6 ms |
1372 KB |
Output is correct |
9 |
Correct |
150 ms |
26144 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
10 ms |
3176 KB |
Output is correct |
13 |
Correct |
280 ms |
72932 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
5 ms |
1880 KB |
Output is correct |
17 |
Correct |
122 ms |
41492 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
392 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
40 ms |
7628 KB |
Output is correct |
22 |
Correct |
172 ms |
32596 KB |
Output is correct |
23 |
Correct |
156 ms |
28244 KB |
Output is correct |
24 |
Correct |
220 ms |
51536 KB |
Output is correct |
25 |
Correct |
65 ms |
18264 KB |
Output is correct |
26 |
Incorrect |
177 ms |
32848 KB |
Answer gives possible 1 while actual possible 0 |
27 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
41 ms |
6924 KB |
Output is correct |
5 |
Correct |
152 ms |
26192 KB |
Output is correct |
6 |
Correct |
156 ms |
26088 KB |
Output is correct |
7 |
Correct |
156 ms |
26172 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
42 ms |
7088 KB |
Output is correct |
10 |
Correct |
176 ms |
30936 KB |
Output is correct |
11 |
Correct |
163 ms |
26192 KB |
Output is correct |
12 |
Correct |
221 ms |
49436 KB |
Output is correct |
13 |
Correct |
1 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 |
44 ms |
6896 KB |
Output is correct |
17 |
Correct |
172 ms |
32596 KB |
Output is correct |
18 |
Correct |
169 ms |
30032 KB |
Output is correct |
19 |
Correct |
158 ms |
29016 KB |
Output is correct |
20 |
Correct |
153 ms |
28164 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 |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
7 ms |
1368 KB |
Output is correct |
7 |
Correct |
155 ms |
26144 KB |
Output is correct |
8 |
Correct |
1 ms |
344 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 |
7 ms |
1368 KB |
Output is correct |
13 |
Correct |
151 ms |
26196 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
4 ms |
864 KB |
Output is correct |
17 |
Correct |
71 ms |
16208 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
39 ms |
6736 KB |
Output is correct |
21 |
Correct |
155 ms |
26196 KB |
Output is correct |
22 |
Correct |
151 ms |
26040 KB |
Output is correct |
23 |
Correct |
160 ms |
26028 KB |
Output is correct |
24 |
Correct |
172 ms |
26128 KB |
Output is correct |
25 |
Correct |
61 ms |
16152 KB |
Output is correct |
26 |
Correct |
61 ms |
16164 KB |
Output is correct |
27 |
Correct |
164 ms |
26204 KB |
Output is correct |
28 |
Correct |
150 ms |
26192 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
344 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
6 ms |
1372 KB |
Output is correct |
37 |
Correct |
150 ms |
26144 KB |
Output is correct |
38 |
Correct |
1 ms |
344 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
10 ms |
3176 KB |
Output is correct |
41 |
Correct |
280 ms |
72932 KB |
Output is correct |
42 |
Correct |
0 ms |
344 KB |
Output is correct |
43 |
Correct |
0 ms |
344 KB |
Output is correct |
44 |
Correct |
5 ms |
1880 KB |
Output is correct |
45 |
Correct |
122 ms |
41492 KB |
Output is correct |
46 |
Correct |
1 ms |
348 KB |
Output is correct |
47 |
Correct |
1 ms |
392 KB |
Output is correct |
48 |
Correct |
1 ms |
344 KB |
Output is correct |
49 |
Correct |
40 ms |
7628 KB |
Output is correct |
50 |
Correct |
172 ms |
32596 KB |
Output is correct |
51 |
Correct |
156 ms |
28244 KB |
Output is correct |
52 |
Correct |
220 ms |
51536 KB |
Output is correct |
53 |
Correct |
65 ms |
18264 KB |
Output is correct |
54 |
Incorrect |
177 ms |
32848 KB |
Answer gives possible 1 while actual possible 0 |
55 |
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 |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
7 ms |
1368 KB |
Output is correct |
7 |
Correct |
155 ms |
26144 KB |
Output is correct |
8 |
Correct |
1 ms |
344 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 |
7 ms |
1368 KB |
Output is correct |
13 |
Correct |
151 ms |
26196 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
4 ms |
864 KB |
Output is correct |
17 |
Correct |
71 ms |
16208 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
39 ms |
6736 KB |
Output is correct |
21 |
Correct |
155 ms |
26196 KB |
Output is correct |
22 |
Correct |
151 ms |
26040 KB |
Output is correct |
23 |
Correct |
160 ms |
26028 KB |
Output is correct |
24 |
Correct |
172 ms |
26128 KB |
Output is correct |
25 |
Correct |
61 ms |
16152 KB |
Output is correct |
26 |
Correct |
61 ms |
16164 KB |
Output is correct |
27 |
Correct |
164 ms |
26204 KB |
Output is correct |
28 |
Correct |
150 ms |
26192 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
344 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
6 ms |
1372 KB |
Output is correct |
37 |
Correct |
150 ms |
26144 KB |
Output is correct |
38 |
Correct |
1 ms |
344 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
10 ms |
3176 KB |
Output is correct |
41 |
Correct |
280 ms |
72932 KB |
Output is correct |
42 |
Correct |
0 ms |
344 KB |
Output is correct |
43 |
Correct |
0 ms |
344 KB |
Output is correct |
44 |
Correct |
5 ms |
1880 KB |
Output is correct |
45 |
Correct |
122 ms |
41492 KB |
Output is correct |
46 |
Correct |
1 ms |
348 KB |
Output is correct |
47 |
Correct |
1 ms |
392 KB |
Output is correct |
48 |
Correct |
1 ms |
344 KB |
Output is correct |
49 |
Correct |
40 ms |
7628 KB |
Output is correct |
50 |
Correct |
172 ms |
32596 KB |
Output is correct |
51 |
Correct |
156 ms |
28244 KB |
Output is correct |
52 |
Correct |
220 ms |
51536 KB |
Output is correct |
53 |
Correct |
65 ms |
18264 KB |
Output is correct |
54 |
Incorrect |
177 ms |
32848 KB |
Answer gives possible 1 while actual possible 0 |
55 |
Halted |
0 ms |
0 KB |
- |