#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 7;
int nn, comp, used[N], cc[N], cmp[N], tp[N], first[N];
set < int > sz[N];
int construct(std::vector<std::vector<int>> p) {
nn = p.size();
std::vector<std::vector<int>> answer;
for (int i = 0; i < nn; i++) {
std::vector<int> row;
row.resize(nn);
answer.push_back(row);
}
int sub1 = 1, cnt1 = 0, cnt2 = 0;
vector < pair < int, int > > vc;
for ( int i = 0; i < nn; i++ ) {
for ( int j = 0; j < nn ;j++ ) {
if ( p[i][j] == 2 ) {
sub1 = 0;
cnt2 = 1;
}
if ( p[i][j] == 1 && i != j ) {
cnt1 = 1;
tp[i] = 1;
}
}
}
for ( int i = 0; i < nn; i++ ) {
if ( !sub1 && tp[i] ) {
continue;
}
if ( !cc[i] ) {
cc[i] = ++comp;
first[comp] = i;
sz[cc[i]].insert(i);
}
cmp[ cc[i] ] = i;
for ( int j = 0; j < nn; j++ ) {
if ( p[i][j] == (sub1?1:2) && i != j && (!tp[j] || sub1) ) {
if ( cc[j] && cc[j] != cc[i] ) {
return 0;
}
if( cc[j] ) {
continue;
}
cc[j] = cc[i];
sz[cc[i]].insert(j);
//cout << cmp[ cc[i] ] << ' ' << j << endl;
answer[ cmp[ cc[i] ] ][j] = 1;
answer[ j ][ cmp[ cc[i] ] ] = 1;
cmp[ cc[i] ] = j;
}
}
}
if ( !sub1 && !(cnt1 && cnt2) ) {
for ( int i = 1; i <= comp; i++ ) {
if ( cmp[ i ] != first[i] ) {
answer[cmp[i]][first[i]] = 1;
answer[ first[i] ][cmp[i]] = 1;
}
if ( sz[i].size() == 2 ) {
return 0;
}
}
}
if ( cnt1 && cnt2 ) {
for ( int i = 0; i < nn; i++ ) {
//cout << i << ' ' << cc[i] << ' ' << first[ cc[i] ] << endl;
if ( tp[i] || first[ cc[i] ] != i ) {
continue;
}
//cout << i << endl;
int s = i;
for ( int j = 0; j < nn; j++ ) {
if ( i != j && tp[j] && !used[j] ) {
s = j;
break;
}
}
if ( s == i ) {
continue;
}
//cout << i << ' ' << s << endl;
answer[i][s] = 1;
answer[s][i] = 1;
answer[cmp[cc[i]]][s] = 1;
answer[s][cmp[cc[i]]] = 1;
used[s] = 1;
for ( int j = 0; j < nn; j++ ) {
if ( s != j && tp[j] ) {
answer[s][j] = 1;
answer[j][s] = 1;
used[j] = 1;
}
}
}
build(answer);
return 1;
}
for ( int i = 0; i < nn; i++ ) {
for ( int j = 0; j < nn; j++ ) {
if ( cc[i] == cc[j] ) {
if ( !p[i][j] || !p[j][i] ) {
return 0;
}
}
}
}
build(answer);
return 1;
}
/*
8
1 2 2 0 0 0 0 0
2 1 2 0 0 0 0 0
2 2 1 1 1 0 0 0
0 0 1 1 1 0 0 0
0 0 1 1 1 0 0 0
0 0 0 0 0 1 2 2
0 0 0 0 0 2 1 2
0 0 0 0 0 2 2 1
5
1 2 2 2 2
2 1 2 2 2
2 2 1 1 1
2 2 1 1 1
2 2 1 1 1
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
11 ms |
1280 KB |
Output is correct |
7 |
Correct |
259 ms |
22196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
11 ms |
1280 KB |
Output is correct |
7 |
Correct |
259 ms |
22196 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
12 ms |
1280 KB |
Output is correct |
13 |
Correct |
249 ms |
22136 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
8 ms |
896 KB |
Output is correct |
17 |
Correct |
120 ms |
12264 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
63 ms |
5936 KB |
Output is correct |
21 |
Correct |
248 ms |
22392 KB |
Output is correct |
22 |
Correct |
366 ms |
22136 KB |
Output is correct |
23 |
Correct |
251 ms |
22140 KB |
Output is correct |
24 |
Correct |
248 ms |
22152 KB |
Output is correct |
25 |
Correct |
112 ms |
12296 KB |
Output is correct |
26 |
Correct |
109 ms |
12296 KB |
Output is correct |
27 |
Correct |
309 ms |
22240 KB |
Output is correct |
28 |
Correct |
253 ms |
22136 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
14 ms |
1280 KB |
Output is correct |
9 |
Correct |
282 ms |
22148 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
15 ms |
1296 KB |
Output is correct |
13 |
Correct |
268 ms |
22252 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
9 ms |
896 KB |
Output is correct |
17 |
Correct |
131 ms |
12296 KB |
Output is correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
71 ms |
5880 KB |
Output is correct |
22 |
Correct |
294 ms |
22148 KB |
Output is correct |
23 |
Correct |
269 ms |
22192 KB |
Output is correct |
24 |
Correct |
282 ms |
22136 KB |
Output is correct |
25 |
Correct |
128 ms |
12292 KB |
Output is correct |
26 |
Correct |
142 ms |
12296 KB |
Output is correct |
27 |
Correct |
270 ms |
22152 KB |
Output is correct |
28 |
Correct |
262 ms |
22136 KB |
Output is correct |
29 |
Correct |
108 ms |
12276 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
360 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
360 KB |
Output is correct |
4 |
Correct |
67 ms |
5880 KB |
Output is correct |
5 |
Correct |
258 ms |
22136 KB |
Output is correct |
6 |
Correct |
272 ms |
22136 KB |
Output is correct |
7 |
Correct |
291 ms |
22152 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
76 ms |
5880 KB |
Output is correct |
10 |
Correct |
260 ms |
22196 KB |
Output is correct |
11 |
Correct |
274 ms |
22280 KB |
Output is correct |
12 |
Correct |
284 ms |
22144 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Incorrect |
1 ms |
384 KB |
Too many ways to get from 0 to 4, should be 0 found no less than 1 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
11 ms |
1280 KB |
Output is correct |
7 |
Correct |
259 ms |
22196 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
12 ms |
1280 KB |
Output is correct |
13 |
Correct |
249 ms |
22136 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
8 ms |
896 KB |
Output is correct |
17 |
Correct |
120 ms |
12264 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
63 ms |
5936 KB |
Output is correct |
21 |
Correct |
248 ms |
22392 KB |
Output is correct |
22 |
Correct |
366 ms |
22136 KB |
Output is correct |
23 |
Correct |
251 ms |
22140 KB |
Output is correct |
24 |
Correct |
248 ms |
22152 KB |
Output is correct |
25 |
Correct |
112 ms |
12296 KB |
Output is correct |
26 |
Correct |
109 ms |
12296 KB |
Output is correct |
27 |
Correct |
309 ms |
22240 KB |
Output is correct |
28 |
Correct |
253 ms |
22136 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
1 ms |
384 KB |
Output is correct |
31 |
Correct |
1 ms |
384 KB |
Output is correct |
32 |
Correct |
1 ms |
384 KB |
Output is correct |
33 |
Correct |
1 ms |
384 KB |
Output is correct |
34 |
Correct |
1 ms |
384 KB |
Output is correct |
35 |
Correct |
1 ms |
384 KB |
Output is correct |
36 |
Correct |
14 ms |
1280 KB |
Output is correct |
37 |
Correct |
282 ms |
22148 KB |
Output is correct |
38 |
Correct |
1 ms |
384 KB |
Output is correct |
39 |
Correct |
1 ms |
384 KB |
Output is correct |
40 |
Correct |
15 ms |
1296 KB |
Output is correct |
41 |
Correct |
268 ms |
22252 KB |
Output is correct |
42 |
Correct |
1 ms |
384 KB |
Output is correct |
43 |
Correct |
1 ms |
384 KB |
Output is correct |
44 |
Correct |
9 ms |
896 KB |
Output is correct |
45 |
Correct |
131 ms |
12296 KB |
Output is correct |
46 |
Correct |
1 ms |
256 KB |
Output is correct |
47 |
Correct |
1 ms |
384 KB |
Output is correct |
48 |
Correct |
1 ms |
384 KB |
Output is correct |
49 |
Correct |
71 ms |
5880 KB |
Output is correct |
50 |
Correct |
294 ms |
22148 KB |
Output is correct |
51 |
Correct |
269 ms |
22192 KB |
Output is correct |
52 |
Correct |
282 ms |
22136 KB |
Output is correct |
53 |
Correct |
128 ms |
12292 KB |
Output is correct |
54 |
Correct |
142 ms |
12296 KB |
Output is correct |
55 |
Correct |
270 ms |
22152 KB |
Output is correct |
56 |
Correct |
262 ms |
22136 KB |
Output is correct |
57 |
Correct |
108 ms |
12276 KB |
Output is correct |
58 |
Correct |
1 ms |
384 KB |
Output is correct |
59 |
Incorrect |
1 ms |
384 KB |
Answer gives possible 1 while actual possible 0 |
60 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
11 ms |
1280 KB |
Output is correct |
7 |
Correct |
259 ms |
22196 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
12 ms |
1280 KB |
Output is correct |
13 |
Correct |
249 ms |
22136 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
8 ms |
896 KB |
Output is correct |
17 |
Correct |
120 ms |
12264 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
63 ms |
5936 KB |
Output is correct |
21 |
Correct |
248 ms |
22392 KB |
Output is correct |
22 |
Correct |
366 ms |
22136 KB |
Output is correct |
23 |
Correct |
251 ms |
22140 KB |
Output is correct |
24 |
Correct |
248 ms |
22152 KB |
Output is correct |
25 |
Correct |
112 ms |
12296 KB |
Output is correct |
26 |
Correct |
109 ms |
12296 KB |
Output is correct |
27 |
Correct |
309 ms |
22240 KB |
Output is correct |
28 |
Correct |
253 ms |
22136 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
1 ms |
384 KB |
Output is correct |
31 |
Correct |
1 ms |
384 KB |
Output is correct |
32 |
Correct |
1 ms |
384 KB |
Output is correct |
33 |
Correct |
1 ms |
384 KB |
Output is correct |
34 |
Correct |
1 ms |
384 KB |
Output is correct |
35 |
Correct |
1 ms |
384 KB |
Output is correct |
36 |
Correct |
14 ms |
1280 KB |
Output is correct |
37 |
Correct |
282 ms |
22148 KB |
Output is correct |
38 |
Correct |
1 ms |
384 KB |
Output is correct |
39 |
Correct |
1 ms |
384 KB |
Output is correct |
40 |
Correct |
15 ms |
1296 KB |
Output is correct |
41 |
Correct |
268 ms |
22252 KB |
Output is correct |
42 |
Correct |
1 ms |
384 KB |
Output is correct |
43 |
Correct |
1 ms |
384 KB |
Output is correct |
44 |
Correct |
9 ms |
896 KB |
Output is correct |
45 |
Correct |
131 ms |
12296 KB |
Output is correct |
46 |
Correct |
1 ms |
256 KB |
Output is correct |
47 |
Correct |
1 ms |
384 KB |
Output is correct |
48 |
Correct |
1 ms |
384 KB |
Output is correct |
49 |
Correct |
71 ms |
5880 KB |
Output is correct |
50 |
Correct |
294 ms |
22148 KB |
Output is correct |
51 |
Correct |
269 ms |
22192 KB |
Output is correct |
52 |
Correct |
282 ms |
22136 KB |
Output is correct |
53 |
Correct |
128 ms |
12292 KB |
Output is correct |
54 |
Correct |
142 ms |
12296 KB |
Output is correct |
55 |
Correct |
270 ms |
22152 KB |
Output is correct |
56 |
Correct |
262 ms |
22136 KB |
Output is correct |
57 |
Correct |
108 ms |
12276 KB |
Output is correct |
58 |
Correct |
1 ms |
360 KB |
Output is correct |
59 |
Correct |
1 ms |
384 KB |
Output is correct |
60 |
Correct |
1 ms |
360 KB |
Output is correct |
61 |
Correct |
67 ms |
5880 KB |
Output is correct |
62 |
Correct |
258 ms |
22136 KB |
Output is correct |
63 |
Correct |
272 ms |
22136 KB |
Output is correct |
64 |
Correct |
291 ms |
22152 KB |
Output is correct |
65 |
Correct |
0 ms |
384 KB |
Output is correct |
66 |
Correct |
76 ms |
5880 KB |
Output is correct |
67 |
Correct |
260 ms |
22196 KB |
Output is correct |
68 |
Correct |
274 ms |
22280 KB |
Output is correct |
69 |
Correct |
284 ms |
22144 KB |
Output is correct |
70 |
Correct |
1 ms |
384 KB |
Output is correct |
71 |
Incorrect |
1 ms |
384 KB |
Too many ways to get from 0 to 4, should be 0 found no less than 1 |
72 |
Halted |
0 ms |
0 KB |
- |