54022023-05-12 15:58:58szilSzéfnyitáscpp14Accepted 100/1008ms6420 KiB
#include <bits/stdc++.h>

using ll = long long;
using namespace std;
const ll INF = 1e18;

const int MAXN = 151;

int s[MAXN][2], s2[50001][2], a[MAXN], b[50001];
bool bits[MAXN];

int timer;
struct Node {
    Node *p[2] = {nullptr, nullptr};
    int u = -1, t;
};

Node *root;

void add(vector<int> &v, int u) {
    Node *ptr = root;
    for (int i : v) {
        if (ptr->p[i] == nullptr) {
            ptr->p[i] = new Node();
            ptr->p[i]->t = timer++;
        }
        ptr = ptr->p[i];
    }
    ptr->u = u;
}

void upd(Node *v, int d = 0) {
    b[v->t] = bits[d];
    if (v->u != -1) {
        s2[v->t][0] = s2[v->t][1] = v->u;
        return;
    }
    if (v->p[0] != nullptr) {
        s2[v->t][0] = v->p[0]->t;
        upd(v->p[0], d + 1);
    }
    if (v->p[1] != nullptr) {
        s2[v->t][1] = v->p[1]->t;
        upd(v->p[1], d + 1);
    }
}

int main()
{
    srand(time(0));
    ios::sync_with_stdio(0); cin.tie(0);
    int n, k; cin >> n;
    timer = n + 1;
    root = new Node();
    root->t = timer++;
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> a[i] >> s[i][0] >> s[i][1];
    }
    cin >> k;
    for (int i = 0; i < n; i++) {
        bits[i] = rand() % 2;
    }

    if (n <= 2) {
        b[1] = 0;
        b[2] = 1;

        for (int i = 1; i <= 2; i++) {
            for (int j = 1; j <= 2; j++) {
                for (int c = 1; c <= 2; c++) {
                    for (int d = 1; d <= 2; d++) {
                        s2[1][0] = i;
                        s2[1][1] = j;
                        s2[2][0] = c;
                        s2[2][1] = d;
                        bool g = true;
                        for (int start = 1; start <= n && g; start++) {
                            int left = k;
                            int stB = 1;
                            int st = start;
                            for (int it = 0; it <= 10; it++) {
                                int o1 = a[st];
                                int o2 = b[stB];
                                if (o1 != o2) {
                                    if (left == 0) {
                                        g = false;
                                        break;
                                    }
                                    left--;
                                }
                                st = s[st][o2];
                                stB = s2[stB][o1];
                            }
                        }

                        if (g) {
                            cout << "2 1\n";
                            cout << b[1] << " " << s2[1][0] << " " << s2[1][1] << "\n" << b[2] << " " << s2[2][0] << " " << s2[2][1] << "\n";
                            exit(0);
                        }
                    }
                }
            }
        }
        exit(1);
    }

    for (int i = 1; i <= n; i++) {
        vector<int> v;
        int u = i;
        for (int it = 0; it < n-1; it++) {
            v.push_back(a[u]);
            u = s[u][bits[it]];
        }
        add(v, s[u][bits[n-1]]);
    }
    upd(root);
    cout << timer-1 << " " << n+1 << "\n";
    for (int i = 1; i <= n; i++) {
        cout << a[i] << " " << s[i][0] << " " << s[i][1] << "\n";
    }
    for (int i = n+1; i < timer; i++) {
        if (s2[i][0] == 0) s2[i][0] = s2[i][1];
        if (s2[i][1] == 0) s2[i][1] = s2[i][0];
        if (s2[i][0] == 0) {
            s2[i][0] = s2[i][1] = 1;
        }
        cout << b[i] << " " << s2[i][0] << " " << s2[i][1] << "\n";
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1836 KiB
2Accepted3ms2028 KiB
subtask216/16
3Accepted3ms2028 KiB
4Accepted3ms2240 KiB
5Accepted3ms2448 KiB
6Accepted3ms2664 KiB
7Accepted3ms2880 KiB
8Accepted3ms3092 KiB
9Accepted2ms3172 KiB
10Accepted2ms3172 KiB
11Accepted3ms3384 KiB
12Accepted2ms3384 KiB
13Accepted3ms3516 KiB
14Accepted3ms3596 KiB
subtask324/24
15Accepted3ms3596 KiB
16Accepted3ms3608 KiB
17Accepted3ms3884 KiB
18Accepted3ms4188 KiB
19Accepted3ms4308 KiB
20Accepted3ms4392 KiB
21Accepted3ms4476 KiB
22Accepted3ms4420 KiB
23Accepted3ms4412 KiB
subtask423/23
24Accepted3ms4412 KiB
25Accepted3ms4516 KiB
26Accepted3ms4600 KiB
27Accepted3ms4616 KiB
28Accepted3ms4776 KiB
29Accepted3ms5056 KiB
30Accepted3ms5016 KiB
31Accepted3ms5024 KiB
32Accepted3ms5020 KiB
subtask537/37
33Accepted3ms5020 KiB
34Accepted3ms2240 KiB
35Accepted3ms2448 KiB
36Accepted3ms2664 KiB
37Accepted3ms2880 KiB
38Accepted3ms3092 KiB
39Accepted2ms3172 KiB
40Accepted2ms3172 KiB
41Accepted3ms3384 KiB
42Accepted2ms3384 KiB
43Accepted3ms3516 KiB
44Accepted3ms3596 KiB
45Accepted3ms3608 KiB
46Accepted3ms3884 KiB
47Accepted3ms4188 KiB
48Accepted3ms4308 KiB
49Accepted3ms4392 KiB
50Accepted3ms4476 KiB
51Accepted3ms4420 KiB
52Accepted3ms4412 KiB
53Accepted3ms4516 KiB
54Accepted3ms4600 KiB
55Accepted3ms4616 KiB
56Accepted3ms4776 KiB
57Accepted3ms5056 KiB
58Accepted3ms5016 KiB
59Accepted3ms5024 KiB
60Accepted3ms5020 KiB
61Accepted4ms5200 KiB
62Accepted6ms5932 KiB
63Accepted6ms5808 KiB
64Accepted7ms6048 KiB
65Accepted7ms6232 KiB
66Accepted8ms6420 KiB
67Accepted7ms6188 KiB
68Accepted7ms6244 KiB
69Accepted7ms6260 KiB
70Accepted7ms6276 KiB
71Accepted7ms6268 KiB
72Accepted7ms6292 KiB