81472024-01-12 14:38:30adamTom és Jerry 1 (80)cpp17Runtime error 0/80116ms20432 KiB
#include <bits/stdc++.h>

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

vector<pair<int, int>> bfs_jerry (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;
    vector<pair<int, int>> depths;
    q.push({from, 0, -1});
    while(!q.empty()) {
        if (q.front()[0] == to) {
            depths[q.front()[0]] = pair(q.front()[0], q.front()[1]);
            return depths;
        }
        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;

        }
        assert(q.front().size() >= 2);
        if (path.empty() || q.front()[2] == path[path.size() -1]) {
            depths.push_back(pair(q.front()[0], q.front()[1]));
            path.push_back(q.front()[0]);
        };
        q.pop();
    }
    return depths;
}
map<int, int> bfs_tom (int from, vector<vector<int>> &labyrinth) {
    queue<vector<int>> q; // first: node, second: depth;
    vector<bool> been_here(labyrinth.size(), false);
    vector<int> path;
    map<int, int> depths;
    q.push({from, 0, -1});
    while(!q.empty()) {
        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;

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

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];
    }
    map<int, int> tom_path = bfs_tom(tom_pos, labyrinth_tom);

    for (int i = 0; i < tries.size(); i++) {
        vector<pair<int, int>> jerry_depths = bfs_jerry(tries[i], hole_pos, labyrinth_jerry);
        string log;
        for (pair<int, int> jerr : jerry_depths) {
            assert(tom_path.count(jerr.first) != 0 || tom_path.size() >= jerr.first);
            if (tom_path.count(jerr.first) != 0 && tom_path[jerr.first] <= jerr.second) {
                log = "NEM";
                continue;
            }
        }
        if(log.length() == 0) log = "IGEN";

        cout << log << endl;

    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/80
1Runtime error0/04ms2152 KiB
2Runtime error0/04ms2780 KiB
3Runtime error0/44ms2964 KiB
4Runtime error0/43ms2552 KiB
5Runtime error0/43ms2804 KiB
6Runtime error0/43ms3312 KiB
7Runtime error0/44ms3532 KiB
8Runtime error0/44ms3732 KiB
9Runtime error0/44ms3864 KiB
10Runtime error0/44ms3988 KiB
11Runtime error0/413ms5152 KiB
12Runtime error0/414ms6008 KiB
13Runtime error0/425ms7800 KiB
14Runtime error0/450ms11556 KiB
15Runtime error0/468ms13700 KiB
16Runtime error0/471ms15308 KiB
17Runtime error0/4116ms20432 KiB
18Runtime error0/465ms13996 KiB
19Runtime error0/470ms14744 KiB
20Runtime error0/475ms14472 KiB
21Runtime error0/459ms13184 KiB
22Runtime error0/4112ms19760 KiB