Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
142403 | 谢思涵 | 人际关系 | C++ | 通过 | 100 | 1 MS | 304 KB | 648 | 2024-04-07 20:56:15 |
#include <iostream> #include <queue> using namespace std; int a[110][110], n, x, y; bool flag[110]; struct point{int id, step;}; queue <point> q; void bfs() { while(!q.empty()) { point t = q.front(); q.pop(); int tid = t.id, tstep = t.step; if(tid == y) { cout << tstep - 1 << endl; return; } for(int i = 1; i <= n; i++) { if(a[tid][i] && !flag[i]) { flag[i] = true; q.push({i, tstep + 1}); } } } } int main() { cin >> n >> x >> y; for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) cin >> a[i][j]; q.push({x, 0}); flag[x] = true; bfs(); return 0; }