31072023-02-15 18:15:36horvathabelTom és Jerry 1 (80)cpp17Accepted 80/80114ms17048 KiB
#include <bits/stdc++.h>
using namespace std;
int maxn=100001;
vector<pair<int,int>> g[100001];
vector<int> tomt(maxn); 
void bfst(int t){
	bool seen[maxn];
	tomt[t]=0; 
	queue<int> q; 
	q.push(t);
	seen[t]=true; 

	while (!q.empty()){
		int v=q.front();
		q.pop();
		for (auto edge:g[v]){
			if (edge.second==2 && !seen[edge.first]){
				tomt[edge.first]=tomt[v]+1;
				seen[edge.first]=true; 
				q.push(edge.first);
			} 
		}
	}
	tomt[t]=-1;
} 
vector<int> tavok(maxn);
void bfse(int e){
	vector<bool> seen;
	seen.assign(maxn, 0); 
	tavok[e]=maxn; 
	priority_queue<pair<int,int>> q;
	q.push({tavok[e],e});
	seen[e]=true; 
	while (!q.empty()){
		int v=q.top().second; 
		q.pop();
		for (auto edge:g[v]){
			if (!seen[edge.first]){
			if (tomt[edge.first]==0) tavok[edge.first]=tavok[v]-1;


			else{
				tavok[edge.first]=min(tomt[edge.first]-1, tavok[v]-1);
			}
				q.push({tavok[edge.first],edge.first});
				seen[edge.first]=true; 	
			
				
		
		}
	}
}	
}
int main() {
	int n,m,t,j,e;
	cin>>n>>m>>t>>j>>e; 	
	for (int i=0; i<m;i++){
		int x,y,z;
		cin>>x>>y>>z;
		g[x].push_back(make_pair(y,z));
		g[y].push_back(make_pair(x,z));
	}
	bfst(t);
	bfse(e);
	for (int i=0; i<j;i++){
		int x; 
		cin >>x;
		if (tavok[x]>=0 && x!=t) cout<<"IGEN"<<endl; 
		else cout<<"NEM"<<endl; 
	}
}
SubtaskSumTestVerdictTimeMemory
base80/80
1Accepted0/06ms7900 KiB
2Accepted0/07ms8560 KiB
3Accepted4/44ms8448 KiB
4Accepted4/46ms8660 KiB
5Accepted4/44ms8616 KiB
6Accepted4/44ms8948 KiB
7Accepted4/46ms9164 KiB
8Accepted4/46ms9160 KiB
9Accepted4/47ms9408 KiB
10Accepted4/48ms9548 KiB
11Accepted4/414ms10276 KiB
12Accepted4/417ms10776 KiB
13Accepted4/426ms11512 KiB
14Accepted4/448ms13168 KiB
15Accepted4/467ms14144 KiB
16Accepted4/472ms14468 KiB
17Accepted4/4101ms16212 KiB
18Accepted4/468ms14368 KiB
19Accepted4/493ms14184 KiB
20Accepted4/478ms14168 KiB
21Accepted4/471ms13964 KiB
22Accepted4/4114ms17048 KiB