#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--; vector colors(n); vector parents(n); queue q; q.push(u); colors[u] = 1; parents[u] = u; 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; } } } if (colors[v] == 0) { cout << -1; return 0; } stack path; path.push(v); int t = v; while (t != u) { t = parents[t]; path.push(t); } cout << path.size() - 1 << '\n'; if (path.size() > 1) { while (path.size() > 0) { cout << path.top() + 1 << ' '; path.pop(); } } return 0; }