Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
144377 | 陈家宝 | 人际关系 | C++ | 通过 | 100 | 1 MS | 256 KB | 537 | 2024-04-23 13:07:08 |
#include<bits/stdc++.h> using namespace std; bool f[101][101],flag[101]; struct P{ int id,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; }