54002023-05-12 15:52:41szilSzéfnyitáscpp14Wrong answer 0/1007ms5904 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];

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) {
    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]);
    }
    if (v->p[1] != nullptr) {
        s2[v->t][1] = v->p[1]->t;
        upd(v->p[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 = 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][0];
        }
        add(v, s[u][0]);
    }
    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 << 0 << " " << s2[i][0] << " " << s2[i][1] << "\n";
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Wrong answer3ms1960 KiB
2Wrong answer3ms2232 KiB
subtask20/16
3Wrong answer3ms2232 KiB
4Wrong answer3ms2080 KiB
5Accepted3ms2268 KiB
6Accepted3ms2496 KiB
7Accepted3ms2572 KiB
8Wrong answer3ms2788 KiB
9Wrong answer3ms3012 KiB
10Accepted3ms2992 KiB
11Accepted3ms3120 KiB
12Wrong answer3ms3160 KiB
13Accepted3ms3296 KiB
14Accepted3ms3376 KiB
subtask30/24
15Accepted3ms3376 KiB
16Wrong answer3ms3384 KiB
17Accepted3ms3748 KiB
18Accepted3ms3868 KiB
19Accepted3ms3800 KiB
20Accepted3ms3924 KiB
21Accepted3ms3884 KiB
22Wrong answer3ms3948 KiB
23Wrong answer3ms4080 KiB
subtask40/23
24Wrong answer3ms4080 KiB
25Wrong answer3ms4116 KiB
26Accepted3ms4120 KiB
27Wrong answer3ms4128 KiB
28Accepted3ms4028 KiB
29Accepted3ms4032 KiB
30Accepted3ms4092 KiB
31Accepted3ms4084 KiB
32Accepted3ms4096 KiB
subtask50/37
33Accepted3ms4096 KiB
34Wrong answer3ms2080 KiB
35Accepted3ms2268 KiB
36Accepted3ms2496 KiB
37Accepted3ms2572 KiB
38Wrong answer3ms2788 KiB
39Wrong answer3ms3012 KiB
40Accepted3ms2992 KiB
41Accepted3ms3120 KiB
42Wrong answer3ms3160 KiB
43Accepted3ms3296 KiB
44Accepted3ms3376 KiB
45Wrong answer3ms3384 KiB
46Accepted3ms3748 KiB
47Accepted3ms3868 KiB
48Accepted3ms3800 KiB
49Accepted3ms3924 KiB
50Accepted3ms3884 KiB
51Wrong answer3ms3948 KiB
52Wrong answer3ms4080 KiB
53Wrong answer3ms4116 KiB
54Accepted3ms4120 KiB
55Wrong answer3ms4128 KiB
56Accepted3ms4028 KiB
57Accepted3ms4032 KiB
58Accepted3ms4092 KiB
59Accepted3ms4084 KiB
60Accepted3ms4096 KiB
61Wrong answer3ms4040 KiB
62Wrong answer3ms4068 KiB
63Wrong answer3ms4336 KiB
64Wrong answer3ms4296 KiB
65Wrong answer7ms5336 KiB
66Accepted7ms5384 KiB
67Wrong answer7ms5280 KiB
68Wrong answer7ms5424 KiB
69Wrong answer7ms5568 KiB
70Wrong answer7ms5596 KiB
71Accepted7ms5836 KiB
72Accepted6ms5904 KiB