73672024-01-08 11:32:39tamasmarkTom és Jerry 1 (80)cpp17Wrong answer 60/80122ms16116 KiB
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include<algorithm>
#include <climits>
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) {
    deque<pii> q;
    q.push_back({ dt[start] - 1, start });
    while (!q.empty()) {
        pii v = q.front();
        q.pop_front();
        if (v.fi < 0) continue;
        vis[v.se] = true;
        for (int x : gj[v.se]) {
            if (vis[x]) continue;
            q.push_back({ 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";
        }
    }
}
/*
9 11 6 3 1
1 2 1
1 3 1
2 4 1
3 4 2
3 5 2
4 7 1
3 5 2
5 6 2
6 8 1
7 9 1
8 9 1
7
8
9
*/
SubtaskSumTestVerdictTimeMemory
base60/80
1Accepted0/03ms1808 KiB
2Accepted0/04ms2416 KiB
3Accepted4/43ms2252 KiB
4Accepted4/43ms2368 KiB
5Accepted4/43ms2504 KiB
6Accepted4/43ms2704 KiB
7Accepted4/43ms3060 KiB
8Wrong answer0/44ms3316 KiB
9Wrong answer0/44ms3416 KiB
10Accepted4/44ms3564 KiB
11Accepted4/412ms4252 KiB
12Accepted4/414ms5072 KiB
13Accepted4/425ms6124 KiB
14Accepted4/448ms8864 KiB
15Accepted4/479ms11244 KiB
16Accepted4/468ms14016 KiB
17Accepted4/4101ms14196 KiB
18Accepted4/470ms12052 KiB
19Wrong answer0/475ms13324 KiB
20Wrong answer0/472ms13188 KiB
21Accepted4/468ms11236 KiB
22Wrong answer0/4122ms16116 KiB