55662023-07-27 11:25:49zsomborSzéfnyitáscpp17Accepted 100/10025ms12268 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";
        }
    }
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted8ms8876 KiB
2Accepted8ms9168 KiB
subtask216/16
3Accepted8ms8800 KiB
4Accepted8ms9284 KiB
5Accepted8ms9396 KiB
6Accepted8ms9892 KiB
7Accepted8ms9780 KiB
8Accepted8ms9988 KiB
9Accepted8ms10216 KiB
10Accepted8ms10424 KiB
11Accepted8ms10512 KiB
12Accepted8ms10792 KiB
13Accepted8ms10596 KiB
subtask324/24
14Accepted8ms10956 KiB
15Accepted8ms11244 KiB
16Accepted8ms11396 KiB
17Accepted8ms11532 KiB
18Accepted8ms11604 KiB
19Accepted8ms11460 KiB
20Accepted8ms11636 KiB
21Accepted8ms11456 KiB
subtask423/23
22Accepted8ms11492 KiB
23Accepted8ms11640 KiB
24Accepted8ms11572 KiB
25Accepted8ms11692 KiB
26Accepted8ms11888 KiB
27Accepted8ms11840 KiB
28Accepted8ms11732 KiB
29Accepted8ms11992 KiB
subtask537/37
30Accepted8ms8800 KiB
31Accepted8ms9284 KiB
32Accepted8ms9396 KiB
33Accepted8ms9892 KiB
34Accepted8ms9780 KiB
35Accepted8ms9988 KiB
36Accepted8ms10216 KiB
37Accepted8ms10424 KiB
38Accepted8ms10512 KiB
39Accepted8ms10792 KiB
40Accepted8ms10596 KiB
41Accepted8ms10956 KiB
42Accepted8ms11244 KiB
43Accepted8ms11396 KiB
44Accepted8ms11532 KiB
45Accepted8ms11604 KiB
46Accepted8ms11460 KiB
47Accepted8ms11636 KiB
48Accepted8ms11456 KiB
49Accepted8ms11492 KiB
50Accepted8ms11640 KiB
51Accepted8ms11572 KiB
52Accepted8ms11692 KiB
53Accepted8ms11888 KiB
54Accepted8ms11840 KiB
55Accepted8ms11732 KiB
56Accepted8ms11992 KiB
57Accepted14ms11932 KiB
58Accepted17ms11940 KiB
59Accepted20ms12064 KiB
60Accepted17ms12172 KiB
61Accepted24ms12268 KiB
62Accepted25ms12172 KiB
63Accepted23ms12172 KiB
64Accepted25ms12076 KiB
65Accepted25ms12076 KiB
66Accepted25ms12168 KiB
67Accepted24ms12176 KiB
68Accepted25ms12256 KiB