80952024-01-12 12:48:22adamTom és Jerry 1 (80)cpp17Wrong answer 0/80570ms19572 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;
}
SubtaskSumTestVerdictTimeMemory
base0/80
1Accepted0/03ms1824 KiB
2Wrong answer0/04ms2508 KiB
3Runtime error0/44ms2812 KiB
4Wrong answer0/43ms2364 KiB
5Wrong answer0/43ms2588 KiB
6Wrong answer0/43ms2544 KiB
7Wrong answer0/43ms2848 KiB
8Wrong answer0/44ms3120 KiB
9Wrong answer0/44ms3496 KiB
10Wrong answer0/44ms3760 KiB
11Wrong answer0/410ms4960 KiB
12Wrong answer0/416ms5188 KiB
13Wrong answer0/421ms6772 KiB
14Wrong answer0/454ms10772 KiB
15Wrong answer0/446ms12808 KiB
16Wrong answer0/479ms14748 KiB
17Wrong answer0/4114ms19572 KiB
18Wrong answer0/450ms13752 KiB
19Time limit exceeded0/4564ms8228 KiB
20Time limit exceeded0/4542ms8332 KiB
21Time limit exceeded0/4563ms7304 KiB
22Time limit exceeded0/4570ms10936 KiB