Language: C++

#include <vector>
#include <set>
using namespace std;

int main(){
    int N, M, Z;
    while(cin >> N >> M >> Z && N>0){
        pair<int, int> edges[2 * M];
        for(int i = 0; i < M; ++i){
            int s, d;
            cin >> s >> d;
            edges[2*i] = make_pair(s-1, d-1);
            edges[2*i+1] = make_pair(d-1, s-1);
        }
        vector<pair<int, int> > before;
        for(int i = 0; i < 2*M; ++i){
            if(edges[i].first == 0){
                before.push_back(edges[i]);
            }
        }
        for(int k = 0; k < Z-1; ++k){
            vector<pair<int, int> > after;
            for(int i = 0; i < before.size(); i++){
                for(int j = 0; j < 2*M; j++){
                    if(edges[j].first == before[i].second && edges[j].second != before[i].first){
                        after.push_back(edges[j]);
                        //cout << edges[j].first << ", " << edges[j].second << endl;
                    }
                    
                }
            }
            before.swap(after);
        }
        if(before.size() == 0){
            cout << "no" << endl;
        }
        for(int i = 0; i < before.size(); i++){
            if(before[i].second == N-1){
                cout << "yes" << endl;
                break;
            }
            if(i == before.size()-1){
                cout << "no" << endl;
            }
        }

    }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:7:11: error: 'cin' was not declared in this scope
    7 |     while(cin >> N >> M >> Z && N>0){
      |           ^~~
a.cc:3:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
    2 | #include <set>
  +++ |+#include <iostream>
    3 | using namespace std;
a.cc:35:13: error: 'cout' was not declared in this scope
   35 |             cout << "no" << endl;
      |             ^~~~
a.cc:35:13: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:35:29: error: 'endl' was not declared in this scope
   35 |             cout << "no" << endl;
      |                             ^~~~
a.cc:3:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
    2 | #include <set>
  +++ |+#include <ostream>
    3 | using namespace std;
a.cc:39:17: error: 'cout' was not declared in this scope
   39 |                 cout << "yes" << endl;
      |                 ^~~~
a.cc:39:17: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:39:34: error: 'endl' was not declared in this scope
   39 |                 cout << "yes" << endl;
      |                                  ^~~~
a.cc:39:34: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
a.cc:43:17: error: 'cout' was not declared in this scope
   43 |                 cout << "no" << endl;
      |                 ^~~~
a.cc:43:17: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:43:33: error: 'endl' was not declared in this scope
   43 |                 cout << "no" << endl;
      |                                 ^~~~
a.cc:43:33: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'