#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i,a,b) for (int i = (a); i <= (b); i++)
#define debug(a) cout << #a << " " << a << endl
#define nl "\n"
lli n,ult,a,b,c,d;
lli padre[1002],grupo[1002],visitados[1002],inicios[1002],finales[1002],cant[1002];
bool res;
vector<lli> cabezas;
void procesa(lli act) {
if (padre[act] != act) {
procesa(padre[act]);
padre[act] = ult;
}
else ult = act;
}
void calcula(lli act) {
if (grupo[act] != act) {
calcula(grupo[act]);
grupo[act] = ult;
}
else ult = act;
}
int construct(std::vector<std::vector<int>> p) {
res = true;
n = p.size();
vector<vector<int> > puentes(n, vector<int> (n, 0));
rep(i,0,n-1) padre[i] = i;
rep(i,0,n-1) grupo[i] = i;
rep(i,0,n-1) {
rep(j,i,n-1){
if (visitados[j] == 1) continue;
if (i == j) continue;
if (p[i][j] != p[j][i]) res = false;
if (p[i][j] == 3) res = false;
if (res == false) return 0;
if (p[i][j] == 1) {
padre[j] = i;
puentes[i][j] = 1;
puentes[j][i] = 1;
visitados[j] = 1;
}
}
}
rep(i,0,n-1) {
if (padre[i] != i) continue;
rep(j,i,n-1){
if (i == j) continue;
if (padre[i] != i) continue;
if (visitados[j] == 2) continue;
if (p[i][j] == 2) {
grupo[j] = i;
visitados[j]=2;
}
}
}
rep(i,0,n-1) {
rep(j,i,n-1) {
if(i == j) continue;
procesa(i);
a = ult;
procesa(j);
b = ult;
calcula(a);
c = ult;
calcula(b);
d = ult;
if (p[i][j] == 0){
if (a != b && c != d) continue;
else res = false;
}
else if (p[i][j] == 1){
if (a == b && c == d) continue;
else res = false;
}
else {
if (a != b && c == d) continue;
else res = false;
}
if (!res) return 0;
}
}
rep(i,0,n-1) {
if (padre[i] == i) {
calcula(i);
if (cant[ult] == 0) {
inicios[ult] = i;
finales[ult] = i;
cant[ult] = 1;
}
else {
puentes[i][finales[ult]] = 1;
puentes[finales[ult]][i] = 1;
//cout << ult << ' ' << finales[ult] << endl;
finales[ult] = i;
cant[ult]++;
}
}
}
rep(i,0,n-1) {
if (cant[i] == 2) return 0;
if (cant[i] > 2) {
puentes[finales[i]][inicios[i]] = 1;
puentes[inicios[i]][finales[i]] = 1;
}
}
build(puentes);
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
384 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 |
1260 KB |
Output is correct |
7 |
Correct |
251 ms |
22140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
384 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 |
1260 KB |
Output is correct |
7 |
Correct |
251 ms |
22140 KB |
Output is correct |
8 |
Correct |
1 ms |
364 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 |
1408 KB |
Output is correct |
13 |
Correct |
259 ms |
24172 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
876 KB |
Output is correct |
17 |
Correct |
115 ms |
14188 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 |
6380 KB |
Output is correct |
21 |
Correct |
261 ms |
23972 KB |
Output is correct |
22 |
Correct |
257 ms |
24044 KB |
Output is correct |
23 |
Correct |
267 ms |
24044 KB |
Output is correct |
24 |
Correct |
259 ms |
24044 KB |
Output is correct |
25 |
Correct |
120 ms |
14164 KB |
Output is correct |
26 |
Correct |
114 ms |
14188 KB |
Output is correct |
27 |
Correct |
262 ms |
24172 KB |
Output is correct |
28 |
Correct |
266 ms |
24044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
11 ms |
1360 KB |
Output is correct |
9 |
Correct |
253 ms |
24148 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 |
1388 KB |
Output is correct |
13 |
Correct |
255 ms |
24148 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
5 ms |
876 KB |
Output is correct |
17 |
Correct |
118 ms |
14188 KB |
Output is correct |
18 |
Correct |
1 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 |
65 ms |
6308 KB |
Output is correct |
22 |
Correct |
263 ms |
24300 KB |
Output is correct |
23 |
Correct |
257 ms |
24172 KB |
Output is correct |
24 |
Correct |
265 ms |
24044 KB |
Output is correct |
25 |
Correct |
119 ms |
14188 KB |
Output is correct |
26 |
Correct |
111 ms |
14188 KB |
Output is correct |
27 |
Correct |
256 ms |
24044 KB |
Output is correct |
28 |
Correct |
271 ms |
24292 KB |
Output is correct |
29 |
Correct |
117 ms |
14188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
64 ms |
6300 KB |
Output is correct |
5 |
Correct |
256 ms |
24044 KB |
Output is correct |
6 |
Correct |
265 ms |
24180 KB |
Output is correct |
7 |
Correct |
266 ms |
24156 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
65 ms |
6372 KB |
Output is correct |
10 |
Correct |
258 ms |
24044 KB |
Output is correct |
11 |
Correct |
261 ms |
24172 KB |
Output is correct |
12 |
Correct |
267 ms |
24180 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
65 ms |
6380 KB |
Output is correct |
17 |
Correct |
258 ms |
24300 KB |
Output is correct |
18 |
Correct |
275 ms |
24044 KB |
Output is correct |
19 |
Correct |
260 ms |
24044 KB |
Output is correct |
20 |
Correct |
255 ms |
24156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
384 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 |
1260 KB |
Output is correct |
7 |
Correct |
251 ms |
22140 KB |
Output is correct |
8 |
Correct |
1 ms |
364 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 |
1408 KB |
Output is correct |
13 |
Correct |
259 ms |
24172 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
876 KB |
Output is correct |
17 |
Correct |
115 ms |
14188 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 |
6380 KB |
Output is correct |
21 |
Correct |
261 ms |
23972 KB |
Output is correct |
22 |
Correct |
257 ms |
24044 KB |
Output is correct |
23 |
Correct |
267 ms |
24044 KB |
Output is correct |
24 |
Correct |
259 ms |
24044 KB |
Output is correct |
25 |
Correct |
120 ms |
14164 KB |
Output is correct |
26 |
Correct |
114 ms |
14188 KB |
Output is correct |
27 |
Correct |
262 ms |
24172 KB |
Output is correct |
28 |
Correct |
266 ms |
24044 KB |
Output is correct |
29 |
Correct |
1 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 |
1360 KB |
Output is correct |
37 |
Correct |
253 ms |
24148 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 |
1388 KB |
Output is correct |
41 |
Correct |
255 ms |
24148 KB |
Output is correct |
42 |
Correct |
1 ms |
364 KB |
Output is correct |
43 |
Correct |
1 ms |
364 KB |
Output is correct |
44 |
Correct |
5 ms |
876 KB |
Output is correct |
45 |
Correct |
118 ms |
14188 KB |
Output is correct |
46 |
Correct |
1 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 |
65 ms |
6308 KB |
Output is correct |
50 |
Correct |
263 ms |
24300 KB |
Output is correct |
51 |
Correct |
257 ms |
24172 KB |
Output is correct |
52 |
Correct |
265 ms |
24044 KB |
Output is correct |
53 |
Correct |
119 ms |
14188 KB |
Output is correct |
54 |
Correct |
111 ms |
14188 KB |
Output is correct |
55 |
Correct |
256 ms |
24044 KB |
Output is correct |
56 |
Correct |
271 ms |
24292 KB |
Output is correct |
57 |
Correct |
117 ms |
14188 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 |
114 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 |
364 KB |
Output is correct |
65 |
Correct |
70 ms |
6380 KB |
Output is correct |
66 |
Correct |
113 ms |
14188 KB |
Output is correct |
67 |
Correct |
113 ms |
14188 KB |
Output is correct |
68 |
Correct |
111 ms |
14188 KB |
Output is correct |
69 |
Correct |
115 ms |
14188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
384 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 |
1260 KB |
Output is correct |
7 |
Correct |
251 ms |
22140 KB |
Output is correct |
8 |
Correct |
1 ms |
364 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 |
1408 KB |
Output is correct |
13 |
Correct |
259 ms |
24172 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
876 KB |
Output is correct |
17 |
Correct |
115 ms |
14188 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 |
6380 KB |
Output is correct |
21 |
Correct |
261 ms |
23972 KB |
Output is correct |
22 |
Correct |
257 ms |
24044 KB |
Output is correct |
23 |
Correct |
267 ms |
24044 KB |
Output is correct |
24 |
Correct |
259 ms |
24044 KB |
Output is correct |
25 |
Correct |
120 ms |
14164 KB |
Output is correct |
26 |
Correct |
114 ms |
14188 KB |
Output is correct |
27 |
Correct |
262 ms |
24172 KB |
Output is correct |
28 |
Correct |
266 ms |
24044 KB |
Output is correct |
29 |
Correct |
1 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 |
1360 KB |
Output is correct |
37 |
Correct |
253 ms |
24148 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 |
1388 KB |
Output is correct |
41 |
Correct |
255 ms |
24148 KB |
Output is correct |
42 |
Correct |
1 ms |
364 KB |
Output is correct |
43 |
Correct |
1 ms |
364 KB |
Output is correct |
44 |
Correct |
5 ms |
876 KB |
Output is correct |
45 |
Correct |
118 ms |
14188 KB |
Output is correct |
46 |
Correct |
1 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 |
65 ms |
6308 KB |
Output is correct |
50 |
Correct |
263 ms |
24300 KB |
Output is correct |
51 |
Correct |
257 ms |
24172 KB |
Output is correct |
52 |
Correct |
265 ms |
24044 KB |
Output is correct |
53 |
Correct |
119 ms |
14188 KB |
Output is correct |
54 |
Correct |
111 ms |
14188 KB |
Output is correct |
55 |
Correct |
256 ms |
24044 KB |
Output is correct |
56 |
Correct |
271 ms |
24292 KB |
Output is correct |
57 |
Correct |
117 ms |
14188 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 |
64 ms |
6300 KB |
Output is correct |
62 |
Correct |
256 ms |
24044 KB |
Output is correct |
63 |
Correct |
265 ms |
24180 KB |
Output is correct |
64 |
Correct |
266 ms |
24156 KB |
Output is correct |
65 |
Correct |
1 ms |
364 KB |
Output is correct |
66 |
Correct |
65 ms |
6372 KB |
Output is correct |
67 |
Correct |
258 ms |
24044 KB |
Output is correct |
68 |
Correct |
261 ms |
24172 KB |
Output is correct |
69 |
Correct |
267 ms |
24180 KB |
Output is correct |
70 |
Correct |
1 ms |
364 KB |
Output is correct |
71 |
Correct |
1 ms |
364 KB |
Output is correct |
72 |
Correct |
1 ms |
364 KB |
Output is correct |
73 |
Correct |
65 ms |
6380 KB |
Output is correct |
74 |
Correct |
258 ms |
24300 KB |
Output is correct |
75 |
Correct |
275 ms |
24044 KB |
Output is correct |
76 |
Correct |
260 ms |
24044 KB |
Output is correct |
77 |
Correct |
255 ms |
24156 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 |
114 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 |
364 KB |
Output is correct |
85 |
Correct |
70 ms |
6380 KB |
Output is correct |
86 |
Correct |
113 ms |
14188 KB |
Output is correct |
87 |
Correct |
113 ms |
14188 KB |
Output is correct |
88 |
Correct |
111 ms |
14188 KB |
Output is correct |
89 |
Correct |
115 ms |
14188 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 |
111 ms |
14164 KB |
Output is correct |
94 |
Correct |
1 ms |
364 KB |
Output is correct |
95 |
Correct |
1 ms |
364 KB |
Output is correct |
96 |
Correct |
1 ms |
364 KB |
Output is correct |
97 |
Correct |
29 ms |
3820 KB |
Output is correct |
98 |
Correct |
110 ms |
14188 KB |
Output is correct |
99 |
Correct |
112 ms |
14188 KB |
Output is correct |
100 |
Correct |
108 ms |
14316 KB |
Output is correct |
101 |
Correct |
108 ms |
14188 KB |
Output is correct |
102 |
Correct |
110 ms |
14188 KB |
Output is correct |
103 |
Correct |
115 ms |
14188 KB |
Output is correct |
104 |
Correct |
106 ms |
14188 KB |
Output is correct |
105 |
Correct |
115 ms |
14164 KB |
Output is correct |