#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 7;
vector < int > adj[N], visited(N);
bool first[N];
void dfs( int v ) {
visited[v] = 1;
for ( auto u: adj[v] ) {
if ( !visited[u] ) {
dfs(u);
}
}
}
int construct(std::vector<std::vector<int>> p) {
int n = p.size();
std::vector<std::vector<int>> answer;
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++ ) {
if ( i == j ) {
continue;
}
if ( p[i][j] == 1 ) {
adj[i].push_back(j);
}
if ( p[i][j] == 3 ) {
return 0;
}
}
}
vector < int > comp, used(n + 7);
for ( int i = 0; i < n; i++ ) {
if ( visited[i] ) {
continue;
}
for ( auto j: adj[i] ) {
visited[j] = 1;
}
comp.push_back(i);
}
int cnt = 0;
for ( int i = 0; i < n; i++ ) {
if ( used[i] ) {
continue;
}
used[i] = 1;
for ( auto j: adj[i] ) {
answer[i][j] = 1;
used[j] = 1;
answer[j][i] = 1;
for ( auto k: adj[i] ) {
if ( j != k && p[j][k] != 1 ) {
return 0;
}
}
}
}
int sz = comp.size();
used = vector < int > (n + 7);
for ( int i = 0; i < sz; i++ ) {
vector < int > vc = { comp[i] }, us(n + 7);
if ( used[ comp[i] ] ) {
continue;
}
used[ comp[i] ] = i + 1;
us[ comp[i] ] = 1;
for ( int j = 0; j < sz; j++ ) {
if ( i != j && p[ comp[i] ][ comp[j] ] == 2 ) {
vc.push_back(comp[j]);
us[comp[j]] = 1;
used[ comp[j] ] = i + 1;
}
}
for ( auto v: vc ) {
for ( int j = 0; j < sz; j++ ) {
int u = comp[j];
if ( v != u && p[ v ][u] == 0 ) {
for ( auto x: adj[v] ) {
for ( auto y: adj[u] ) {
if ( p[x][y] ) {
return 0;
}
}
}
}
if ( v != u && p[v][u] == 2 && !us[u] ) {
return 0;
}
}
}
int szz = vc.size();
if ( szz == 2 ) {
return 0;
}
for ( int i = 0; i < szz; i++ ) {
cnt += adj[ vc[i] ].size() + 1;
for ( int j = 0; j < szz; j++ ) {
if ( i == j ) {
continue;
}
if ( p[ vc[i] ][ vc[j] ] != 2 ) {
return 0;
}
int v = vc[i], u = vc[j];
for ( auto x: adj[v] ) {
for ( auto y: adj[u] ) {
if( p[x][y] != 2 ) {
return 0;
}
}
}
}
}
for ( int i = 0; i < szz - 1; i++ ) {
answer[vc[i]][vc[i + 1]] = 1;
answer[ vc[i + 1] ][ vc[i] ] = 1;
}
if ( szz > 1 ) {
answer[ vc[szz - 1] ][ vc[0] ] = 1;
answer[ vc[ 0 ] ][ vc[szz - 1] ] = 1;
}
}
if ( cnt != n ) {
return 0;
}
build(answer);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
11 ms |
1388 KB |
Output is correct |
7 |
Correct |
257 ms |
26092 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
11 ms |
1388 KB |
Output is correct |
7 |
Correct |
257 ms |
26092 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
11 ms |
1260 KB |
Output is correct |
13 |
Correct |
252 ms |
22124 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
0 ms |
364 KB |
Output is correct |
16 |
Correct |
5 ms |
876 KB |
Output is correct |
17 |
Correct |
127 ms |
14572 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
64 ms |
5928 KB |
Output is correct |
21 |
Correct |
259 ms |
22652 KB |
Output is correct |
22 |
Correct |
275 ms |
22252 KB |
Output is correct |
23 |
Correct |
259 ms |
24172 KB |
Output is correct |
24 |
Correct |
254 ms |
22252 KB |
Output is correct |
25 |
Correct |
109 ms |
12780 KB |
Output is correct |
26 |
Correct |
105 ms |
12268 KB |
Output is correct |
27 |
Correct |
262 ms |
25324 KB |
Output is correct |
28 |
Correct |
251 ms |
22124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
11 ms |
1260 KB |
Output is correct |
9 |
Correct |
263 ms |
22124 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
11 ms |
1260 KB |
Output is correct |
13 |
Correct |
251 ms |
22124 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
0 ms |
364 KB |
Output is correct |
16 |
Correct |
5 ms |
876 KB |
Output is correct |
17 |
Correct |
110 ms |
12268 KB |
Output is correct |
18 |
Correct |
0 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
64 ms |
5868 KB |
Output is correct |
22 |
Correct |
259 ms |
22252 KB |
Output is correct |
23 |
Correct |
251 ms |
22124 KB |
Output is correct |
24 |
Correct |
282 ms |
22252 KB |
Output is correct |
25 |
Correct |
107 ms |
12268 KB |
Output is correct |
26 |
Correct |
107 ms |
12268 KB |
Output is correct |
27 |
Correct |
252 ms |
22124 KB |
Output is correct |
28 |
Correct |
261 ms |
22508 KB |
Output is correct |
29 |
Correct |
109 ms |
12156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
66 ms |
5868 KB |
Output is correct |
5 |
Correct |
256 ms |
22764 KB |
Output is correct |
6 |
Correct |
254 ms |
22124 KB |
Output is correct |
7 |
Correct |
270 ms |
24300 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
69 ms |
5868 KB |
Output is correct |
10 |
Correct |
256 ms |
22156 KB |
Output is correct |
11 |
Correct |
257 ms |
22252 KB |
Output is correct |
12 |
Correct |
263 ms |
22380 KB |
Output is correct |
13 |
Correct |
1 ms |
496 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
64 ms |
5868 KB |
Output is correct |
17 |
Correct |
256 ms |
22252 KB |
Output is correct |
18 |
Correct |
253 ms |
22124 KB |
Output is correct |
19 |
Correct |
253 ms |
22252 KB |
Output is correct |
20 |
Correct |
255 ms |
22268 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
11 ms |
1388 KB |
Output is correct |
7 |
Correct |
257 ms |
26092 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
11 ms |
1260 KB |
Output is correct |
13 |
Correct |
252 ms |
22124 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
0 ms |
364 KB |
Output is correct |
16 |
Correct |
5 ms |
876 KB |
Output is correct |
17 |
Correct |
127 ms |
14572 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
64 ms |
5928 KB |
Output is correct |
21 |
Correct |
259 ms |
22652 KB |
Output is correct |
22 |
Correct |
275 ms |
22252 KB |
Output is correct |
23 |
Correct |
259 ms |
24172 KB |
Output is correct |
24 |
Correct |
254 ms |
22252 KB |
Output is correct |
25 |
Correct |
109 ms |
12780 KB |
Output is correct |
26 |
Correct |
105 ms |
12268 KB |
Output is correct |
27 |
Correct |
262 ms |
25324 KB |
Output is correct |
28 |
Correct |
251 ms |
22124 KB |
Output is correct |
29 |
Correct |
0 ms |
364 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
1 ms |
364 KB |
Output is correct |
35 |
Correct |
1 ms |
364 KB |
Output is correct |
36 |
Correct |
11 ms |
1260 KB |
Output is correct |
37 |
Correct |
263 ms |
22124 KB |
Output is correct |
38 |
Correct |
1 ms |
364 KB |
Output is correct |
39 |
Correct |
1 ms |
364 KB |
Output is correct |
40 |
Correct |
11 ms |
1260 KB |
Output is correct |
41 |
Correct |
251 ms |
22124 KB |
Output is correct |
42 |
Correct |
1 ms |
364 KB |
Output is correct |
43 |
Correct |
0 ms |
364 KB |
Output is correct |
44 |
Correct |
5 ms |
876 KB |
Output is correct |
45 |
Correct |
110 ms |
12268 KB |
Output is correct |
46 |
Correct |
0 ms |
364 KB |
Output is correct |
47 |
Correct |
1 ms |
364 KB |
Output is correct |
48 |
Correct |
1 ms |
364 KB |
Output is correct |
49 |
Correct |
64 ms |
5868 KB |
Output is correct |
50 |
Correct |
259 ms |
22252 KB |
Output is correct |
51 |
Correct |
251 ms |
22124 KB |
Output is correct |
52 |
Correct |
282 ms |
22252 KB |
Output is correct |
53 |
Correct |
107 ms |
12268 KB |
Output is correct |
54 |
Correct |
107 ms |
12268 KB |
Output is correct |
55 |
Correct |
252 ms |
22124 KB |
Output is correct |
56 |
Correct |
261 ms |
22508 KB |
Output is correct |
57 |
Correct |
109 ms |
12156 KB |
Output is correct |
58 |
Correct |
1 ms |
364 KB |
Output is correct |
59 |
Correct |
1 ms |
364 KB |
Output is correct |
60 |
Correct |
5 ms |
876 KB |
Output is correct |
61 |
Correct |
118 ms |
14188 KB |
Output is correct |
62 |
Correct |
1 ms |
364 KB |
Output is correct |
63 |
Correct |
1 ms |
364 KB |
Output is correct |
64 |
Correct |
1 ms |
512 KB |
Output is correct |
65 |
Correct |
81 ms |
5868 KB |
Output is correct |
66 |
Correct |
109 ms |
12268 KB |
Output is correct |
67 |
Correct |
110 ms |
12268 KB |
Output is correct |
68 |
Correct |
109 ms |
12268 KB |
Output is correct |
69 |
Correct |
119 ms |
12268 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
11 ms |
1388 KB |
Output is correct |
7 |
Correct |
257 ms |
26092 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
11 ms |
1260 KB |
Output is correct |
13 |
Correct |
252 ms |
22124 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
0 ms |
364 KB |
Output is correct |
16 |
Correct |
5 ms |
876 KB |
Output is correct |
17 |
Correct |
127 ms |
14572 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
64 ms |
5928 KB |
Output is correct |
21 |
Correct |
259 ms |
22652 KB |
Output is correct |
22 |
Correct |
275 ms |
22252 KB |
Output is correct |
23 |
Correct |
259 ms |
24172 KB |
Output is correct |
24 |
Correct |
254 ms |
22252 KB |
Output is correct |
25 |
Correct |
109 ms |
12780 KB |
Output is correct |
26 |
Correct |
105 ms |
12268 KB |
Output is correct |
27 |
Correct |
262 ms |
25324 KB |
Output is correct |
28 |
Correct |
251 ms |
22124 KB |
Output is correct |
29 |
Correct |
0 ms |
364 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
1 ms |
364 KB |
Output is correct |
35 |
Correct |
1 ms |
364 KB |
Output is correct |
36 |
Correct |
11 ms |
1260 KB |
Output is correct |
37 |
Correct |
263 ms |
22124 KB |
Output is correct |
38 |
Correct |
1 ms |
364 KB |
Output is correct |
39 |
Correct |
1 ms |
364 KB |
Output is correct |
40 |
Correct |
11 ms |
1260 KB |
Output is correct |
41 |
Correct |
251 ms |
22124 KB |
Output is correct |
42 |
Correct |
1 ms |
364 KB |
Output is correct |
43 |
Correct |
0 ms |
364 KB |
Output is correct |
44 |
Correct |
5 ms |
876 KB |
Output is correct |
45 |
Correct |
110 ms |
12268 KB |
Output is correct |
46 |
Correct |
0 ms |
364 KB |
Output is correct |
47 |
Correct |
1 ms |
364 KB |
Output is correct |
48 |
Correct |
1 ms |
364 KB |
Output is correct |
49 |
Correct |
64 ms |
5868 KB |
Output is correct |
50 |
Correct |
259 ms |
22252 KB |
Output is correct |
51 |
Correct |
251 ms |
22124 KB |
Output is correct |
52 |
Correct |
282 ms |
22252 KB |
Output is correct |
53 |
Correct |
107 ms |
12268 KB |
Output is correct |
54 |
Correct |
107 ms |
12268 KB |
Output is correct |
55 |
Correct |
252 ms |
22124 KB |
Output is correct |
56 |
Correct |
261 ms |
22508 KB |
Output is correct |
57 |
Correct |
109 ms |
12156 KB |
Output is correct |
58 |
Correct |
1 ms |
364 KB |
Output is correct |
59 |
Correct |
1 ms |
364 KB |
Output is correct |
60 |
Correct |
1 ms |
364 KB |
Output is correct |
61 |
Correct |
66 ms |
5868 KB |
Output is correct |
62 |
Correct |
256 ms |
22764 KB |
Output is correct |
63 |
Correct |
254 ms |
22124 KB |
Output is correct |
64 |
Correct |
270 ms |
24300 KB |
Output is correct |
65 |
Correct |
1 ms |
364 KB |
Output is correct |
66 |
Correct |
69 ms |
5868 KB |
Output is correct |
67 |
Correct |
256 ms |
22156 KB |
Output is correct |
68 |
Correct |
257 ms |
22252 KB |
Output is correct |
69 |
Correct |
263 ms |
22380 KB |
Output is correct |
70 |
Correct |
1 ms |
496 KB |
Output is correct |
71 |
Correct |
1 ms |
364 KB |
Output is correct |
72 |
Correct |
1 ms |
364 KB |
Output is correct |
73 |
Correct |
64 ms |
5868 KB |
Output is correct |
74 |
Correct |
256 ms |
22252 KB |
Output is correct |
75 |
Correct |
253 ms |
22124 KB |
Output is correct |
76 |
Correct |
253 ms |
22252 KB |
Output is correct |
77 |
Correct |
255 ms |
22268 KB |
Output is correct |
78 |
Correct |
1 ms |
364 KB |
Output is correct |
79 |
Correct |
1 ms |
364 KB |
Output is correct |
80 |
Correct |
5 ms |
876 KB |
Output is correct |
81 |
Correct |
118 ms |
14188 KB |
Output is correct |
82 |
Correct |
1 ms |
364 KB |
Output is correct |
83 |
Correct |
1 ms |
364 KB |
Output is correct |
84 |
Correct |
1 ms |
512 KB |
Output is correct |
85 |
Correct |
81 ms |
5868 KB |
Output is correct |
86 |
Correct |
109 ms |
12268 KB |
Output is correct |
87 |
Correct |
110 ms |
12268 KB |
Output is correct |
88 |
Correct |
109 ms |
12268 KB |
Output is correct |
89 |
Correct |
119 ms |
12268 KB |
Output is correct |
90 |
Correct |
1 ms |
364 KB |
Output is correct |
91 |
Correct |
1 ms |
364 KB |
Output is correct |
92 |
Correct |
5 ms |
876 KB |
Output is correct |
93 |
Correct |
104 ms |
12140 KB |
Output is correct |
94 |
Correct |
1 ms |
364 KB |
Output is correct |
95 |
Correct |
0 ms |
364 KB |
Output is correct |
96 |
Correct |
1 ms |
364 KB |
Output is correct |
97 |
Correct |
26 ms |
3820 KB |
Output is correct |
98 |
Correct |
107 ms |
14188 KB |
Output is correct |
99 |
Correct |
104 ms |
14188 KB |
Output is correct |
100 |
Correct |
104 ms |
14188 KB |
Output is correct |
101 |
Correct |
119 ms |
14444 KB |
Output is correct |
102 |
Correct |
105 ms |
14204 KB |
Output is correct |
103 |
Correct |
104 ms |
14188 KB |
Output is correct |
104 |
Correct |
103 ms |
14188 KB |
Output is correct |
105 |
Correct |
110 ms |
14316 KB |
Output is correct |