80902024-01-12 12:39:21adamTom és Jerry 1 (80)cpp17Wrong answer 0/80574ms23780 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() {
    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] == jerry_path[i+1]) {
                cout << "NEM" << endl;
                should = true;
                break;
            }
        }
        if (should) {
            continue;
        } else cout << "IGEN" << endl;
    }

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/80
1Wrong answer0/03ms1852 KiB
2Wrong answer0/06ms2580 KiB
3Runtime error0/44ms2904 KiB
4Wrong answer0/43ms2468 KiB
5Wrong answer0/43ms2724 KiB
6Wrong answer0/43ms2916 KiB
7Wrong answer0/44ms3312 KiB
8Wrong answer0/44ms3612 KiB
9Wrong answer0/44ms3876 KiB
10Wrong answer0/46ms4180 KiB
11Wrong answer0/416ms5288 KiB
12Wrong answer0/423ms5916 KiB
13Wrong answer0/432ms7740 KiB
14Wrong answer0/478ms12192 KiB
15Wrong answer0/476ms15156 KiB
16Wrong answer0/4112ms17808 KiB
17Wrong answer0/4163ms23780 KiB
18Wrong answer0/479ms18300 KiB
19Time limit exceeded0/4568ms13768 KiB
20Time limit exceeded0/4558ms14560 KiB
21Time limit exceeded0/4569ms14396 KiB
22Time limit exceeded0/4574ms19420 KiB