Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
121507 | 吴悠 | 人际关系 | C++ | 通过 | 100 | 1 MS | 260 KB | 534 | 2024-01-21 21:15:56 |
#include<iostream> #include<queue> using namespace std; bool f[101][101],flag[101]; struct P{ int id; int steps; }; queue<P> q; int main(){ int n,a,b,ans=0;; cin>>n>>a>>b; for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ cin>>f[i][j]; } } q.push({a,0}); flag[a]=true; while(q.empty()==false){ P front=q.front(); if(front.id==b){ cout<<front.steps-1<<endl; exit(0); } q.pop(); for(int i=1;i<=n;i++){ if(f[front.id][i]==true && flag[i]==false){ q.push({i,front.steps+1}); flag[i]=true; } } } return 0; }