53982023-05-12 15:50:38szilSzéfnyitáscpp14Wrong answer 0/1007ms6016 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++) {
        cout << 0 << " " << s2[i][0] << " " << s2[i][1] << "\n";
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Wrong answer3ms1832 KiB
2Wrong answer3ms2028 KiB
subtask20/16
3Wrong answer3ms2028 KiB
4Wrong answer3ms2244 KiB
5Wrong answer3ms2452 KiB
6Accepted2ms2664 KiB
7Accepted2ms2872 KiB
8Wrong answer2ms2956 KiB
9Wrong answer3ms3104 KiB
10Accepted2ms3028 KiB
11Accepted3ms3160 KiB
12Wrong answer2ms3248 KiB
13Accepted3ms3476 KiB
14Accepted3ms3560 KiB
subtask30/24
15Accepted3ms3560 KiB
16Wrong answer3ms3920 KiB
17Wrong answer3ms3796 KiB
18Wrong answer3ms3712 KiB
19Wrong answer3ms3712 KiB
20Wrong answer3ms3764 KiB
21Wrong answer3ms3708 KiB
22Wrong answer3ms3764 KiB
23Wrong answer3ms3708 KiB
subtask40/23
24Wrong answer3ms3708 KiB
25Wrong answer3ms3688 KiB
26Wrong answer3ms3692 KiB
27Wrong answer3ms3828 KiB
28Wrong answer3ms3940 KiB
29Wrong answer3ms4104 KiB
30Wrong answer3ms4064 KiB
31Wrong answer3ms4112 KiB
32Wrong answer3ms4376 KiB
subtask50/37
33Wrong answer3ms4376 KiB
34Wrong answer3ms2244 KiB
35Wrong answer3ms2452 KiB
36Accepted2ms2664 KiB
37Accepted2ms2872 KiB
38Wrong answer2ms2956 KiB
39Wrong answer3ms3104 KiB
40Accepted2ms3028 KiB
41Accepted3ms3160 KiB
42Wrong answer2ms3248 KiB
43Accepted3ms3476 KiB
44Accepted3ms3560 KiB
45Wrong answer3ms3920 KiB
46Wrong answer3ms3796 KiB
47Wrong answer3ms3712 KiB
48Wrong answer3ms3712 KiB
49Wrong answer3ms3764 KiB
50Wrong answer3ms3708 KiB
51Wrong answer3ms3764 KiB
52Wrong answer3ms3708 KiB
53Wrong answer3ms3688 KiB
54Wrong answer3ms3692 KiB
55Wrong answer3ms3828 KiB
56Wrong answer3ms3940 KiB
57Wrong answer3ms4104 KiB
58Wrong answer3ms4064 KiB
59Wrong answer3ms4112 KiB
60Wrong answer3ms4376 KiB
61Wrong answer3ms4280 KiB
62Wrong answer3ms4356 KiB
63Wrong answer3ms4316 KiB
64Wrong answer3ms4316 KiB
65Wrong answer6ms5372 KiB
66Wrong answer7ms5516 KiB
67Wrong answer7ms5512 KiB
68Wrong answer6ms5456 KiB
69Wrong answer7ms5608 KiB
70Wrong answer7ms5896 KiB
71Wrong answer7ms6016 KiB
72Wrong answer6ms5732 KiB