54012023-05-12 15:55:28szilSzéfnyitáscpp14Wrong answer 23/1008ms6336 KiB
#include <bits/stdc++.h>

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

const int MAXN = 151;

int a[MAXN];
int s[MAXN][2], s2[50001][2], 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;
    }

    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
1Accepted3ms1844 KiB
2Accepted3ms2056 KiB
subtask20/16
3Accepted3ms2056 KiB
4Accepted3ms2244 KiB
5Accepted3ms2456 KiB
6Wrong answer3ms2800 KiB
7Wrong answer3ms2876 KiB
8Accepted3ms3220 KiB
9Accepted2ms3176 KiB
10Wrong answer3ms3260 KiB
11Wrong answer3ms3472 KiB
12Accepted3ms3520 KiB
13Wrong answer3ms3612 KiB
14Wrong answer3ms3824 KiB
subtask30/24
15Wrong answer3ms3824 KiB
16Accepted3ms3924 KiB
17Accepted3ms4276 KiB
18Accepted3ms4296 KiB
19Accepted3ms4232 KiB
20Accepted3ms4408 KiB
21Accepted3ms4396 KiB
22Accepted3ms4360 KiB
23Accepted3ms4368 KiB
subtask423/23
24Accepted3ms4368 KiB
25Accepted3ms4492 KiB
26Accepted3ms4348 KiB
27Accepted3ms4512 KiB
28Accepted3ms4436 KiB
29Accepted3ms4428 KiB
30Accepted3ms4440 KiB
31Accepted3ms4696 KiB
32Accepted3ms4792 KiB
subtask50/37
33Accepted3ms4792 KiB
34Accepted3ms2244 KiB
35Accepted3ms2456 KiB
36Wrong answer3ms2800 KiB
37Wrong answer3ms2876 KiB
38Accepted3ms3220 KiB
39Accepted2ms3176 KiB
40Wrong answer3ms3260 KiB
41Wrong answer3ms3472 KiB
42Accepted3ms3520 KiB
43Wrong answer3ms3612 KiB
44Wrong answer3ms3824 KiB
45Accepted3ms3924 KiB
46Accepted3ms4276 KiB
47Accepted3ms4296 KiB
48Accepted3ms4232 KiB
49Accepted3ms4408 KiB
50Accepted3ms4396 KiB
51Accepted3ms4360 KiB
52Accepted3ms4368 KiB
53Accepted3ms4492 KiB
54Accepted3ms4348 KiB
55Accepted3ms4512 KiB
56Accepted3ms4436 KiB
57Accepted3ms4428 KiB
58Accepted3ms4440 KiB
59Accepted3ms4696 KiB
60Accepted3ms4792 KiB
61Accepted4ms4880 KiB
62Accepted6ms5608 KiB
63Accepted6ms5560 KiB
64Accepted7ms5756 KiB
65Accepted7ms5812 KiB
66Accepted7ms5916 KiB
67Accepted7ms5836 KiB
68Accepted7ms5940 KiB
69Accepted7ms5792 KiB
70Accepted8ms6252 KiB
71Accepted7ms6336 KiB
72Accepted7ms6264 KiB