29422023-02-04 18:05:29horvathabelTom és Jerry 1 (80)cpp17Time limit exceeded 64/80600ms16176 KiB

#include <bits/stdc++.h>
using namespace std;
vector<pair<int,int>> g[100001];
int tomtav[100001];
vector<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); 
	p[x]=-1;
	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 jerrytav[e]; 

	else{
		int z=p[e]; 
		while (z!=x){
			mego[z]=true;
			z=p[z];
		}
	}
	return 1; 
}
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 (z==e) cout<<"IGEN"<<endl;
		else{
			
			if (bfsj(z,e)==0) cout<<"NEM"<<endl;
			else{
				 cout<<"IGEN"<<endl; 
				for (int i=0; i<n;i++){

				}
			}
		}
	}
}
SubtaskSumTestVerdictTimeMemory
base64/80
1Accepted0/06ms8360 KiB
2Accepted0/08ms8728 KiB
3Accepted4/48ms8872 KiB
4Accepted4/48ms9224 KiB
5Accepted4/48ms9360 KiB
6Accepted4/48ms9568 KiB
7Accepted4/48ms9796 KiB
8Accepted4/48ms10020 KiB
9Accepted4/48ms10024 KiB
10Accepted4/47ms10240 KiB
11Accepted4/412ms10764 KiB
12Accepted4/413ms11256 KiB
13Accepted4/419ms11596 KiB
14Accepted4/429ms13108 KiB
15Accepted4/446ms14244 KiB
16Accepted4/445ms14964 KiB
17Accepted4/464ms16176 KiB
18Accepted4/443ms14476 KiB
19Time limit exceeded0/4563ms9244 KiB
20Time limit exceeded0/4600ms9148 KiB
21Time limit exceeded0/4547ms9056 KiB
22Time limit exceeded0/4569ms10660 KiB