21902022-12-30 15:11:141478Tom és Jerry 1 (80)cpp11Elfogadva 80/80123ms16628 KiB
#include <bits/stdc++.h>

using namespace std;

const int MINI = -300000;

int main()
{
    //ifstream cin("be.txt");

    int n, m, t, p, e;
    cin >> n >> m >> t >> p >> e;
    vector<vector<int>> jN(n + 1, vector<int>(1)), tN(n + 1, vector<int>(1));
    for (int i = 1; i <= m; i++)
    {
        int k, v, s;
        cin >> k >> v >> s;
        if (s == 2)
        {
            tN[k].push_back(v);
            tN[v].push_back(k);
        }
        jN[k].push_back(v);
        jN[v].push_back(k);
    }

    /*
    for (int i = 1; i <= n; i++)
    {
        cout << i << ": " << '\n';
        for (int j = 1; j < tN[i].size(); j++)
        {
            cout << tN[i][j] << " ";
        }
        cout << '\n';
    }
    */

    vector<int> tD(n + 1, MINI);
    queue<int> q;
    q.push(t);
    tD[t] = 0;
    while (!q.empty())
    {
        int a = q.front();
        q.pop();
        for (int i = 1; i < tN[a].size(); i++)
        {
            if (tD[tN[a][i]] == MINI)
            {
                tD[tN[a][i]] = tD[a] + 1;
                q.push(tN[a][i]);
            }
        }
    }

    /*
    for (int i = 1; i <= n; i++)
    {
        cout << tD[i] << " ";
    }
    */

    vector<int> jD(n + 1, MINI);
    priority_queue<pair<int, int>> pq;
    if (tD[e] == MINI)
    {
        jD[e] = INT_MAX;
    }
    pq.push({jD[e], e});
    while (!pq.empty())
    {
        pair<int, int> a = pq.top();
        pq.pop();
        for (int i = 1; i < jN[a.second].size(); i++)
        {
            if (jD[jN[a.second][i]] == MINI)
            {
                jD[jN[a.second][i]] = jD[a.second] - 1;
                if (tD[jN[a.second][i]] != MINI)
                {
                    jD[jN[a.second][i]] = min(jD[jN[a.second][i]], tD[jN[a.second][i]] - 1);
                }
                pq.push({jD[jN[a.second][i]], jN[a.second][i]});
            }
        }
    }

    while (p--)
    {
        int a;
        cin >> a;

        if (jD[a] >= 0)
        {
            cout << "IGEN" << '\n';
        }
        else
        {
            cout << "NEM" << '\n';
        }
    }

    return 0;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base80/80
1Elfogadva0/03ms1808 KiB
2Elfogadva0/04ms2488 KiB
3Elfogadva4/42ms2376 KiB
4Elfogadva4/42ms2284 KiB
5Elfogadva4/42ms2672 KiB
6Elfogadva4/42ms2756 KiB
7Elfogadva4/43ms2696 KiB
8Elfogadva4/44ms2948 KiB
9Elfogadva4/44ms3160 KiB
10Elfogadva4/44ms3468 KiB
11Elfogadva4/410ms4172 KiB
12Elfogadva4/416ms5692 KiB
13Elfogadva4/426ms6532 KiB
14Elfogadva4/452ms10172 KiB
15Elfogadva4/471ms10800 KiB
16Elfogadva4/487ms16628 KiB
17Elfogadva4/4112ms14704 KiB
18Elfogadva4/474ms12632 KiB
19Elfogadva4/490ms14380 KiB
20Elfogadva4/486ms14416 KiB
21Elfogadva4/478ms12280 KiB
22Elfogadva4/4123ms15356 KiB