Submission #745798

# Submission time Handle Problem Language Result Execution time Memory
745798 2023-05-21T07:59:03 Z vjudge1 Event Hopping (BOI22_events) C++17
0 / 100
74 ms 25016 KB
#include <bits/stdc++.h>
using namespace std;
map<int, vector<int>> g; 
int n,q;
int bfs(int x, int cel){
	queue<int> q;
	q.push(x);
	vector<int> tav; 
	tav.assign(n+1, -1); 
	tav[x]=0; 
	while (!q.empty()){
		int v=q.front();
		q.pop();
		for (int edge:g[v]){
			if (edge==cel){
				tav[edge]=tav[v]+1;
				return tav[edge];
			}
			tav[edge]=tav[v]+1; 
			q.push(edge);
		}
	}
	return -1;
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n>>q;
	vector<pair<int, int>> idopontok; 
	for (int i=0; i<n;i++){
		int a,b;
		cin>>a>>b;
		g[a].push_back(b);
		idopontok.push_back(make_pair(a,b));
	}
	for (int t=0; t<q;t++){
		int x,y;
		cin>>x>>y;
		x--;
		y--;
		int cel=idopontok[y].second;
		int mego=bfs(idopontok[x].second, cel);
		if (mego!=-1){
			cout<<mego<<endl;
			
		}
		else cout<<"IMPOSSIBLE"<<endl; 
		
	}
}
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 74 ms 25016 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -