55652023-07-27 11:25:18zsomborSzéfnyitáscpp17Wrong answer 0/1009ms11180 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) {
    /*cout << endl << i << "  ";
    for (int l = 1; l <= n; l++) cout << v[l] << " ";
    cout << "  ";
    for (int l = 1; l <= n; l++) cout << cur[l] << " ";*/
    int i = *s.begin(), J = cur[i], j = cur[i];
    vector <set <int>> v(n + 1);
    for (int cnt = 0; cnt < 23000; 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 test(int A) {
    int a = A, b = 1, cnt = 0;
    for (int i = 0; i < 1e2; i++) {
        int x = B[a], y = B[(b % n ? b % n : n)];
        cout << a << " " << b << "  " << x << " " << y << endl;
        if (x != y) cnt++;
        a = T[a][y]; b = t[b][x];
    }
    if (cnt >= k) cout << A << " ";
    return cnt;
}

bool teszt = 1;

int main() {
    if (teszt) {
        n = 3;
        k = n;
        srand(time(0));
        for (int i = 1; i <= n; i++) {
            B[i] = rand() % 2;
            T[i][0] = rand() % n + 1;
            T[i][1] = rand() % n + 1;
        }
        cout << "bemenet:\n";
        for (int i = 1; i <= n; i++) {
            cout << B[i] << " " << T[i][0] << " " << T[i][1] << endl;
        }
        cout << endl;
    }
    else {
        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";
        }
    }

    cout << endl;
    bool jo = true;
    //for (int i = 1; i <= n; i++) if (test(i) >= k) jo = false;
    test(3);
    cout << endl << (jo ? "HELYES" : "ROSSZ");
}

/*

5
1 5 1
1 1 4
0 5 4
0 2 3
0 2 2
5


3
1 2 1
0 1 3
0 2 2
3

*/
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Wrong answer9ms8556 KiB
2Wrong answer9ms8852 KiB
subtask20/16
3Wrong answer8ms8912 KiB
4Wrong answer8ms8872 KiB
5Wrong answer8ms8876 KiB
6Wrong answer8ms9128 KiB
7Wrong answer8ms9360 KiB
8Wrong answer8ms9316 KiB
9Wrong answer9ms9472 KiB
10Wrong answer8ms9432 KiB
11Wrong answer9ms9688 KiB
12Wrong answer9ms9900 KiB
13Wrong answer9ms10092 KiB
subtask30/24
14Wrong answer8ms10048 KiB
15Wrong answer9ms9944 KiB
16Wrong answer9ms10196 KiB
17Wrong answer8ms10408 KiB
18Wrong answer9ms10620 KiB
19Wrong answer9ms10580 KiB
20Wrong answer9ms10492 KiB
21Wrong answer9ms10788 KiB
subtask40/23
22Wrong answer9ms10704 KiB
23Wrong answer9ms11016 KiB
24Wrong answer8ms10700 KiB
25Wrong answer8ms10704 KiB
26Wrong answer8ms10880 KiB
27Wrong answer8ms10700 KiB
28Wrong answer8ms10700 KiB
29Wrong answer8ms10700 KiB
subtask50/37
30Wrong answer8ms8912 KiB
31Wrong answer8ms8872 KiB
32Wrong answer8ms8876 KiB
33Wrong answer8ms9128 KiB
34Wrong answer8ms9360 KiB
35Wrong answer8ms9316 KiB
36Wrong answer9ms9472 KiB
37Wrong answer8ms9432 KiB
38Wrong answer9ms9688 KiB
39Wrong answer9ms9900 KiB
40Wrong answer9ms10092 KiB
41Wrong answer8ms10048 KiB
42Wrong answer9ms9944 KiB
43Wrong answer9ms10196 KiB
44Wrong answer8ms10408 KiB
45Wrong answer9ms10620 KiB
46Wrong answer9ms10580 KiB
47Wrong answer9ms10492 KiB
48Wrong answer9ms10788 KiB
49Wrong answer9ms10704 KiB
50Wrong answer9ms11016 KiB
51Wrong answer8ms10700 KiB
52Wrong answer8ms10704 KiB
53Wrong answer8ms10880 KiB
54Wrong answer8ms10700 KiB
55Wrong answer8ms10700 KiB
56Wrong answer8ms10700 KiB
57Wrong answer8ms10700 KiB
58Wrong answer8ms10744 KiB
59Wrong answer8ms10756 KiB
60Wrong answer8ms10964 KiB
61Wrong answer8ms10924 KiB
62Wrong answer8ms10964 KiB
63Wrong answer8ms11180 KiB
64Wrong answer8ms11136 KiB
65Wrong answer8ms11136 KiB
66Wrong answer8ms11136 KiB
67Wrong answer8ms11132 KiB
68Wrong answer8ms11180 KiB