37202023-03-02 13:52:59ZsofiaKeresztelyTom és Jerry 1 (80)cpp14Accepted 80/80224ms17872 KiB
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define fi first
#define se second

vector<vector<int> > gj, gt;
vector<int> dt;
vector<bool> vis;

void tom(int start){
    queue<int> q;
    q.push(start);
    dt[start] = 0;
    while (!q.empty()){
        int v = q.front();
        q.pop();
        for (int x : gt[v]){
            if (dt[x] < INT_MAX/2) continue;
            dt[x] = dt[v] + 1;
            q.push(x);
        }
    }
}

void jerry(int start){
    priority_queue<pii> q;
    q.push({dt[start] - 1, start});
    while (!q.empty()){
        pii v = q.top();
        q.pop();
        if (v.fi < 0) continue;
        vis[v.se] = true;
        for (int x : gj[v.se]){
            if (vis[x]) continue;
            q.push({min(dt[x] - 1, v.fi - 1), x});
        }
    }
}

int main()
{
    int n, m, t, p, j;
    cin >> n >> m >> t >> p >> j;
    gj.resize(n+1);
    gt.resize(n+1);
    dt.assign(n+1, INT_MAX/2);
    vis.assign(n+1, false);
    while (m--){
        int a, b, w;
        cin >> a >> b >> w;
        gj[a].push_back(b);
        gj[b].push_back(a);
        if (w == 2){
            gt[a].push_back(b);
            gt[b].push_back(a);
        }
    }
    tom(t);
    jerry(j);
    while (p--){
        int a;
        cin >> a;
        if (vis[a]){
            cout << "IGEN\n";
        }
        else{
            cout << "NEM\n";
        }
    }
}
SubtaskSumTestVerdictTimeMemory
base80/80
1Accepted0/03ms1808 KiB
2Accepted0/04ms2488 KiB
3Accepted4/43ms2216 KiB
4Accepted4/43ms2456 KiB
5Accepted4/43ms2680 KiB
6Accepted4/43ms2896 KiB
7Accepted4/43ms3244 KiB
8Accepted4/44ms3504 KiB
9Accepted4/44ms3560 KiB
10Accepted4/44ms3916 KiB
11Accepted4/418ms5216 KiB
12Accepted4/414ms5672 KiB
13Accepted4/435ms7352 KiB
14Accepted4/476ms10304 KiB
15Accepted4/4224ms17660 KiB
16Accepted4/474ms14792 KiB
17Accepted4/4119ms14608 KiB
18Accepted4/4108ms12952 KiB
19Accepted4/493ms13556 KiB
20Accepted4/497ms13268 KiB
21Accepted4/475ms11124 KiB
22Accepted4/4207ms17872 KiB