81932024-01-12 17:46:54GervidTom és Jerry 1 (80)cpp17Time limit exceeded 64/80578ms19732 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();
	}

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

		q.push(jstart);
		q.push(-1);

		int distance = 1;

		set<int> been;
		been.insert(jstart);
		
		while (q.size() > 1)
		{
			if (q.front() == -1)
			{
				distance++;
				q.pop(), q.push(-1);

				continue;
			}

			if (q.front() == hole)
			{
				q = {};
				cout << "IGEN" << endl;
				break;
			}

			for (i = 0; i < jg[q.front()].size(); i++)
			{
				if (!been.count(jg[q.front()][i]) && distance < tdist[jg[q.front()][i]])
				{
					been.insert(jg[q.front()][i]);
					q.push(jg[q.front()][i]);
				}
			}

			q.pop();
		}

		if (q.size() > 0)
		{
			q = {};
			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
base64/80
1Accepted0/03ms1876 KiB
2Accepted0/07ms2504 KiB
3Accepted4/43ms2152 KiB
4Accepted4/43ms2292 KiB
5Accepted4/43ms2508 KiB
6Accepted4/43ms2720 KiB
7Accepted4/44ms3000 KiB
8Accepted4/47ms3256 KiB
9Accepted4/47ms3472 KiB
10Accepted4/48ms4036 KiB
11Accepted4/420ms4588 KiB
12Accepted4/435ms6044 KiB
13Accepted4/461ms7692 KiB
14Accepted4/4104ms10292 KiB
15Accepted4/4126ms10420 KiB
16Accepted4/4217ms19732 KiB
17Accepted4/4372ms18464 KiB
18Accepted4/4143ms13968 KiB
19Time limit exceeded0/4555ms10820 KiB
20Time limit exceeded0/4566ms10628 KiB
21Time limit exceeded0/4542ms8324 KiB
22Time limit exceeded0/4578ms9760 KiB