#include #include #include #include using namespace std; int main() { int n; cin >> n; vector> M(n, vector(n)); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> M[i][j]; } } int u, v; cin >> u >> v; u--; v--; if (u == v) { cout << 0; return 0; } vector colors(n); vector parents(n); vector length(n); queue q; q.push(v); colors[v] = 1; parents[v] = v; length[v] = 0; while (q.size() > 0) { int t = q.front(); q.pop(); colors[t] = 2; for (int j = 0; j < n; j++) { if (M[t][j] == 1 && colors[j] == 0) { q.push(j); colors[j] = 1; parents[j] = t; length[j] = length[t] + 1; } } } if (colors[u] == 0) { cout << -1; return 0; } cout << length[u] << '\n'; int t = u; cout << t + 1 << ' '; while (t != v) { t = parents[t]; cout << t + 1 << ' '; } return 0; }