提交时间:2024-01-21 22:05:14
运行 ID: 121528
# include <bits/stdc++.h> using namespace std ; bool flg [105] [105] ; bool vst [105] ; int mn = 114514 ; int n , a , b ; void dfs ( int x , int cnt ) { if ( x == b ) { mn = min ( mn , cnt ) ; return ; } for ( int i = 1 ; i <= n ; i ++ ) { if ( ! vst [i] and flg [x] [i] ) { if ( i != b ) { dfs ( i , cnt + 1 ) ; } else { dfs ( i , cnt ) ; } } } } 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 ; }