21902022-12-30 15:11:141478Tom és Jerry 1 (80)cpp11Accepted 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;
}
SubtaskSumTestVerdictTimeMemory
base80/80
1Accepted0/03ms1808 KiB
2Accepted0/04ms2488 KiB
3Accepted4/42ms2376 KiB
4Accepted4/42ms2284 KiB
5Accepted4/42ms2672 KiB
6Accepted4/42ms2756 KiB
7Accepted4/43ms2696 KiB
8Accepted4/44ms2948 KiB
9Accepted4/44ms3160 KiB
10Accepted4/44ms3468 KiB
11Accepted4/410ms4172 KiB
12Accepted4/416ms5692 KiB
13Accepted4/426ms6532 KiB
14Accepted4/452ms10172 KiB
15Accepted4/471ms10800 KiB
16Accepted4/487ms16628 KiB
17Accepted4/4112ms14704 KiB
18Accepted4/474ms12632 KiB
19Accepted4/490ms14380 KiB
20Accepted4/486ms14416 KiB
21Accepted4/478ms12280 KiB
22Accepted4/4123ms15356 KiB