UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#214261#2763. 幻想乡的拜访KXGCompile Error//C++994b2024-11-16 20:59:342024-11-16 23:13:14

answer

#include <cstdio>
#include <vector>
using namespace std;
const int mod = 1e9 + 7;
int n, u, v;
vector<int> G[1000010];
long long dp1[1000010], dp2[1000010], siz[1000010];
void dfs(int u, int fa) {
    siz[u] = u;
    for (int v : G[u]) {
        if (v == fa) continue;
        dfs(v, u);
        siz[u] += siz[v];
        dp1[u] += dp1[v] + siz[v];
    }
}
void dfs2(int u, int fa) {
    for (int v : G[u]) {
        if (v == fa) continue;
        dp2[v] = dp2[u] - siz[v] + (siz[1] - siz[v]);
        dfs2(v, u);
    }
}
int main() {
    scanf("%d", &n);
    for (int i = 1; i < n; i++) {
        scanf("%d%d", &u, &v);
        G[u].push_back(v);
        G[v].push_back(u);
    }
    dfs(1, -1);
    dp2[1] = dp1[1];
    dfs2(1, -1);
    long long ans = 0;
    for (int i = 1; i <= n; i++) {
        dp2[i] %= mod;
        ans += i * dp2[i] % mod;
    }
    ans %= mod;
    ans = ans * ((mod + 1) / 2) % mod;
    printf("%lld\n", ans);
    return 0;
}

详细

answer.code: In function 'void dfs(int, int)':
answer.code:10:18: error: range-based 'for' loops are not allowed in C++98 mode
     for (int v : G[u]) {\x0d
                  ^
answer.code: In function 'void dfs2(int, int)':
answer.code:18:18: error: range-based 'for' loops are not allowed in C++98 mode
     for (int v : G[u]) {\x0d
                  ^
answer.code: In function 'int main()':
answer.code:25:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn...