#include <bits/stdc++.h>
#include "supertrees.h"
using namespace std;
const int c=1002;
bool v[c], p;
int n, cnt, ki[c], id[c], si;
vector<vector<int> >sz, sol;
vector<int> kor;
void el(int a, int b) {
sol[a][b]=1, sol[b][a]=1;
}
void dfs(int a) {
kor.push_back(a);
ki[a]=a, v[a]=1, id[a]=cnt;
for (int i=0; i<n; i++) if (!v[i] && sz[a][i]==1) v[i]=1, ki[i]=a, id[i]=cnt, el(a, i);
for (int i=0; i<n; i++) if (!v[i] && sz[a][i]==2) dfs(i);
}
int construct(vector<vector<int> > x) {
n=x.size(), sz=x;
sol.resize(n);
for (int i=0; i<n; i++) for (int j=0; j<n; j++) sol[i].push_back(0);
for (int i=0; i<n; i++) {
if (!v[i]) dfs(i), cnt++;
si=kor.size();
if (si>1) {
if (si==2) p=1;
for (int i=1; i<si; i++) el(kor[i-1], kor[i]);
el(kor[0], kor[si-1]);
}
kor.clear();
}
for (int i=0; i<n; i++) for (int j=0; j<n; j++) {
if (ki[i]==ki[j] && sz[i][j]!=1) p=1;
if (id[i]==id[j] && ki[i]!=ki[j] && sz[i][j]!=2) p=1;
if (id[i]!=id[j]&& sz[i][j]) p=1;
}
if (p) return 0;
else build(sol);
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
11 ms |
1408 KB |
Output is correct |
7 |
Correct |
258 ms |
26104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
11 ms |
1408 KB |
Output is correct |
7 |
Correct |
258 ms |
26104 KB |
Output is correct |
8 |
Correct |
0 ms |
256 KB |
Output is correct |
9 |
Correct |
0 ms |
256 KB |
Output is correct |
10 |
Correct |
0 ms |
256 KB |
Output is correct |
11 |
Correct |
1 ms |
256 KB |
Output is correct |
12 |
Correct |
11 ms |
1408 KB |
Output is correct |
13 |
Correct |
251 ms |
26104 KB |
Output is correct |
14 |
Correct |
0 ms |
256 KB |
Output is correct |
15 |
Correct |
0 ms |
256 KB |
Output is correct |
16 |
Correct |
6 ms |
1024 KB |
Output is correct |
17 |
Correct |
126 ms |
16216 KB |
Output is correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
73 ms |
6904 KB |
Output is correct |
21 |
Correct |
253 ms |
26232 KB |
Output is correct |
22 |
Correct |
250 ms |
26104 KB |
Output is correct |
23 |
Correct |
260 ms |
26232 KB |
Output is correct |
24 |
Correct |
261 ms |
26232 KB |
Output is correct |
25 |
Correct |
114 ms |
16220 KB |
Output is correct |
26 |
Correct |
115 ms |
16248 KB |
Output is correct |
27 |
Correct |
269 ms |
26108 KB |
Output is correct |
28 |
Correct |
251 ms |
26192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
11 ms |
1408 KB |
Output is correct |
9 |
Correct |
250 ms |
26236 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
11 |
Correct |
0 ms |
256 KB |
Output is correct |
12 |
Correct |
11 ms |
1408 KB |
Output is correct |
13 |
Correct |
262 ms |
26196 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
0 ms |
256 KB |
Output is correct |
16 |
Correct |
6 ms |
1024 KB |
Output is correct |
17 |
Correct |
125 ms |
16248 KB |
Output is correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
19 |
Correct |
0 ms |
256 KB |
Output is correct |
20 |
Correct |
0 ms |
256 KB |
Output is correct |
21 |
Correct |
65 ms |
6776 KB |
Output is correct |
22 |
Correct |
254 ms |
26104 KB |
Output is correct |
23 |
Correct |
254 ms |
26200 KB |
Output is correct |
24 |
Correct |
270 ms |
26360 KB |
Output is correct |
25 |
Correct |
113 ms |
16248 KB |
Output is correct |
26 |
Correct |
119 ms |
16248 KB |
Output is correct |
27 |
Correct |
259 ms |
26232 KB |
Output is correct |
28 |
Correct |
263 ms |
26232 KB |
Output is correct |
29 |
Correct |
112 ms |
16248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
67 ms |
6776 KB |
Output is correct |
5 |
Correct |
250 ms |
26104 KB |
Output is correct |
6 |
Correct |
250 ms |
26104 KB |
Output is correct |
7 |
Correct |
264 ms |
26232 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
65 ms |
6904 KB |
Output is correct |
10 |
Correct |
267 ms |
26200 KB |
Output is correct |
11 |
Correct |
254 ms |
26232 KB |
Output is correct |
12 |
Correct |
263 ms |
26360 KB |
Output is correct |
13 |
Correct |
0 ms |
256 KB |
Output is correct |
14 |
Correct |
0 ms |
256 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
64 ms |
6776 KB |
Output is correct |
17 |
Correct |
261 ms |
26232 KB |
Output is correct |
18 |
Correct |
260 ms |
26236 KB |
Output is correct |
19 |
Correct |
260 ms |
26232 KB |
Output is correct |
20 |
Correct |
252 ms |
26232 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
11 ms |
1408 KB |
Output is correct |
7 |
Correct |
258 ms |
26104 KB |
Output is correct |
8 |
Correct |
0 ms |
256 KB |
Output is correct |
9 |
Correct |
0 ms |
256 KB |
Output is correct |
10 |
Correct |
0 ms |
256 KB |
Output is correct |
11 |
Correct |
1 ms |
256 KB |
Output is correct |
12 |
Correct |
11 ms |
1408 KB |
Output is correct |
13 |
Correct |
251 ms |
26104 KB |
Output is correct |
14 |
Correct |
0 ms |
256 KB |
Output is correct |
15 |
Correct |
0 ms |
256 KB |
Output is correct |
16 |
Correct |
6 ms |
1024 KB |
Output is correct |
17 |
Correct |
126 ms |
16216 KB |
Output is correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
73 ms |
6904 KB |
Output is correct |
21 |
Correct |
253 ms |
26232 KB |
Output is correct |
22 |
Correct |
250 ms |
26104 KB |
Output is correct |
23 |
Correct |
260 ms |
26232 KB |
Output is correct |
24 |
Correct |
261 ms |
26232 KB |
Output is correct |
25 |
Correct |
114 ms |
16220 KB |
Output is correct |
26 |
Correct |
115 ms |
16248 KB |
Output is correct |
27 |
Correct |
269 ms |
26108 KB |
Output is correct |
28 |
Correct |
251 ms |
26192 KB |
Output is correct |
29 |
Correct |
0 ms |
256 KB |
Output is correct |
30 |
Correct |
0 ms |
256 KB |
Output is correct |
31 |
Correct |
1 ms |
256 KB |
Output is correct |
32 |
Correct |
1 ms |
256 KB |
Output is correct |
33 |
Correct |
1 ms |
256 KB |
Output is correct |
34 |
Correct |
1 ms |
384 KB |
Output is correct |
35 |
Correct |
1 ms |
384 KB |
Output is correct |
36 |
Correct |
11 ms |
1408 KB |
Output is correct |
37 |
Correct |
250 ms |
26236 KB |
Output is correct |
38 |
Correct |
1 ms |
256 KB |
Output is correct |
39 |
Correct |
0 ms |
256 KB |
Output is correct |
40 |
Correct |
11 ms |
1408 KB |
Output is correct |
41 |
Correct |
262 ms |
26196 KB |
Output is correct |
42 |
Correct |
1 ms |
256 KB |
Output is correct |
43 |
Correct |
0 ms |
256 KB |
Output is correct |
44 |
Correct |
6 ms |
1024 KB |
Output is correct |
45 |
Correct |
125 ms |
16248 KB |
Output is correct |
46 |
Correct |
1 ms |
256 KB |
Output is correct |
47 |
Correct |
0 ms |
256 KB |
Output is correct |
48 |
Correct |
0 ms |
256 KB |
Output is correct |
49 |
Correct |
65 ms |
6776 KB |
Output is correct |
50 |
Correct |
254 ms |
26104 KB |
Output is correct |
51 |
Correct |
254 ms |
26200 KB |
Output is correct |
52 |
Correct |
270 ms |
26360 KB |
Output is correct |
53 |
Correct |
113 ms |
16248 KB |
Output is correct |
54 |
Correct |
119 ms |
16248 KB |
Output is correct |
55 |
Correct |
259 ms |
26232 KB |
Output is correct |
56 |
Correct |
263 ms |
26232 KB |
Output is correct |
57 |
Correct |
112 ms |
16248 KB |
Output is correct |
58 |
Correct |
1 ms |
256 KB |
Output is correct |
59 |
Correct |
0 ms |
256 KB |
Output is correct |
60 |
Correct |
6 ms |
1024 KB |
Output is correct |
61 |
Correct |
124 ms |
16248 KB |
Output is correct |
62 |
Correct |
1 ms |
256 KB |
Output is correct |
63 |
Correct |
0 ms |
384 KB |
Output is correct |
64 |
Correct |
1 ms |
256 KB |
Output is correct |
65 |
Correct |
64 ms |
6776 KB |
Output is correct |
66 |
Correct |
119 ms |
16340 KB |
Output is correct |
67 |
Correct |
117 ms |
16248 KB |
Output is correct |
68 |
Correct |
117 ms |
16216 KB |
Output is correct |
69 |
Correct |
123 ms |
16220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
11 ms |
1408 KB |
Output is correct |
7 |
Correct |
258 ms |
26104 KB |
Output is correct |
8 |
Correct |
0 ms |
256 KB |
Output is correct |
9 |
Correct |
0 ms |
256 KB |
Output is correct |
10 |
Correct |
0 ms |
256 KB |
Output is correct |
11 |
Correct |
1 ms |
256 KB |
Output is correct |
12 |
Correct |
11 ms |
1408 KB |
Output is correct |
13 |
Correct |
251 ms |
26104 KB |
Output is correct |
14 |
Correct |
0 ms |
256 KB |
Output is correct |
15 |
Correct |
0 ms |
256 KB |
Output is correct |
16 |
Correct |
6 ms |
1024 KB |
Output is correct |
17 |
Correct |
126 ms |
16216 KB |
Output is correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
73 ms |
6904 KB |
Output is correct |
21 |
Correct |
253 ms |
26232 KB |
Output is correct |
22 |
Correct |
250 ms |
26104 KB |
Output is correct |
23 |
Correct |
260 ms |
26232 KB |
Output is correct |
24 |
Correct |
261 ms |
26232 KB |
Output is correct |
25 |
Correct |
114 ms |
16220 KB |
Output is correct |
26 |
Correct |
115 ms |
16248 KB |
Output is correct |
27 |
Correct |
269 ms |
26108 KB |
Output is correct |
28 |
Correct |
251 ms |
26192 KB |
Output is correct |
29 |
Correct |
0 ms |
256 KB |
Output is correct |
30 |
Correct |
0 ms |
256 KB |
Output is correct |
31 |
Correct |
1 ms |
256 KB |
Output is correct |
32 |
Correct |
1 ms |
256 KB |
Output is correct |
33 |
Correct |
1 ms |
256 KB |
Output is correct |
34 |
Correct |
1 ms |
384 KB |
Output is correct |
35 |
Correct |
1 ms |
384 KB |
Output is correct |
36 |
Correct |
11 ms |
1408 KB |
Output is correct |
37 |
Correct |
250 ms |
26236 KB |
Output is correct |
38 |
Correct |
1 ms |
256 KB |
Output is correct |
39 |
Correct |
0 ms |
256 KB |
Output is correct |
40 |
Correct |
11 ms |
1408 KB |
Output is correct |
41 |
Correct |
262 ms |
26196 KB |
Output is correct |
42 |
Correct |
1 ms |
256 KB |
Output is correct |
43 |
Correct |
0 ms |
256 KB |
Output is correct |
44 |
Correct |
6 ms |
1024 KB |
Output is correct |
45 |
Correct |
125 ms |
16248 KB |
Output is correct |
46 |
Correct |
1 ms |
256 KB |
Output is correct |
47 |
Correct |
0 ms |
256 KB |
Output is correct |
48 |
Correct |
0 ms |
256 KB |
Output is correct |
49 |
Correct |
65 ms |
6776 KB |
Output is correct |
50 |
Correct |
254 ms |
26104 KB |
Output is correct |
51 |
Correct |
254 ms |
26200 KB |
Output is correct |
52 |
Correct |
270 ms |
26360 KB |
Output is correct |
53 |
Correct |
113 ms |
16248 KB |
Output is correct |
54 |
Correct |
119 ms |
16248 KB |
Output is correct |
55 |
Correct |
259 ms |
26232 KB |
Output is correct |
56 |
Correct |
263 ms |
26232 KB |
Output is correct |
57 |
Correct |
112 ms |
16248 KB |
Output is correct |
58 |
Correct |
0 ms |
256 KB |
Output is correct |
59 |
Correct |
0 ms |
256 KB |
Output is correct |
60 |
Correct |
1 ms |
256 KB |
Output is correct |
61 |
Correct |
67 ms |
6776 KB |
Output is correct |
62 |
Correct |
250 ms |
26104 KB |
Output is correct |
63 |
Correct |
250 ms |
26104 KB |
Output is correct |
64 |
Correct |
264 ms |
26232 KB |
Output is correct |
65 |
Correct |
1 ms |
384 KB |
Output is correct |
66 |
Correct |
65 ms |
6904 KB |
Output is correct |
67 |
Correct |
267 ms |
26200 KB |
Output is correct |
68 |
Correct |
254 ms |
26232 KB |
Output is correct |
69 |
Correct |
263 ms |
26360 KB |
Output is correct |
70 |
Correct |
0 ms |
256 KB |
Output is correct |
71 |
Correct |
0 ms |
256 KB |
Output is correct |
72 |
Correct |
0 ms |
384 KB |
Output is correct |
73 |
Correct |
64 ms |
6776 KB |
Output is correct |
74 |
Correct |
261 ms |
26232 KB |
Output is correct |
75 |
Correct |
260 ms |
26236 KB |
Output is correct |
76 |
Correct |
260 ms |
26232 KB |
Output is correct |
77 |
Correct |
252 ms |
26232 KB |
Output is correct |
78 |
Correct |
1 ms |
256 KB |
Output is correct |
79 |
Correct |
0 ms |
256 KB |
Output is correct |
80 |
Correct |
6 ms |
1024 KB |
Output is correct |
81 |
Correct |
124 ms |
16248 KB |
Output is correct |
82 |
Correct |
1 ms |
256 KB |
Output is correct |
83 |
Correct |
0 ms |
384 KB |
Output is correct |
84 |
Correct |
1 ms |
256 KB |
Output is correct |
85 |
Correct |
64 ms |
6776 KB |
Output is correct |
86 |
Correct |
119 ms |
16340 KB |
Output is correct |
87 |
Correct |
117 ms |
16248 KB |
Output is correct |
88 |
Correct |
117 ms |
16216 KB |
Output is correct |
89 |
Correct |
123 ms |
16220 KB |
Output is correct |
90 |
Correct |
0 ms |
384 KB |
Output is correct |
91 |
Correct |
0 ms |
256 KB |
Output is correct |
92 |
Correct |
6 ms |
1024 KB |
Output is correct |
93 |
Correct |
123 ms |
16216 KB |
Output is correct |
94 |
Correct |
1 ms |
384 KB |
Output is correct |
95 |
Correct |
0 ms |
256 KB |
Output is correct |
96 |
Correct |
0 ms |
256 KB |
Output is correct |
97 |
Correct |
30 ms |
4352 KB |
Output is correct |
98 |
Correct |
118 ms |
16248 KB |
Output is correct |
99 |
Correct |
121 ms |
16248 KB |
Output is correct |
100 |
Correct |
115 ms |
16220 KB |
Output is correct |
101 |
Correct |
114 ms |
16248 KB |
Output is correct |
102 |
Correct |
126 ms |
16248 KB |
Output is correct |
103 |
Correct |
127 ms |
16248 KB |
Output is correct |
104 |
Correct |
125 ms |
16248 KB |
Output is correct |
105 |
Correct |
126 ms |
16248 KB |
Output is correct |