题解 100% AC
2025-08-12 09:34:01
发布于:江苏
5阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
int a[105][105];
int b[105];
queue<int> q;
queue<int> s;
int main(){
int n,x,y;
cin>>n>>x>>y;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
cin>>a[i][j];
b[x]=1;
q.push(x);
s.push(0);
while(!q.empty()){
for(int j=1;j<=n;j++){
if(a[q.front()][j]!=0&&!b[j]){
q.push(j);
s.push(s.front()+1);
if(j==y){
cout<<s.front();
return 0;
}
b[j]=1;
}
}
q.pop();
s.pop();
}
return 0;
}
这里空空如也
有帮助,赞一个