55642023-07-27 11:25:12zsomborSzéfnyitáscpp17Wrong answer 0/1009ms11432 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 answer9ms8552 KiB
2Wrong answer9ms8856 KiB
subtask20/16
3Wrong answer8ms9148 KiB
4Wrong answer9ms9364 KiB
5Wrong answer8ms9208 KiB
6Wrong answer9ms9340 KiB
7Wrong answer9ms9552 KiB
8Wrong answer9ms9568 KiB
9Wrong answer9ms9824 KiB
10Wrong answer9ms10032 KiB
11Wrong answer8ms10332 KiB
12Wrong answer8ms10288 KiB
13Wrong answer8ms10248 KiB
subtask30/24
14Wrong answer9ms10340 KiB
15Wrong answer9ms10644 KiB
16Wrong answer8ms10600 KiB
17Wrong answer8ms10600 KiB
18Wrong answer8ms10496 KiB
19Wrong answer8ms10684 KiB
20Wrong answer9ms10644 KiB
21Wrong answer9ms10692 KiB
subtask40/23
22Wrong answer8ms10728 KiB
23Wrong answer8ms10980 KiB
24Wrong answer9ms10784 KiB
25Wrong answer8ms10824 KiB
26Wrong answer8ms10820 KiB
27Wrong answer9ms10908 KiB
28Wrong answer8ms10948 KiB
29Wrong answer9ms10924 KiB
subtask50/37
30Wrong answer8ms9148 KiB
31Wrong answer9ms9364 KiB
32Wrong answer8ms9208 KiB
33Wrong answer9ms9340 KiB
34Wrong answer9ms9552 KiB
35Wrong answer9ms9568 KiB
36Wrong answer9ms9824 KiB
37Wrong answer9ms10032 KiB
38Wrong answer8ms10332 KiB
39Wrong answer8ms10288 KiB
40Wrong answer8ms10248 KiB
41Wrong answer9ms10340 KiB
42Wrong answer9ms10644 KiB
43Wrong answer8ms10600 KiB
44Wrong answer8ms10600 KiB
45Wrong answer8ms10496 KiB
46Wrong answer8ms10684 KiB
47Wrong answer9ms10644 KiB
48Wrong answer9ms10692 KiB
49Wrong answer8ms10728 KiB
50Wrong answer8ms10980 KiB
51Wrong answer9ms10784 KiB
52Wrong answer8ms10824 KiB
53Wrong answer8ms10820 KiB
54Wrong answer9ms10908 KiB
55Wrong answer8ms10948 KiB
56Wrong answer9ms10924 KiB
57Wrong answer9ms11184 KiB
58Wrong answer8ms11264 KiB
59Wrong answer8ms11304 KiB
60Wrong answer9ms11240 KiB
61Wrong answer9ms11236 KiB
62Wrong answer9ms11432 KiB
63Wrong answer8ms11344 KiB
64Wrong answer8ms11344 KiB
65Wrong answer8ms11348 KiB
66Wrong answer8ms11360 KiB
67Wrong answer8ms11356 KiB
68Wrong answer8ms11352 KiB