29312023-02-04 16:45:14horvathabelTom és Jerry 1 (80)cpp17Wrong answer 4/80103ms15552 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();
		seen[v]=true; 
		for (pair<int, int> edge:g[v]){
			if (edge.second==2 && !seen[edge.first]){
				tomtav[edge.first]=tomtav[v]+1;
				q.push(edge.first); 
			}
		}
	}
}
void bfsj(int x){
	
	queue<int> q; 
	q.push(x); 
	vector<bool> seen;
	seen.assign(n+1, false); 
	seen[x]=true; 
	while (!q.empty()){
		int v=q.front();
		q.pop();
		seen[v]=true; 
		for (pair<int, int> edge: g[v]){

			if (!seen[edge.first] && edge.first!=t){
				if ( tomtav[edge.first]==0 || tomtav[edge.first]>jerrytav[v]+1){
					jerrytav[edge.first]=jerrytav[v]+1;
					q.push(edge.first);
			}
			}
		} 
	}
	seen.clear(); 
}
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); 
		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
base4/80
1Wrong answer0/04ms6684 KiB
2Runtime error0/07ms7188 KiB
3Wrong answer0/44ms7024 KiB
4Accepted4/44ms7064 KiB
5Wrong answer0/44ms7292 KiB
6Wrong answer0/44ms7524 KiB
7Runtime error0/44ms7980 KiB
8Runtime error0/46ms8476 KiB
9Runtime error0/46ms8296 KiB
10Runtime error0/46ms8424 KiB
11Runtime error0/414ms9148 KiB
12Runtime error0/416ms9472 KiB
13Runtime error0/424ms9896 KiB
14Runtime error0/445ms11340 KiB
15Runtime error0/464ms12388 KiB
16Runtime error0/461ms13492 KiB
17Runtime error0/4103ms14796 KiB
18Runtime error0/459ms12880 KiB
19Runtime error0/461ms13156 KiB
20Runtime error0/454ms13196 KiB
21Runtime error0/452ms12680 KiB
22Runtime error0/497ms15552 KiB