Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
121153 | 李树强 | 人际关系 | C++ | 运行超时 | 70 | 2024 MS | 264 KB | 564 | 2024-01-21 15:35:12 |
#include<iostream> #include<vector> using namespace std; const int N = 110; int n, a, b, t, ans = 1e9; bool vis[N]; vector<int> vec[N]; void dfs(int x, int cnt = 0){ if(vis[x]) return; if(x == b){ ans = min(ans, cnt - 1); return; } vis[x] = true; for(int i = 0; i < vec[x].size(); i++){ dfs(vec[x][i], cnt + 1); } vis[x] = false; } int main(){ cin >> n >> a >> b; for(int i = 1; i <= n; i++){ for(int j = 1; j <= n; j++){ cin >> t; if(t) vec[i].push_back(j); } } dfs(a); cout << ans; return 0; }