81022024-01-12 13:14:05gortomiTom és Jerry 1 (80)cpp17Accepted 80/8059ms14740 KiB
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, m, t, p, e;
    cin >> n >> m >> t >> p >> e;
    vector<vector<int> > g1(n + 1), g2(n + 1);
    for(int i = 0; i < m; i++)
    {
        int x, y, w;
        cin >> x >> y >> w;
        g1[x].push_back(y);
        g1[y].push_back(x);
        if(w == 2)
        {
            g2[x].push_back(y);
            g2[y].push_back(x);
        }
    }
    queue<int> q;
    q.push(t);
    vector<int> d(n + 1, 1e9);
    d[t] = 0;
    while(!q.empty())
    {
        int v = q.front();
        q.pop();
        for(auto x : g2[v])
        {
            if(d[x] == 1e9)
            {
                d[x] = d[v] + 1;
                q.push(x);
            }
        }
    }
    priority_queue<pair<int, int> > pq;
    vector<int> l(n + 1, -1);
    pq.push({d[e] - 1, e});
    l[e] = d[e] - 1;
    while(!pq.empty())
    {
        auto [l_v, v] = pq.top();
        pq.pop();
        //cout << v << "\n";
        if(l[v] != l_v) continue;

        for(auto x : g1[v])
        {
            int len = min(d[x] - 1, l[v] - 1);
            if(l[x] < len)
            {
                l[x] = len;
                pq.push({l[x], x});
            }
        }
    }
    while(p--)
    {
        int x;
        cin >> x;
        cout << (l[x] < 0 ? "NEM" : "IGEN") << "\n";
    }
}
SubtaskSumTestVerdictTimeMemory
base80/80
1Accepted0/03ms1828 KiB
2Accepted0/04ms2292 KiB
3Accepted4/43ms2232 KiB
4Accepted4/43ms2460 KiB
5Accepted4/43ms2700 KiB
6Accepted4/43ms2904 KiB
7Accepted4/43ms3268 KiB
8Accepted4/44ms3548 KiB
9Accepted4/44ms3640 KiB
10Accepted4/44ms3732 KiB
11Accepted4/48ms4468 KiB
12Accepted4/48ms5444 KiB
13Accepted4/416ms6196 KiB
14Accepted4/430ms9212 KiB
15Accepted4/437ms9400 KiB
16Accepted4/443ms14740 KiB
17Accepted4/457ms13832 KiB
18Accepted4/441ms11452 KiB
19Accepted4/446ms13288 KiB
20Accepted4/443ms13408 KiB
21Accepted4/432ms10976 KiB
22Accepted4/459ms14124 KiB