199032025-12-29 12:56:00szabelrTom és Jerry 1 (80)cpp17Elfogadva 80/80123ms5680 KiB
// Tom és Jerry 1.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
#include <queue>
#include <climits>
using namespace std;
int main()
{
    int n, m, t, p, e;
    cin >> n >> m >> t >> p >> e;
    vector<vector<int>> adj_tom(n+1);
    vector<vector<int>> adj(n+1);
    for (int i = 0; i < m; i++)
    {
        int a, b, c;
        cin >> a >> b >> c;
        adj[a].push_back(b);
        adj[b].push_back(a);
        if (c == 2) {
            adj_tom[a].push_back(b);
            adj_tom[b].push_back(a);
        }
    }
    vector<int> tomt(n + 1, -1);
    queue<int> q;
    tomt[t] = 0;
    q.push(t);
    while (!q.empty())
    {
        int v = q.front();
        q.pop();

        for (auto szomszed: adj_tom[v])
        {
            if (tomt[szomszed] == -1)
            {
                tomt[szomszed] = tomt[v] + 1;
                q.push(szomszed);
            }
        }
    }
    vector<int> max_safe_time(n + 1, -1);
    priority_queue<pair<int, int>> pq;
    int start_limit;
    if (tomt[e] == -1) {
        start_limit = INT_MAX;
    }
    else {
        start_limit = tomt[e] - 1;
    }
    if (start_limit >= 0) {
        max_safe_time[e] = start_limit;
        pq.push({ start_limit, e });
    }
    while (!pq.empty()) {
        int aktualis_ido = pq.top().first;
        int u = pq.top().second;
        pq.pop();
        if (aktualis_ido < max_safe_time[u]) continue;
        for (int v : adj[u]) {
            int uj= aktualis_ido-1;
            int tom_limit_v;
            if (tomt[v] == -1) {
                tom_limit_v = INT_MAX;
            }
            else {
                tom_limit_v = tomt[v] - 1;
            }
            int vegleges_ido = min(uj, tom_limit_v);
            if (vegleges_ido > max_safe_time[v]) {
                max_safe_time[v] = vegleges_ido;
                pq.push({ vegleges_ido, v });   
            }
        }
    }
    for (int i = 0; i < p; i++) {
        int s;
        cin >> s;
        if (max_safe_time[s] >= 0) {
            cout << "IGEN" << endl;
        }
        else {
            cout << "NEM" << endl;
        }
    }
    return 0;
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
RészfeladatÖsszpontTesztVerdiktIdőMemória
base80/80
1Elfogadva0/01ms316 KiB
2Elfogadva0/03ms316 KiB
3Elfogadva4/41ms508 KiB
4Elfogadva4/41ms316 KiB
5Elfogadva4/41ms508 KiB
6Elfogadva4/41ms316 KiB
7Elfogadva4/42ms424 KiB
8Elfogadva4/43ms316 KiB
9Elfogadva4/43ms684 KiB
10Elfogadva4/43ms564 KiB
11Elfogadva4/49ms820 KiB
12Elfogadva4/413ms1332 KiB
13Elfogadva4/424ms1640 KiB
14Elfogadva4/450ms2956 KiB
15Elfogadva4/470ms3240 KiB
16Elfogadva4/479ms5680 KiB
17Elfogadva4/4105ms5168 KiB
18Elfogadva4/472ms4140 KiB
19Elfogadva4/493ms5044 KiB
20Elfogadva4/487ms4916 KiB
21Elfogadva4/472ms3704 KiB
22Elfogadva4/4123ms5428 KiB