Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
99660 modongtao 树的深度 C++ 通过 100 0 MS 260 KB 558 2023-08-23 14:51:56

Tests(8/8):


#include <bits/stdc++.h> using namespace std; int tree[10005][2]; int depth[10005]; int main() { int n, m=0; cin >> n; for (int i = 1; i <= n; i++) { cin >> tree[i][0] >> tree[i][1]; } queue<int> q; q.push(1); depth[1] = 1; while (!q.empty()) { int x = q.front(); q.pop(); m = max(m, depth[x]); if (tree[x][0] != 0) { depth[tree[x][0]] = depth[x] + 1; q.push(tree[x][0]); } if (tree[x][1] != 0) { depth[tree[x][1]] = depth[x] + 1; q.push(tree[x][1]); } } cout << m << endl; return 0; }


测评信息: