8095 2024. 01. 12 12:48:22 adam Tom és Jerry 1 (80) cpp17 Hibás válasz 0/80 570ms 19572 KiB
#include <bits/stdc++.h>

using namespace std;
vector<vector<int>> labyrinth_jerry;
vector<vector<int>> labyrinth_tom;

vector<int> bfs (int from, int to, vector<vector<int>> &labyrinth) {
    queue<vector<int>> q; // first: node, second: depth;
    vector<bool> been_here(labyrinth.size(), false);
    vector<int> path;
    q.push({from, 0, -1});
    while(!q.empty()) {
        if (q.front()[0] == to) {
            path.push_back(q.front()[0]);
            return path;
        }
        for (int i = 0; i < labyrinth[q.front()[0]].size(); i++) {
            if(been_here[labyrinth[q.front()[0]][i]]) continue;
            q.push({labyrinth[q.front()[0]][i], q.front()[1]+1, q.front()[0]});
            been_here[labyrinth[q.front()[0]][i]] = true;

        }
        if (path.empty() || q.front()[2] == path[path.size() -1]) path.push_back(q.front()[0]);
        q.pop();
    }
    return path;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int point_count, road_count, tom_pos, tries_count, hole_pos;
    cin >> point_count >> road_count >> tom_pos >> tries_count >> hole_pos;
    labyrinth_jerry.assign(road_count, vector(0, 0));
    labyrinth_tom.assign(road_count, vector(0, 0));
    for (int i = 0; i < road_count; i++) {
        int road_from, road_to, width;
        cin >> road_from >> road_to >> width;

        if (width == 2) {
            labyrinth_jerry[road_from].push_back(road_to);
            labyrinth_jerry[road_to].push_back(road_from);
            labyrinth_tom[road_from].push_back(road_to);
            labyrinth_tom[road_to].push_back(road_from);
        } else {
            labyrinth_jerry[road_from].push_back(road_to);
            labyrinth_jerry[road_to].push_back(road_from);
        }
    }



    vector<int> tries(tries_count, 0);
    for (int i = 0; i < tries_count; i++) {
        cin >> tries[i];
    }
    vector<int> tom_path = bfs(tom_pos, hole_pos, labyrinth_tom);
    /*for (int i = 0; i < tom_path.size(); i++) {
        cout << tom_path[i] << " ";
    }
    cout << endl;*/
    for (int j = 0; j < tries.size(); j++) {
        vector<int> jerry_path = bfs(tries[j], hole_pos, labyrinth_jerry);
        /*for (int i = 0; i < jerry_path.size(); i++) {
            cout << jerry_path[i] << " ";
        }
        cout << endl;*/
        bool should = false;
        for (int i = 0; i < jerry_path.size(); i++) {
            if (tom_path[i > tom_path.size() - 1 ? tom_path.size() - 1 : i] == jerry_path[i+1]) {
                cout << "NEM" << endl;
                should = true;
                break;
            }
        }
        if (should) {
            continue;
        } else cout << "IGEN" << endl;
    }

    return 0;
}
Részfeladat Összpont Teszt Verdikt Idő Memória
base 0/80
1 Elfogadva 0/0 3ms 1824 KiB
2 Hibás válasz 0/0 4ms 2508 KiB
3 Futási hiba 0/4 4ms 2812 KiB
4 Hibás válasz 0/4 3ms 2364 KiB
5 Hibás válasz 0/4 3ms 2588 KiB
6 Hibás válasz 0/4 3ms 2544 KiB
7 Hibás válasz 0/4 3ms 2848 KiB
8 Hibás válasz 0/4 4ms 3120 KiB
9 Hibás válasz 0/4 4ms 3496 KiB
10 Hibás válasz 0/4 4ms 3760 KiB
11 Hibás válasz 0/4 10ms 4960 KiB
12 Hibás válasz 0/4 16ms 5188 KiB
13 Hibás válasz 0/4 21ms 6772 KiB
14 Hibás válasz 0/4 54ms 10772 KiB
15 Hibás válasz 0/4 46ms 12808 KiB
16 Hibás válasz 0/4 79ms 14748 KiB
17 Hibás válasz 0/4 114ms 19572 KiB
18 Hibás válasz 0/4 50ms 13752 KiB
19 Időlimit túllépés 0/4 564ms 8228 KiB
20 Időlimit túllépés 0/4 542ms 8332 KiB
21 Időlimit túllépés 0/4 563ms 7304 KiB
22 Időlimit túllépés 0/4 570ms 10936 KiB