35592023-02-28 22:23:44SleepyOverlordTom és Jerry 1 (80)cpp17Elfogadva 80/80109ms11708 KiB
#include <vector>
#include <string> 
#include <set> 
#include <map> 
#include <unordered_set>
#include <unordered_map>
#include <queue> 
#include <bitset> 
#include <stack>
#include <list>

#include <numeric> 
#include <algorithm> 
#include <random>
#include <chrono>

#include <cstdio>
#include <fstream>
#include <iostream> 
#include <sstream> 
#include <iomanip>
#include <climits>

#include <cctype>
#include <cmath> 
#include <ctime>
#include <cassert>

using namespace std;

#define ULL unsigned long long
#define LL long long
#define PII pair <int, int>
#define VB vector <bool>
#define VI vector <int>
#define VLL vector <LL>
#define VD vector <double>
#define VS vector <string>
#define VPII vector <pair <int, int> >
#define VVI vector < VI >
#define VVB vector < VB >
#define SI set < int >
#define USI unordered_set <int>
#define MII map <int, int>
#define UMII unordered_map <int, int>
#define MS multiset
#define US unordered_set
#define UM unordered_map
#define UMS unordered_multiset
#define UMM unordered_multimap

#define FORN(i, n) for(int i = 0; i < (n); ++i)
#define FOR(i, a, b) for(int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)

#define SZ size()
#define BG begin() 
#define EN end() 
#define CL clear()
#define X first
#define Y second
#define RS resize
#define PB push_back
#define MP make_pair
#define ALL(x) x.begin(), x.end()
#define INS insert
#define ER erase
#define CNT count

#define IN_FILE "a.in"
#define OUT_FILE "a.out"

template <typename T>
void PR(T var1)
{
	cout << var1 <<endl;
}
template <typename T, typename... Types>
void PR(T var1, Types... var2)
{
	cout << var1;
	PR(var2...);
}

#define INF 2000000000

int n, m, t, p, e;
vector <VPII> g;
VI d, latest;

void bf(int source)
{
	d[source] = 0;
	queue<int> fifo;
	fifo.push(source);
	while (!fifo.empty())
	{
		int node = fifo.front();
		fifo.pop();
		for (auto it : g[node])
			if (d[it.X] == -1 && it.Y == 2)
			{
				d[it.X] = d[node] + 1;
				fifo.push(it.X);
			}
	}
}

void bf2(int source)
{
	//latest[i] - legkesobbi idopillanat amikor elindulhatok i-bol, 
	//		  	  hogy elerjem az egerlyukat
	//-1 - meg nem tudom
	//-2 - lehetetlen
	//INF - barmikor
	if (d[source] == -1) latest[source] = INF;
	else latest[source] = d[source] ? d[source] - 1 : -2;
	queue<int> fifo;
	fifo.push(source);
	while (!fifo.empty())
	{
		int node = fifo.front();
		fifo.pop();
		for (auto it : g[node])
		{
			if (latest[it.X] == INF) continue;
			if (latest[it.X] == -1)
			{
				fifo.push(it.X);
				if (latest[node] == -2) 
				{
					latest[it.X] = -2;
					continue;
				}
				if (latest[node] == INF) latest[it.X] = INF;
				else latest[it.X] = latest[node] - 1;
				if (d[it.X] != -1) latest[it.X] = min(latest[it.X], d[it.X] - 1);
				if (latest[it.X] == -1) latest[it.X] = -2;
			}
			else
			{
				if (latest[node] == -2) continue;
				if (d[it.X] != -1)
				{
					int aux = min(d[it.X] - 1, latest[node] - 1);
					if (latest[it.X] < aux)
					{
						latest[it.X] = aux;
						fifo.push(it.X);
					}
					if (latest[it.X] == -1) latest[it.X] = -2;
				}
				else
					if (latest[node] == INF) 
					{
						latest[it.X] = INF;
						fifo.push(it.X);
					}
					else 
						if (latest[it.X] < latest[node] - 1)
						{
							latest[it.X] = latest[node] - 1;
							if (latest[it.X] == -1) latest[it.X] = -2;
							fifo.push(it.X);
						}
					
			}
		}
	}
}

int main()
{
	//freopen(IN_FILE, "r", stdin);
	//freopen(OUT_FILE, "w", stdout);

	cin >> n >> m >> t >> p >> e;
	g.RS(n + 1);
	FOR(i, 1, m)
	{
		int x, y, z;
		cin >> x >> y >> z;
		g[x].PB({y, z});
		g[y].PB({x, z});
	}
	d.RS(n + 1, -1);
	latest.RS(n + 1, -1);
	bf(t);
	bf2(e);
	FOR(i, 1, p)
	{
		int x;
		cin >> x;
		if (latest[x] >= 0) PR("IGEN");
		else PR("NEM");
	}

	return 0;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base80/80
1Elfogadva0/03ms1812 KiB
2Elfogadva0/04ms2284 KiB
3Elfogadva4/43ms2268 KiB
4Elfogadva4/43ms2432 KiB
5Elfogadva4/43ms2644 KiB
6Elfogadva4/43ms2892 KiB
7Elfogadva4/43ms3228 KiB
8Elfogadva4/44ms3612 KiB
9Elfogadva4/44ms3460 KiB
10Elfogadva4/44ms3640 KiB
11Elfogadva4/410ms4228 KiB
12Elfogadva4/414ms5048 KiB
13Elfogadva4/421ms5784 KiB
14Elfogadva4/446ms7552 KiB
15Elfogadva4/464ms8836 KiB
16Elfogadva4/463ms11164 KiB
17Elfogadva4/497ms11316 KiB
18Elfogadva4/464ms9504 KiB
19Elfogadva4/475ms10060 KiB
20Elfogadva4/479ms9732 KiB
21Elfogadva4/478ms8920 KiB
22Elfogadva4/4109ms11708 KiB