Submission #59291

# Submission time Handle Problem Language Result Execution time Memory
59291 2018-07-21T12:05:23 Z gabrielsimoes Duathlon (APIO18_duathlon) C++17
23 / 100
178 ms 22996 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int MAXN = 1e5+10;
const int MAXM = 2e5+10;

int n, m;
vector<int> g[MAXN];
ll sub[MAXN];
bool ok[MAXN];

void dfs0(int cur, int pre) {
    if (ok[cur]) return;
    ok[cur] = 1;
    sub[cur] = 1;
    for (int nx : g[cur]) {
        if (nx != pre) {
            dfs0(nx, cur);
            sub[cur] += sub[nx];
        }
    }
}

ll ans = 0;
void dfs1(int cur, int pre, ll sum = 0) {
    if (ok[cur]) return;
    ok[cur] = 1;
    ans += 2 * sum * (sub[cur]-1);

    // printf("dfs1 %d %lld %lld: ans %lld\n", cur, sum, sub[cur], ans);

    for (int nx : g[cur]) {
        if (nx != pre) {
            ans += (sub[cur]-1-sub[nx]) * sub[nx];
            dfs1(nx, cur, sum + sub[cur] - sub[nx]);
            // printf("dfs1 %d: ans %lld\n", cur, ans);
        }
    }
}

int main() {
    scanf("%d%d", &n, &m);

    for (int i = 0,a,b; i < m; i++) {
        scanf("%d%d", &a, &b);
        g[a].push_back(b);
        g[b].push_back(a);
    }

    for (int i = 0; i < n; i++) dfs0(i, i);
    memset(ok, 0, sizeof(ok));
    for (int i = 0; i < n; i++) dfs1(i, i);

    printf("%lld\n", ans);
}

Compilation message

count_triplets.cpp: In function 'int main()':
count_triplets.cpp:43:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~
count_triplets.cpp:46:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &a, &b);
         ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 2808 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 2808 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 152 ms 14392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 14392 KB Output is correct
2 Correct 7 ms 14392 KB Output is correct
3 Correct 6 ms 14392 KB Output is correct
4 Correct 7 ms 14392 KB Output is correct
5 Correct 5 ms 14392 KB Output is correct
6 Correct 5 ms 14392 KB Output is correct
7 Correct 5 ms 14392 KB Output is correct
8 Correct 7 ms 14392 KB Output is correct
9 Correct 6 ms 14392 KB Output is correct
10 Correct 6 ms 14392 KB Output is correct
11 Correct 6 ms 14392 KB Output is correct
12 Correct 6 ms 14392 KB Output is correct
13 Correct 7 ms 14392 KB Output is correct
14 Correct 7 ms 14392 KB Output is correct
15 Correct 7 ms 14392 KB Output is correct
16 Correct 6 ms 14392 KB Output is correct
17 Correct 6 ms 14392 KB Output is correct
18 Correct 5 ms 14392 KB Output is correct
19 Correct 5 ms 14392 KB Output is correct
20 Correct 5 ms 14392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 178 ms 14392 KB Output is correct
2 Correct 119 ms 14392 KB Output is correct
3 Correct 140 ms 14392 KB Output is correct
4 Correct 122 ms 14392 KB Output is correct
5 Correct 122 ms 14392 KB Output is correct
6 Correct 176 ms 14392 KB Output is correct
7 Correct 134 ms 14392 KB Output is correct
8 Correct 124 ms 14392 KB Output is correct
9 Correct 153 ms 14392 KB Output is correct
10 Correct 133 ms 14392 KB Output is correct
11 Correct 134 ms 14392 KB Output is correct
12 Correct 118 ms 14392 KB Output is correct
13 Correct 168 ms 14392 KB Output is correct
14 Correct 97 ms 14692 KB Output is correct
15 Correct 111 ms 15560 KB Output is correct
16 Correct 56 ms 15560 KB Output is correct
17 Correct 76 ms 18144 KB Output is correct
18 Correct 109 ms 19200 KB Output is correct
19 Correct 81 ms 20496 KB Output is correct
20 Correct 90 ms 21808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 21808 KB Output is correct
2 Correct 6 ms 21808 KB Output is correct
3 Incorrect 5 ms 21808 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 108 ms 21808 KB Output is correct
2 Correct 117 ms 21808 KB Output is correct
3 Incorrect 142 ms 22996 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 2808 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 2808 KB Output isn't correct
2 Halted 0 ms 0 KB -