81142024-01-12 13:50:59adamTom és Jerry 1 (80)cpp17Futási hiba 0/80108ms19388 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;

        }
        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;

        }
        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) {
            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;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base0/80
1Elfogadva0/03ms1888 KiB
2Futási hiba0/04ms2616 KiB
3Futási hiba0/44ms2780 KiB
4Hibás válasz0/43ms2384 KiB
5Hibás válasz0/43ms2392 KiB
6Futási hiba0/43ms2492 KiB
7Hibás válasz0/43ms2696 KiB
8Hibás válasz0/44ms3084 KiB
9Futási hiba0/44ms3208 KiB
10Futási hiba0/44ms3404 KiB
11Hibás válasz0/410ms4732 KiB
12Hibás válasz0/414ms4964 KiB
13Futási hiba0/416ms6896 KiB
14Hibás válasz0/454ms10508 KiB
15Futási hiba0/435ms12708 KiB
16Futási hiba0/441ms14516 KiB
17Futási hiba0/4108ms19388 KiB
18Hibás válasz0/450ms13296 KiB
19Futási hiba0/446ms14020 KiB
20Futási hiba0/446ms14000 KiB
21Futási hiba0/437ms12036 KiB
22Futási hiba0/492ms18972 KiB