5566 | 2023-07-27 11:25:49 | zsombor | Széfnyitás | cpp17 | Accepted 100/100 | 25ms | 12268 KiB |
#include <iostream>
#include <vector>
#include <set>
using namespace std;
int n, k;
vector <int> B(3e4, 0);
vector <vector <int>> T(3e4, vector <int>(2, 1));
vector <vector <int>> t(3e4, vector <int>(2, 1));
vector <int> cur(3e4, 1);
void solve(set <int> s) {
int i = *s.begin(), J = cur[i], j = cur[i];
vector <set <int>> v(n + 1);
for (int cnt = 0; cnt < n; cnt++) {
for (int l = 1; l <= n; l++) {
if (!s.count(l)) continue;
if (B[cur[l]] != B[j]) {
s.erase(l);
v[j].insert(l);
}
cur[l] = T[cur[l]][B[j]];
}
j = T[j][B[j]];
}
j = J;
for (int cnt = 0; cnt < n; cnt++) {
if (v[j].empty()) { j = T[j][B[j]]; continue; }
t[(i - 1) * n + j][1 - B[j]] = ((*v[j].begin()) - 1) * n + cur[*v[j].begin()];
solve(v[j]);
v[j].clear();
j = T[j][B[j]];
}
}
int main() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> B[i] >> T[i][0] >> T[i][1];
cin >> k;
set <int> s;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
t[(i - 1) * n + j][0] = (i - 1) * n + T[j][0];
t[(i - 1) * n + j][1] = (i - 1) * n + T[j][1];
}
cur[i] = i;
s.insert(i);
}
solve(s);
cout << n * n << " 1\n";
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
cout << B[j] << " " << t[(i - 1) * n + j][0] << " " << t[(i - 1) * n + j][1] << "\n";
}
}
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 8ms | 8876 KiB | ||||
2 | Accepted | 8ms | 9168 KiB | ||||
subtask2 | 16/16 | ||||||
3 | Accepted | 8ms | 8800 KiB | ||||
4 | Accepted | 8ms | 9284 KiB | ||||
5 | Accepted | 8ms | 9396 KiB | ||||
6 | Accepted | 8ms | 9892 KiB | ||||
7 | Accepted | 8ms | 9780 KiB | ||||
8 | Accepted | 8ms | 9988 KiB | ||||
9 | Accepted | 8ms | 10216 KiB | ||||
10 | Accepted | 8ms | 10424 KiB | ||||
11 | Accepted | 8ms | 10512 KiB | ||||
12 | Accepted | 8ms | 10792 KiB | ||||
13 | Accepted | 8ms | 10596 KiB | ||||
subtask3 | 24/24 | ||||||
14 | Accepted | 8ms | 10956 KiB | ||||
15 | Accepted | 8ms | 11244 KiB | ||||
16 | Accepted | 8ms | 11396 KiB | ||||
17 | Accepted | 8ms | 11532 KiB | ||||
18 | Accepted | 8ms | 11604 KiB | ||||
19 | Accepted | 8ms | 11460 KiB | ||||
20 | Accepted | 8ms | 11636 KiB | ||||
21 | Accepted | 8ms | 11456 KiB | ||||
subtask4 | 23/23 | ||||||
22 | Accepted | 8ms | 11492 KiB | ||||
23 | Accepted | 8ms | 11640 KiB | ||||
24 | Accepted | 8ms | 11572 KiB | ||||
25 | Accepted | 8ms | 11692 KiB | ||||
26 | Accepted | 8ms | 11888 KiB | ||||
27 | Accepted | 8ms | 11840 KiB | ||||
28 | Accepted | 8ms | 11732 KiB | ||||
29 | Accepted | 8ms | 11992 KiB | ||||
subtask5 | 37/37 | ||||||
30 | Accepted | 8ms | 8800 KiB | ||||
31 | Accepted | 8ms | 9284 KiB | ||||
32 | Accepted | 8ms | 9396 KiB | ||||
33 | Accepted | 8ms | 9892 KiB | ||||
34 | Accepted | 8ms | 9780 KiB | ||||
35 | Accepted | 8ms | 9988 KiB | ||||
36 | Accepted | 8ms | 10216 KiB | ||||
37 | Accepted | 8ms | 10424 KiB | ||||
38 | Accepted | 8ms | 10512 KiB | ||||
39 | Accepted | 8ms | 10792 KiB | ||||
40 | Accepted | 8ms | 10596 KiB | ||||
41 | Accepted | 8ms | 10956 KiB | ||||
42 | Accepted | 8ms | 11244 KiB | ||||
43 | Accepted | 8ms | 11396 KiB | ||||
44 | Accepted | 8ms | 11532 KiB | ||||
45 | Accepted | 8ms | 11604 KiB | ||||
46 | Accepted | 8ms | 11460 KiB | ||||
47 | Accepted | 8ms | 11636 KiB | ||||
48 | Accepted | 8ms | 11456 KiB | ||||
49 | Accepted | 8ms | 11492 KiB | ||||
50 | Accepted | 8ms | 11640 KiB | ||||
51 | Accepted | 8ms | 11572 KiB | ||||
52 | Accepted | 8ms | 11692 KiB | ||||
53 | Accepted | 8ms | 11888 KiB | ||||
54 | Accepted | 8ms | 11840 KiB | ||||
55 | Accepted | 8ms | 11732 KiB | ||||
56 | Accepted | 8ms | 11992 KiB | ||||
57 | Accepted | 14ms | 11932 KiB | ||||
58 | Accepted | 17ms | 11940 KiB | ||||
59 | Accepted | 20ms | 12064 KiB | ||||
60 | Accepted | 17ms | 12172 KiB | ||||
61 | Accepted | 24ms | 12268 KiB | ||||
62 | Accepted | 25ms | 12172 KiB | ||||
63 | Accepted | 23ms | 12172 KiB | ||||
64 | Accepted | 25ms | 12076 KiB | ||||
65 | Accepted | 25ms | 12076 KiB | ||||
66 | Accepted | 25ms | 12168 KiB | ||||
67 | Accepted | 24ms | 12176 KiB | ||||
68 | Accepted | 25ms | 12256 KiB |