Submission #698789

# Submission time Handle Problem Language Result Execution time Memory
698789 2023-02-14T09:59:46 Z vjudge1 Duathlon (APIO18_duathlon) C++17
0 / 100
526 ms 1048576 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define endl '\n'

const int M = 1e4+5, K = 4e2+2, MOD = 1e9+7;
vector<int> node[M];
int d[M], noc[M], n, dp[M];

void dfs(int s, int p = 1) {
    noc[s]++;
    for (int i:node[s]) {
        if (i != p) {
            d[i] = d[s]+1;
            dfs(i, s);
            noc[s] += noc[i];
        }
    }
}

void dfs2(int s, int p = 1) {
    for (int i:node[s]) {
        if (i != p) {
            dp[i] = dp[s] + n - 2*noc[i];
            dfs2(i, s);
        }
    }
}

signed main() {
    cin.tie(0)->sync_with_stdio(0);

    int m;
    cin >> n >> m;

    for (int i = 1; i <= m; i++) {
        int a, b;
        cin >> a >> b;
        node[a].push_back(b);
        node[b].push_back(a);
    } dfs(1);
    for (int i = 1; i <= n; i++) dp[1] += d[i];

    dfs2(1);
    int ans = 0;
    for (int i = 1; i <= n; i++) ans += dp[i] - n + 1;
    // for (int i = 1; i <= n; i++) cout << dp[i] << ' '; cout << endl;
    cout << ans << endl;

    return 0;
}
/*
4 3
1 2 2 3 3 4
*/
# Verdict Execution time Memory Grader output
1 Runtime error 437 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 437 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 956 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Incorrect 1 ms 596 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 852 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Runtime error 526 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 852 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 437 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 437 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -