29322023-02-04 17:06:19horvathabelTom és Jerry 1 (80)cpp17Time limit exceeded 64/80574ms14688 KiB

#include <bits/stdc++.h>
using namespace std;
vector<pair<int,int>> g[100001];
int tomtav[100001];
vector<int> jerrytav;
int t,n;
vector<bool> seenn;

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){
	
	queue<int> q; 
	q.push(x); 
	seenn[x]=true; 
	while (!q.empty()){
		int v=q.front();
		q.pop();
		
		for (pair<int, int> edge: g[v]){
			if (!seenn[edge.first]){
				if ( tomtav[edge.first]==0){
					jerrytav[edge.first]=jerrytav[v]+1;
					q.push(edge.first);
					seenn[edge.first]=true; 
			}
				else if(tomtav[edge.first]>jerrytav[v]+1){
					
					jerrytav[edge.first]=jerrytav[v]+1;
					q.push(edge.first);
					seenn[edge.first]=true; 
				}
			}
		} 
	}

}
int main() {
	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);
		seenn.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(); 
		seenn.clear();
	}
}
SubtaskSumTestVerdictTimeMemory
base64/80
1Accepted0/04ms6688 KiB
2Accepted0/07ms7112 KiB
3Accepted4/44ms7092 KiB
4Accepted4/44ms7304 KiB
5Accepted4/44ms7384 KiB
6Accepted4/44ms7524 KiB
7Accepted4/44ms7876 KiB
8Accepted4/46ms8124 KiB
9Accepted4/47ms8352 KiB
10Accepted4/47ms8588 KiB
11Accepted4/414ms9336 KiB
12Accepted4/417ms9720 KiB
13Accepted4/427ms10132 KiB
14Accepted4/446ms11608 KiB
15Accepted4/474ms12620 KiB
16Accepted4/475ms13320 KiB
17Accepted4/4115ms14688 KiB
18Accepted4/471ms13076 KiB
19Time limit exceeded0/4574ms7940 KiB
20Time limit exceeded0/4574ms8008 KiB
21Time limit exceeded0/4566ms8016 KiB
22Time limit exceeded0/4568ms9188 KiB