81962024-01-12 18:08:15GervidTom és Jerry 1 (80)cpp17Accepted 80/80210ms16984 KiB
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <limits.h>
#include <algorithm>
#include <math.h>

using namespace std;

int main()
{
	int n, m, tstart, jstart, jtrys, hole, i, j, node1, node2, type;
	cin >> n >> m >> tstart >> jtrys >> hole;
	tstart--, hole--;

	vector<vector<int>> jg(n);
	map<int, vector<int>> tg;

	for (i = 0; i < m; i++)
	{
		cin >> node1 >> node2 >> type;
		node1--, node2--;

		jg[node1].push_back(node2);
		jg[node2].push_back(node1);

		if (type == 2)
		{
			if (!tg.count(node1))
			{
				tg[node1] = {};
			}
			if (!tg.count(node2))
			{
				tg[node2] = {};
			}

			tg[node1].push_back(node2);
			tg[node2].push_back(node1);
		}
	}

	queue<int> q;
	q.push(tstart);

	vector<int> tdist(n, INT_MAX);
	tdist[tstart] = 0;

	while (q.size() > 0)
	{
		for (i = 0; i < tg[q.front()].size(); i++)
		{
			if (tdist[tg[q.front()][i]] == INT_MAX) //!been
			{
				tdist[tg[q.front()][i]] = tdist[q.front()] + 1;
				q.push(tg[q.front()][i]);
			}
		}

		q.pop();
	}

	queue<pair<int, int>> q2;
	q2.push({ hole, tdist[hole] });
	vector<int> timeleft(n, -1);
	timeleft[hole] = INT_MAX;

	while (q2.size() > 0)
	{
		for (i = 0; i < jg[q2.front().first].size(); i++)
		{
			if (timeleft[jg[q2.front().first][i]] < q2.front().second - 1)
			{
				timeleft[jg[q2.front().first][i]] = min(tdist[jg[q2.front().first][i]], q2.front().second - 1);
				q2.push({ jg[q2.front().first][i], timeleft[jg[q2.front().first][i]] });
			}
		}

		q2.pop();
	}

	for (j = 0; j < jtrys; j++)
	{
		cin >> jstart;
		jstart--;

		if (timeleft[jstart] > 0)
		{
			cout << "IGEN" << endl;
		}
		else
		{
			cout << "NEM" << endl;
		}
	}
}
//9 10 6 3 1
//1 2 1
//1 3 1
//2 4 1
//3 4 2
//4 7 1
//3 5 2
//5 6 2
//6 8 1
//7 9 1
//8 9 1
//7
//8
//9
SubtaskSumTestVerdictTimeMemory
base80/80
1Accepted0/03ms1876 KiB
2Accepted0/06ms2496 KiB
3Accepted4/43ms2392 KiB
4Accepted4/43ms2612 KiB
5Accepted4/43ms2748 KiB
6Accepted4/43ms2956 KiB
7Accepted4/44ms3324 KiB
8Accepted4/44ms3616 KiB
9Accepted4/46ms3856 KiB
10Accepted4/47ms4172 KiB
11Accepted4/417ms4812 KiB
12Accepted4/420ms5988 KiB
13Accepted4/445ms7368 KiB
14Accepted4/490ms10492 KiB
15Accepted4/497ms9844 KiB
16Accepted4/4133ms16860 KiB
17Accepted4/4210ms16984 KiB
18Accepted4/4118ms12956 KiB
19Accepted4/4150ms16548 KiB
20Accepted4/4141ms16152 KiB
21Accepted4/4103ms10992 KiB
22Accepted4/4194ms15652 KiB