Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- vector <int> v[10010];
- int k,n,m;
- int mx=-2e9;
- bool check[10010];
- queue <int> q;
- int dist[10010];
- void tower(int k){
- q.push(1);
- dist[1]=0;
- check[1]=1;
- while(!q.empty()){
- int qf=q.front();
- if(dist[qf]<=k){
- mx=max(qf,mx);
- }
- q.pop();
- for(auto x:v[qf]){
- if(!check[x]){
- q.push(x);
- dist[x]=dist[qf]+1;
- check[x]=1;
- }
- }
- }
- }
- int main()
- {
- scanf("%d%d%d",&k,&n,&m);
- int a,b;
- for(int i=0;i<m;++i){
- scanf("%d%d",&a,&b);
- v[a].push_back(b);
- }
- tower(k);
- printf("%d",mx);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement