提交时间:2024-08-21 17:23:54
运行 ID: 180699
#include<iostream> using namespace std; const int INF = 0x3f3f3f3f; int a[110][110]; int main(){ int n,A,B,t; cin>>n>>A>>B; for(int i = 1; i <= n; i++){ for(int j = 1; j <= n; j++){ cin>>t; if(t == 0){ a[i][j] = INF; }else{ a[i][j] = 1; } } } for(int k = 1; k <= n; k++){ for(int i = 1; i <= n; i++){ for(int j = 1; j <= n; j++){ a[i][j] = min(a[i][j],a[i][k]+a[k][j]); } } } cout<<a[A][B]-1; return 0; }