81952024-01-12 18:03:27GervidTom és Jerry 1 (80)cpp17Wrong answer 40/80215ms17444 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]] == -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
base40/80
1Accepted0/03ms1872 KiB
2Wrong answer0/06ms2544 KiB
3Accepted4/43ms2300 KiB
4Accepted4/43ms2508 KiB
5Wrong answer0/43ms2628 KiB
6Accepted4/43ms2868 KiB
7Accepted4/44ms2976 KiB
8Wrong answer0/44ms3356 KiB
9Wrong answer0/46ms3416 KiB
10Accepted4/47ms3752 KiB
11Wrong answer0/417ms4388 KiB
12Accepted4/420ms5460 KiB
13Accepted4/443ms6948 KiB
14Wrong answer0/490ms10248 KiB
15Wrong answer0/496ms9620 KiB
16Accepted4/4135ms17136 KiB
17Accepted4/4215ms17444 KiB
18Wrong answer0/4112ms12848 KiB
19Wrong answer0/4145ms16504 KiB
20Wrong answer0/4141ms15968 KiB
21Accepted4/4114ms10700 KiB
22Wrong answer0/4196ms15416 KiB