29412023-02-04 17:59:02horvathabelTom és Jerry 1 (80)cpp17Runtime error 0/8050ms17000 KiB

#include <bits/stdc++.h>
using namespace std;
vector<pair<int,int>> g[100001];
int tomtav[100001];
bool mego[100001];
int t,n,e;
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;  
			}
		}
	}
}
int bfsj(int x, int e){
	vector<bool> seen(100001); 
	vector<int> jerrytav(100001); 
	vector<int> p(100001); 
	jerrytav[x]=0;
	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);
					p[edge.first]=v;
					seen[edge.first]=true; 
			}
				
			}
		} 
	}
	if (jerrytav[e]==0) return 0;
	else{
		int z=p[e]; 
		while (z!=x){
			mego[z]=true;
			z=p[z];
		}
	}
}
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;

		
		if (mego[z]) cout<<"IGEN"<<endl;
		else{
			
			if (bfsj(z,e)==0) cout<<"NEM"<<endl;
			else{
				 cout<<"IGEN"<<endl; 
				for (int i=0; i<n;i++){

				}
			}
		}
	}
}
SubtaskSumTestVerdictTimeMemory
base0/80
1Runtime error0/06ms8360 KiB
2Runtime error0/07ms8556 KiB
3Runtime error0/46ms8768 KiB
4Runtime error0/46ms8936 KiB
5Runtime error0/44ms9216 KiB
6Runtime error0/46ms9272 KiB
7Runtime error0/46ms9532 KiB
8Runtime error0/46ms9612 KiB
9Runtime error0/46ms9844 KiB
10Runtime error0/46ms10248 KiB
11Runtime error0/48ms10692 KiB
12Runtime error0/49ms11032 KiB
13Runtime error0/414ms11672 KiB
14Runtime error0/423ms13348 KiB
15Runtime error0/429ms14572 KiB
16Runtime error0/430ms15128 KiB
17Runtime error0/450ms16444 KiB
18Runtime error0/429ms14476 KiB
19Runtime error0/429ms14476 KiB
20Runtime error0/428ms14784 KiB
21Runtime error0/425ms14272 KiB
22Runtime error0/445ms17000 KiB