29352023-02-04 17:11:16horvathabelTom és Jerry 1 (80)cpp17Time limit exceeded 64/80573ms14692 KiB

#include <bits/stdc++.h>
using namespace std;
vector<pair<int,int>> g[100001];
int tomtav[100001];
vector<int> jerrytav;
int t,n;
void bfstom(int x){
	bool seen[100001];

	tomtav[x]=0; 
	seen[x]=true; 
	queue<int> q;
	q.push(x);
	while (!q.empty()){
		int v=q.front();
		q.pop();
		
		for (pair<int, int> edge:g[v]){
			if (edge.second==2 && !seen[edge.first]){
				tomtav[edge.first]=tomtav[v]+1;
				q.push(edge.first);
				seen[edge.first]=true;  
			}
		}
	}
}
void bfsj(int x){
	vector<bool> seen(100001); 
	queue<int> q; 
	q.push(x); 
	seen[x]=true; 
	while (!q.empty()){
		int v=q.front();
		q.pop();
		
		for (pair<int, int> edge: g[v]){
			if (!seen[edge.first]){
				if ( tomtav[edge.first]==0 || tomtav[edge.first]>jerrytav[v]+1){
					jerrytav[edge.first]=jerrytav[v]+1;
					q.push(edge.first);
					seen[edge.first]=true; 
			}
				
			}
		} 
	}

}
int main() {
	ios::sync_with_stdio(false);
  	cin.tie(0);
	int n, m,t,jt,e;
	cin>>n>>m>>t>>jt>>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));
	}
	bfstom(t);
	tomtav[t]=-1; 
	
	for (int i=0; i<jt;i++){
		int z; 
		cin>>z;
		jerrytav.assign(n+1, 0);

		bfsj(z);
		
		if (z==e) cout<<"IGEN"<<endl;
		else{
			for (int i=1; i<=n;i++){
			}
			if (jerrytav[e]==0) cout<<"NEM"<<endl;
			else cout<<"IGEN"<<endl; 
		}
		jerrytav.clear(); 
	}
}
SubtaskSumTestVerdictTimeMemory
base64/80
1Accepted0/04ms6716 KiB
2Accepted0/06ms7268 KiB
3Accepted4/44ms7444 KiB
4Accepted4/44ms7432 KiB
5Accepted4/44ms7664 KiB
6Accepted4/44ms7884 KiB
7Accepted4/44ms8224 KiB
8Accepted4/44ms8256 KiB
9Accepted4/46ms8384 KiB
10Accepted4/46ms8420 KiB
11Accepted4/48ms8904 KiB
12Accepted4/412ms9400 KiB
13Accepted4/417ms9972 KiB
14Accepted4/425ms11608 KiB
15Accepted4/443ms12548 KiB
16Accepted4/443ms13616 KiB
17Accepted4/463ms14692 KiB
18Accepted4/439ms12904 KiB
19Time limit exceeded0/4572ms7812 KiB
20Time limit exceeded0/4569ms8076 KiB
21Time limit exceeded0/4573ms7996 KiB
22Time limit exceeded0/4564ms9148 KiB