21942022-12-31 09:36:081478Inverziócpp11Runtime error 0/50574ms123060 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
base0/50
1Runtime error0/03ms1908 KiB
2Wrong answer0/010ms13612 KiB
3Runtime error0/12ms2372 KiB
4Wrong answer0/24ms2800 KiB
5Wrong answer0/72ms2924 KiB
6Wrong answer0/212ms14480 KiB
7Wrong answer0/297ms120228 KiB
8Wrong answer0/2160ms120316 KiB
9Wrong answer0/2100ms120260 KiB
10Wrong answer0/2495ms120264 KiB
11Time limit exceeded0/2574ms61400 KiB
12Time limit exceeded0/2540ms118452 KiB
13Wrong answer0/2280ms120528 KiB
14Wrong answer0/2195ms120784 KiB
15Wrong answer0/286ms120988 KiB
16Runtime error0/2296ms121548 KiB
17Wrong answer0/2231ms121140 KiB
18Wrong answer0/2130ms121144 KiB
19Wrong answer0/387ms121412 KiB
20Wrong answer0/397ms121348 KiB
21Wrong answer0/297ms121604 KiB
22Wrong answer0/2337ms121552 KiB
23Runtime error0/2331ms123060 KiB
24Wrong answer0/297ms121552 KiB