#include <iostream>
using namespace std;
struct node{
int value;
node * next;
node(int v, node * n = NULL){
value = v;
next = n;
}
};
struct queue{ // Структура очередь
node * start;
node * finish;
int len = 0;
queue(node * s = NULL, node * f = NULL){
start = s;
finish = f;
}
string push(int n){
if(len == 0){
node * new_node = new node(n,finish);
start = new_node;
finish = new_node;
}else{
node * new_node = new node(n,NULL);
start -> next = new_node;
start = new_node;
}
len++;
return "ok";
}
int pop(){
int v = finish -> value;
finish = finish -> next;
len--;
return v;
}
int front(){
return finish -> value;
}
int size(){
return len;
}
};
int main() {
int n, s, f;
cin >> n >> s >> f;
int graph[n][n];
int dist[n]; // Массив расстояний от начальной до i-ой вершины
bool used[n];
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
cin >> graph[i][j];
}
}
for(int i = 0; i < n; i++){
dist[i] = 0;
used[i] = false;
}
queue vertex; // Очередь вершин
vertex.push(s-1);
used[s-1] = true;
while(vertex.size() != 0){
int v = vertex.front();
for(int i = 0; i < n; i++){
if(graph[v][i] == 1 && used[i] == false){
vertex.push(i);
dist[i] = dist[v] + 1;
used[i] = true; // i-ая вершина пройдена и не будет корректироваться позже
}
}
used[v] = true;
vertex.pop();
}
cout << dist[f-1];
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKc3RydWN0IG5vZGV7CglpbnQgdmFsdWU7Cglub2RlICogbmV4dDsKCW5vZGUoaW50IHYsIG5vZGUgKiBuID0gTlVMTCl7CgkJdmFsdWUgPSB2OwoJCW5leHQgPSBuOwoJfQp9OwogCnN0cnVjdCBxdWV1ZXsgLy8g0KHRgtGA0YPQutGC0YPRgNCwINC+0YfQtdGA0LXQtNGMCglub2RlICogc3RhcnQ7Cglub2RlICogZmluaXNoOwoJaW50IGxlbiA9IDA7CglxdWV1ZShub2RlICogcyA9IE5VTEwsIG5vZGUgKiBmID0gTlVMTCl7CgkJc3RhcnQgPSBzOwoJCWZpbmlzaCA9IGY7Cgl9C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