UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#212721#3829. Czhouzhichen123456Compile Error//C++615b2024-10-20 10:08:172024-10-20 12:39:38

answer

#include <iostream>
#include <vector>

int dfs(int node, int depth, std::vector<std::vector<int>>& tree) {
    if (tree[node].empty()) return depth;
    int total_depth = 0;
    for (int child : tree[node]) {
        total_depth += dfs(child, depth + 1, tree);
    }
    return total_depth;
}

int main() {
    int n;
    std::cin >> n;
    std::vector<std::vector<int>> tree(n + 1);
    for (int i = 0; i < n - 1; ++i) {
        int x, y;
        std::cin >> x >> y;
        tree[x].push_back(y);
    }
    int result = dfs(1, 0, tree);
    std::cout << result << std::endl;
    return 0;
}

详细

answer.code:4:57: error: '>>' should be '> >' within a nested template argument list
 int dfs(int node, int depth, std::vector<std::vector<int>>& tree) {\x0d
                                                         ^
answer.code: In function 'int dfs(int, int, std::vector<std::vector<int> >&)':
answer.code:7:22: error: range-based 'for' loops are not allowed in C++98 mode
     for (int child : tree[node]) {\x0d
                      ^
answer.code: In function 'int main()':
answer.code:16:32: error: '>...