SHARE
TWEET

Untitled

a guest Jan 18th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. vector <int> v[10010];
  5. int k,n,m;
  6. int mx=-2e9;
  7. bool check[10010];
  8. queue <int> q;
  9. int dist[10010];
  10. void tower(int k){
  11.     q.push(1);
  12.     dist[1]=0;
  13.     check[1]=1;
  14.     while(!q.empty()){
  15.         int qf=q.front();
  16.         if(dist[qf]<=k){
  17.             mx=max(qf,mx);
  18.         }
  19.         q.pop();
  20.         for(auto x:v[qf]){
  21.             if(!check[x]){
  22.                 q.push(x);
  23.                 dist[x]=dist[qf]+1;
  24.                 check[x]=1;
  25.             }
  26.         }
  27.     }
  28. }
  29.  
  30. int main()
  31. {
  32.  
  33.     scanf("%d%d%d",&k,&n,&m);
  34.     int a,b;
  35.     for(int i=0;i<m;++i){
  36.         scanf("%d%d",&a,&b);
  37.         v[a].push_back(b);
  38.     }
  39.     tower(k);
  40.     printf("%d",mx);
  41.     return 0;
  42. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top