#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
using namespace std;
vector<int> L[100001];
int d[100001];
int n, m ,s;
void bfs(int s) {
for(int i = 1; i <= n; i++) {
d[i] = -1;
}
d[s] = 0;
queue<int> q;
q.push(s);
while (!q.empty()) {
int node = q.front();
q.pop();
for (auto vec : L[node]) {
if(d[vec] == -1) {
d[vec] = d[node] + 1;
q.push(vec);
}
}
}
}
int main(){
ifstream input("bfs.in");
ofstream output("bfs.out");
input >> n >> m >> s;
for (int i = 1; i <= m ; i++) {
int a, b;
input >> a >> b;
L[a].push_back(b);
}
}