81962024-01-12 18:08:15GervidTom és Jerry 1 (80)cpp17Elfogadva 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
RészfeladatÖsszpontTesztVerdiktIdőMemória
base80/80
1Elfogadva0/03ms1876 KiB
2Elfogadva0/06ms2496 KiB
3Elfogadva4/43ms2392 KiB
4Elfogadva4/43ms2612 KiB
5Elfogadva4/43ms2748 KiB
6Elfogadva4/43ms2956 KiB
7Elfogadva4/44ms3324 KiB
8Elfogadva4/44ms3616 KiB
9Elfogadva4/46ms3856 KiB
10Elfogadva4/47ms4172 KiB
11Elfogadva4/417ms4812 KiB
12Elfogadva4/420ms5988 KiB
13Elfogadva4/445ms7368 KiB
14Elfogadva4/490ms10492 KiB
15Elfogadva4/497ms9844 KiB
16Elfogadva4/4133ms16860 KiB
17Elfogadva4/4210ms16984 KiB
18Elfogadva4/4118ms12956 KiB
19Elfogadva4/4150ms16548 KiB
20Elfogadva4/4141ms16152 KiB
21Elfogadva4/4103ms10992 KiB
22Elfogadva4/4194ms15652 KiB