200082025-12-31 00:17:52szabelrBizonyításcpp17Accepted 50/50303ms2128 KiB
// Bizonyítás.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>

using namespace std;

// Az elérhetőségi mátrix: matrix[honnan][hova]
bool elerheto[501][501];

int main() {
    // Gyorsítás: a standard bemenet/kimenet szinkronizációjának kikapcsolása
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, q;
    if (!(cin >> n >> q)) return 0;

    // Kezdetben minden állításból levezethető saját maga (reflexivitás)
    for (int i = 1; i <= n; i++) {
        elerheto[i][i] = true;
    }

    for (int i = 0; i < q; i++) {
        int tipus, x, y;
        cin >> tipus >> x >> y;

        if (tipus == 2) {
            // RÖPDOLGOZAT: Megnézzük, van-e levezetés x-ből y-ba
            if (elerheto[x][y]) {
                cout << "IGEN\n";
            }
            else {
                cout << "NEM\n";
            }
        }
        else if (tipus == 1) {
            // ÚJ BIZONYÍTÁS: x -> y
            // Ha már tudjuk, hogy x-ből elérhető y, nem kell tennünk semmit
            if (elerheto[x][y]) continue;

            // 1. Gyűjtsük össze az "Elődöket" (akik látják x-et)
            vector<int> elodok;
            for (int j = 1; j <= n; j++) {
                if (elerheto[j][x]) {
                    elodok.push_back(j);
                }
            }

            // 2. Gyűjtsük össze az "Utódokat" (akit y lát)
            vector<int> utodok;
            for (int j = 1; j <= n; j++) {
                if (elerheto[y][j]) {
                    utodok.push_back(j);
                }
            }

            // 3. A "Híd" megépítése: Minden elődöt összekötünk minden utóddal
            for (int forras : elodok) {
                for (int cel : utodok) {
                    elerheto[forras][cel] = true;
                }
            }
        }
    }

    return 0;
}
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted1ms316 KiB
2Accepted86ms1076 KiB
subtask210/10
3Accepted2ms500 KiB
4Accepted4ms524 KiB
5Accepted35ms760 KiB
6Accepted20ms564 KiB
7Accepted23ms680 KiB
8Accepted2ms316 KiB
9Accepted1ms316 KiB
10Accepted7ms316 KiB
11Accepted17ms572 KiB
12Accepted28ms564 KiB
subtask315/15
13Accepted1ms316 KiB
14Accepted1ms508 KiB
15Accepted1ms316 KiB
16Accepted1ms512 KiB
17Accepted1ms432 KiB
18Accepted1ms508 KiB
19Accepted1ms500 KiB
20Accepted1ms316 KiB
21Accepted1ms316 KiB
22Accepted1ms316 KiB
23Accepted2ms316 KiB
24Accepted1ms316 KiB
25Accepted1ms444 KiB
26Accepted1ms316 KiB
27Accepted1ms316 KiB
28Accepted1ms500 KiB
29Accepted1ms316 KiB
30Accepted1ms316 KiB
31Accepted1ms316 KiB
32Accepted1ms316 KiB
33Accepted1ms316 KiB
34Accepted1ms316 KiB
35Accepted1ms500 KiB
36Accepted1ms316 KiB
37Accepted1ms316 KiB
38Accepted1ms316 KiB
subtask425/25
39Accepted1ms316 KiB
40Accepted87ms1212 KiB
41Accepted2ms500 KiB
42Accepted4ms524 KiB
43Accepted35ms760 KiB
44Accepted20ms564 KiB
45Accepted23ms680 KiB
46Accepted2ms316 KiB
47Accepted1ms316 KiB
48Accepted7ms316 KiB
49Accepted17ms572 KiB
50Accepted28ms564 KiB
51Accepted1ms508 KiB
52Accepted1ms316 KiB
53Accepted1ms512 KiB
54Accepted1ms432 KiB
55Accepted1ms508 KiB
56Accepted1ms500 KiB
57Accepted1ms316 KiB
58Accepted1ms316 KiB
59Accepted1ms316 KiB
60Accepted2ms316 KiB
61Accepted1ms316 KiB
62Accepted1ms444 KiB
63Accepted1ms316 KiB
64Accepted1ms316 KiB
65Accepted1ms500 KiB
66Accepted1ms316 KiB
67Accepted1ms316 KiB
68Accepted1ms316 KiB
69Accepted1ms316 KiB
70Accepted1ms316 KiB
71Accepted1ms316 KiB
72Accepted1ms500 KiB
73Accepted1ms316 KiB
74Accepted1ms316 KiB
75Accepted1ms316 KiB
76Accepted23ms856 KiB
77Accepted14ms624 KiB
78Accepted67ms1188 KiB
79Accepted13ms568 KiB
80Accepted48ms816 KiB
81Accepted20ms680 KiB
82Accepted21ms564 KiB
83Accepted18ms568 KiB
84Accepted29ms564 KiB
85Accepted52ms904 KiB
86Accepted37ms1340 KiB
87Accepted48ms908 KiB
88Accepted18ms564 KiB
89Accepted23ms608 KiB
90Accepted59ms1332 KiB
91Accepted68ms820 KiB
92Accepted59ms1316 KiB
93Accepted59ms820 KiB
94Accepted59ms1328 KiB
95Accepted41ms928 KiB
96Accepted57ms1072 KiB
97Accepted59ms2064 KiB
98Accepted43ms1076 KiB
99Accepted57ms1180 KiB
100Accepted256ms1580 KiB
101Accepted259ms1680 KiB
102Accepted303ms2100 KiB
103Accepted303ms2128 KiB
104Accepted246ms1332 KiB