#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e3 + 7;
vector < int > used, adj[MAXN];
vector < vector < int > > ans;
void dfs( int v ) {
used[v] = 1;
for ( auto u: adj[v] ) {
ans[v][u] = 1;
ans[u][v] = 1;
if ( !used[u] ) {
dfs( u );
}
}
}
int construct(std::vector<std::vector<int>> p) {
int n = p.size();
vector < int > roots, rt(n);
used.assign(n, 0);
ans.clear();
for ( int i = 0; i < n; i++ ) {
vector < int > vc(n);
ans.push_back(vc);
for ( int j = 0; j < n; j++ ) {
if ( p[i][j] == 3 ) {
return 0;
}
}
}
for ( int i = 0; i < n; i++ ) {
if ( used[i] ) {
continue;
}
used[i] = 1;
roots.push_back(i);
rt[i] = 1;
cerr << i << ' ';
for ( int j = 0; j < n; j++ ) {
if ( i == j ) {
if ( p[i][j] != 1 ) {
cerr << "here1" << endl;
return 0;
}
continue;
}
if ( p[i][j] == 1 ) {
adj[i].push_back(j);
adj[j].push_back(i);
used[j] = 1;
}
}
vector < int > nb(n);
for ( auto v: adj[i] ) {
nb[v] = 1;
for ( auto u: adj[i] ) {
if ( p[v][u] != 1 ) {
cerr << "here4" << endl;
return 0;
}
}
}
nb[i] = 1;
for ( auto v: adj[i] ) {
for ( int j = 0; j < n; j++ ) {
if ( !nb[j] && p[v][j] == 1 ) {
return 0;
}
}
}
}
cerr << endl;
used.assign(n, 0);
for ( auto i: roots ) {
if ( used[i] ) {
continue;
}
vector < int > cycle = { i }, cy(n);
used[i] = 1;
cy[i] = 1;
for ( auto j: roots ) {
if ( i != j && p[i][j] == 2 ) {
if ( used[j] ) {
return 0;
}
cycle.push_back(j);
cy[j] = 1;
}
}
if ( cycle.size() == 2 ) {
cerr << "here" << 5 << endl;
return 0;
}
if ( cycle.size() == 1 ) {
continue;
}
cerr << i << ' ';
for ( int j = 1; j < (int)cycle.size(); j++ ) {
adj[ cycle[j] ].push_back( cycle[j - 1] );
adj[ cycle[j - 1] ].push_back( cycle[j] );
used[cycle[j]] = 1;
cerr << cycle[j] << " ";
}
cerr << endl;
adj[ cycle.back() ].push_back(i);
adj[i].push_back( cycle.back() );
for ( auto v: cycle ) {
for ( auto u: cycle ) {
if ( v == u ) {
continue;
}
if ( p[v][u] != 2 ) {
return 0;
}
for ( auto x: adj[v] ) {
for ( auto y: adj[u] ) {
if ( cy[x] || cy[y] ) {
continue;
}
if ( p[x][y] != 2 ) {
cerr << "Here6" << endl;
return 0;
}
}
if ( !cy[x] && p[x][u] != 2 ) {
return 0;
}
}
}
for ( int j = 0; j < n; j++ ) {
if ( j != v && p[v][j] == 2 && rt[j] && !cy[j] ) {
return 0;
}
}
}
}
used.assign(n, 0);
for ( int i = 0; i < n; i++ ) {
if ( !used[i] ) {
dfs( i );
}
}
build(ans);
return 1;
}
/*
4
1 1 2 2
1 1 2 2
2 2 1 2
2 2 2 1
2
1 0
0 1
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
12 ms |
1192 KB |
Output is correct |
7 |
Correct |
262 ms |
22028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
12 ms |
1192 KB |
Output is correct |
7 |
Correct |
262 ms |
22028 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
15 ms |
1120 KB |
Output is correct |
13 |
Correct |
253 ms |
22040 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
5 ms |
740 KB |
Output is correct |
17 |
Correct |
118 ms |
12192 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
69 ms |
5772 KB |
Output is correct |
21 |
Correct |
239 ms |
22036 KB |
Output is correct |
22 |
Correct |
244 ms |
22032 KB |
Output is correct |
23 |
Correct |
258 ms |
22080 KB |
Output is correct |
24 |
Correct |
252 ms |
22176 KB |
Output is correct |
25 |
Correct |
102 ms |
12180 KB |
Output is correct |
26 |
Correct |
103 ms |
12052 KB |
Output is correct |
27 |
Correct |
263 ms |
22020 KB |
Output is correct |
28 |
Correct |
237 ms |
22052 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
16 ms |
1120 KB |
Output is correct |
9 |
Correct |
300 ms |
22048 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
12 ms |
1228 KB |
Output is correct |
13 |
Correct |
252 ms |
22176 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
8 ms |
716 KB |
Output is correct |
17 |
Correct |
114 ms |
12180 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
63 ms |
5768 KB |
Output is correct |
22 |
Correct |
254 ms |
22132 KB |
Output is correct |
23 |
Correct |
241 ms |
22044 KB |
Output is correct |
24 |
Correct |
257 ms |
22084 KB |
Output is correct |
25 |
Correct |
108 ms |
12176 KB |
Output is correct |
26 |
Correct |
132 ms |
12180 KB |
Output is correct |
27 |
Correct |
244 ms |
22052 KB |
Output is correct |
28 |
Correct |
261 ms |
22148 KB |
Output is correct |
29 |
Correct |
106 ms |
12100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
63 ms |
5776 KB |
Output is correct |
5 |
Correct |
233 ms |
22064 KB |
Output is correct |
6 |
Correct |
235 ms |
22212 KB |
Output is correct |
7 |
Correct |
246 ms |
22044 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
65 ms |
5700 KB |
Output is correct |
10 |
Correct |
249 ms |
22036 KB |
Output is correct |
11 |
Correct |
247 ms |
22028 KB |
Output is correct |
12 |
Correct |
256 ms |
22084 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
300 KB |
Output is correct |
16 |
Correct |
62 ms |
5700 KB |
Output is correct |
17 |
Correct |
256 ms |
22044 KB |
Output is correct |
18 |
Correct |
242 ms |
22032 KB |
Output is correct |
19 |
Correct |
239 ms |
22084 KB |
Output is correct |
20 |
Correct |
238 ms |
22028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
12 ms |
1192 KB |
Output is correct |
7 |
Correct |
262 ms |
22028 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
15 ms |
1120 KB |
Output is correct |
13 |
Correct |
253 ms |
22040 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
5 ms |
740 KB |
Output is correct |
17 |
Correct |
118 ms |
12192 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
69 ms |
5772 KB |
Output is correct |
21 |
Correct |
239 ms |
22036 KB |
Output is correct |
22 |
Correct |
244 ms |
22032 KB |
Output is correct |
23 |
Correct |
258 ms |
22080 KB |
Output is correct |
24 |
Correct |
252 ms |
22176 KB |
Output is correct |
25 |
Correct |
102 ms |
12180 KB |
Output is correct |
26 |
Correct |
103 ms |
12052 KB |
Output is correct |
27 |
Correct |
263 ms |
22020 KB |
Output is correct |
28 |
Correct |
237 ms |
22052 KB |
Output is correct |
29 |
Correct |
1 ms |
204 KB |
Output is correct |
30 |
Correct |
1 ms |
204 KB |
Output is correct |
31 |
Correct |
1 ms |
204 KB |
Output is correct |
32 |
Correct |
1 ms |
204 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |
34 |
Correct |
1 ms |
204 KB |
Output is correct |
35 |
Correct |
1 ms |
204 KB |
Output is correct |
36 |
Correct |
16 ms |
1120 KB |
Output is correct |
37 |
Correct |
300 ms |
22048 KB |
Output is correct |
38 |
Correct |
1 ms |
204 KB |
Output is correct |
39 |
Correct |
1 ms |
204 KB |
Output is correct |
40 |
Correct |
12 ms |
1228 KB |
Output is correct |
41 |
Correct |
252 ms |
22176 KB |
Output is correct |
42 |
Correct |
1 ms |
204 KB |
Output is correct |
43 |
Correct |
1 ms |
204 KB |
Output is correct |
44 |
Correct |
8 ms |
716 KB |
Output is correct |
45 |
Correct |
114 ms |
12180 KB |
Output is correct |
46 |
Correct |
1 ms |
204 KB |
Output is correct |
47 |
Correct |
1 ms |
204 KB |
Output is correct |
48 |
Correct |
1 ms |
204 KB |
Output is correct |
49 |
Correct |
63 ms |
5768 KB |
Output is correct |
50 |
Correct |
254 ms |
22132 KB |
Output is correct |
51 |
Correct |
241 ms |
22044 KB |
Output is correct |
52 |
Correct |
257 ms |
22084 KB |
Output is correct |
53 |
Correct |
108 ms |
12176 KB |
Output is correct |
54 |
Correct |
132 ms |
12180 KB |
Output is correct |
55 |
Correct |
244 ms |
22052 KB |
Output is correct |
56 |
Correct |
261 ms |
22148 KB |
Output is correct |
57 |
Correct |
106 ms |
12100 KB |
Output is correct |
58 |
Correct |
1 ms |
204 KB |
Output is correct |
59 |
Correct |
1 ms |
204 KB |
Output is correct |
60 |
Correct |
5 ms |
716 KB |
Output is correct |
61 |
Correct |
109 ms |
12192 KB |
Output is correct |
62 |
Correct |
1 ms |
204 KB |
Output is correct |
63 |
Correct |
1 ms |
204 KB |
Output is correct |
64 |
Correct |
1 ms |
204 KB |
Output is correct |
65 |
Correct |
63 ms |
5780 KB |
Output is correct |
66 |
Correct |
107 ms |
12100 KB |
Output is correct |
67 |
Correct |
100 ms |
12060 KB |
Output is correct |
68 |
Correct |
111 ms |
12228 KB |
Output is correct |
69 |
Correct |
104 ms |
12068 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
12 ms |
1192 KB |
Output is correct |
7 |
Correct |
262 ms |
22028 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
15 ms |
1120 KB |
Output is correct |
13 |
Correct |
253 ms |
22040 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
5 ms |
740 KB |
Output is correct |
17 |
Correct |
118 ms |
12192 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
69 ms |
5772 KB |
Output is correct |
21 |
Correct |
239 ms |
22036 KB |
Output is correct |
22 |
Correct |
244 ms |
22032 KB |
Output is correct |
23 |
Correct |
258 ms |
22080 KB |
Output is correct |
24 |
Correct |
252 ms |
22176 KB |
Output is correct |
25 |
Correct |
102 ms |
12180 KB |
Output is correct |
26 |
Correct |
103 ms |
12052 KB |
Output is correct |
27 |
Correct |
263 ms |
22020 KB |
Output is correct |
28 |
Correct |
237 ms |
22052 KB |
Output is correct |
29 |
Correct |
1 ms |
204 KB |
Output is correct |
30 |
Correct |
1 ms |
204 KB |
Output is correct |
31 |
Correct |
1 ms |
204 KB |
Output is correct |
32 |
Correct |
1 ms |
204 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |
34 |
Correct |
1 ms |
204 KB |
Output is correct |
35 |
Correct |
1 ms |
204 KB |
Output is correct |
36 |
Correct |
16 ms |
1120 KB |
Output is correct |
37 |
Correct |
300 ms |
22048 KB |
Output is correct |
38 |
Correct |
1 ms |
204 KB |
Output is correct |
39 |
Correct |
1 ms |
204 KB |
Output is correct |
40 |
Correct |
12 ms |
1228 KB |
Output is correct |
41 |
Correct |
252 ms |
22176 KB |
Output is correct |
42 |
Correct |
1 ms |
204 KB |
Output is correct |
43 |
Correct |
1 ms |
204 KB |
Output is correct |
44 |
Correct |
8 ms |
716 KB |
Output is correct |
45 |
Correct |
114 ms |
12180 KB |
Output is correct |
46 |
Correct |
1 ms |
204 KB |
Output is correct |
47 |
Correct |
1 ms |
204 KB |
Output is correct |
48 |
Correct |
1 ms |
204 KB |
Output is correct |
49 |
Correct |
63 ms |
5768 KB |
Output is correct |
50 |
Correct |
254 ms |
22132 KB |
Output is correct |
51 |
Correct |
241 ms |
22044 KB |
Output is correct |
52 |
Correct |
257 ms |
22084 KB |
Output is correct |
53 |
Correct |
108 ms |
12176 KB |
Output is correct |
54 |
Correct |
132 ms |
12180 KB |
Output is correct |
55 |
Correct |
244 ms |
22052 KB |
Output is correct |
56 |
Correct |
261 ms |
22148 KB |
Output is correct |
57 |
Correct |
106 ms |
12100 KB |
Output is correct |
58 |
Correct |
1 ms |
204 KB |
Output is correct |
59 |
Correct |
1 ms |
204 KB |
Output is correct |
60 |
Correct |
1 ms |
204 KB |
Output is correct |
61 |
Correct |
63 ms |
5776 KB |
Output is correct |
62 |
Correct |
233 ms |
22064 KB |
Output is correct |
63 |
Correct |
235 ms |
22212 KB |
Output is correct |
64 |
Correct |
246 ms |
22044 KB |
Output is correct |
65 |
Correct |
1 ms |
204 KB |
Output is correct |
66 |
Correct |
65 ms |
5700 KB |
Output is correct |
67 |
Correct |
249 ms |
22036 KB |
Output is correct |
68 |
Correct |
247 ms |
22028 KB |
Output is correct |
69 |
Correct |
256 ms |
22084 KB |
Output is correct |
70 |
Correct |
1 ms |
204 KB |
Output is correct |
71 |
Correct |
1 ms |
204 KB |
Output is correct |
72 |
Correct |
1 ms |
300 KB |
Output is correct |
73 |
Correct |
62 ms |
5700 KB |
Output is correct |
74 |
Correct |
256 ms |
22044 KB |
Output is correct |
75 |
Correct |
242 ms |
22032 KB |
Output is correct |
76 |
Correct |
239 ms |
22084 KB |
Output is correct |
77 |
Correct |
238 ms |
22028 KB |
Output is correct |
78 |
Correct |
1 ms |
204 KB |
Output is correct |
79 |
Correct |
1 ms |
204 KB |
Output is correct |
80 |
Correct |
5 ms |
716 KB |
Output is correct |
81 |
Correct |
109 ms |
12192 KB |
Output is correct |
82 |
Correct |
1 ms |
204 KB |
Output is correct |
83 |
Correct |
1 ms |
204 KB |
Output is correct |
84 |
Correct |
1 ms |
204 KB |
Output is correct |
85 |
Correct |
63 ms |
5780 KB |
Output is correct |
86 |
Correct |
107 ms |
12100 KB |
Output is correct |
87 |
Correct |
100 ms |
12060 KB |
Output is correct |
88 |
Correct |
111 ms |
12228 KB |
Output is correct |
89 |
Correct |
104 ms |
12068 KB |
Output is correct |
90 |
Correct |
1 ms |
204 KB |
Output is correct |
91 |
Correct |
1 ms |
204 KB |
Output is correct |
92 |
Correct |
5 ms |
588 KB |
Output is correct |
93 |
Correct |
101 ms |
8212 KB |
Output is correct |
94 |
Correct |
1 ms |
204 KB |
Output is correct |
95 |
Correct |
1 ms |
204 KB |
Output is correct |
96 |
Correct |
1 ms |
204 KB |
Output is correct |
97 |
Correct |
27 ms |
2244 KB |
Output is correct |
98 |
Correct |
99 ms |
8388 KB |
Output is correct |
99 |
Correct |
97 ms |
8724 KB |
Output is correct |
100 |
Correct |
97 ms |
10424 KB |
Output is correct |
101 |
Correct |
98 ms |
11456 KB |
Output is correct |
102 |
Correct |
116 ms |
10112 KB |
Output is correct |
103 |
Correct |
96 ms |
10128 KB |
Output is correct |
104 |
Correct |
96 ms |
10124 KB |
Output is correct |
105 |
Correct |
104 ms |
10124 KB |
Output is correct |