提交时间:2024-01-21 22:06:59
运行 ID: 121529
# include <bits/stdc++.h> using namespace std ; bool flg [105] [105] ; bool vst [105] ; int mn = 114514 , n , a , b ; void dfs ( int x , int cnt ) { if ( x == b ) { mn = min ( mn , cnt - 1 ) ; return ; } for ( int i = 1 ; i <= n ; i ++ ) { if ( ! vst [i] and flg [x] [i] ) { vst [i] = true ; dfs ( i , cnt + 1 ) ; vst [i] = false ; } } } int main ( ) { cin >> n >> a >> b ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= n ; j ++ ) { cin >> flg [i] [j] ; } } vst [a] = true ; dfs ( a , 0 ) ; cout << mn << endl ; return 0 ; }