Submission #103637

# Submission time Handle Problem Language Result Execution time Memory
103637 2019-04-01T15:57:10 Z zubec Duathlon (APIO18_duathlon) C++14
0 / 100
1000 ms 1049600 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

const int N = 100100;

int n, m;

vector <int> g[N];

ll sz[N];

ll ans = 0;

bool used[N];

void dfs(int v, int p){
    sz[v] = 1;
    used[v] = 1;
    for (int i = 0; i < g[v].size(); i++){
        int to = g[v][i];
        if (to == p)
            continue;
        dfs(to, v);
        sz[v] += sz[to];
    }
    ll cursum = n-sz[v];
    for (int i = 0; i < g[v].size(); i++){
        int to = g[v][i];
        if (to == p)
            continue;
        ans += cursum*sz[to]*2;
        cursum += sz[to];
    }
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    //freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);

    cin >> n >> m;
    for (int i = 1; i <= m; i++){
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    for (int i = 1; i <= n; i++)
        if (!used[i])
            dfs(i, 0);
    cout << ans;

}

/**

4 3
1 2
2 3
3 4

5 4
1 2
3 4
4 5
4 1

*/

Compilation message

count_triplets.cpp: In function 'void dfs(int, int)':
count_triplets.cpp:21:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < g[v].size(); i++){
                     ~~^~~~~~~~~~~~~
count_triplets.cpp:29:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < g[v].size(); i++){
                     ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 945 ms 1049600 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 945 ms 1049600 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1070 ms 190940 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2688 KB Output is correct
2 Correct 6 ms 2688 KB Output is correct
3 Correct 5 ms 2816 KB Output is correct
4 Correct 6 ms 2816 KB Output is correct
5 Correct 5 ms 2816 KB Output is correct
6 Correct 5 ms 2816 KB Output is correct
7 Correct 5 ms 2816 KB Output is correct
8 Correct 5 ms 2816 KB Output is correct
9 Correct 5 ms 2816 KB Output is correct
10 Incorrect 5 ms 2816 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 79 ms 6820 KB Output is correct
2 Correct 110 ms 6928 KB Output is correct
3 Correct 79 ms 6776 KB Output is correct
4 Correct 80 ms 6916 KB Output is correct
5 Correct 112 ms 7004 KB Output is correct
6 Correct 118 ms 10104 KB Output is correct
7 Correct 88 ms 8952 KB Output is correct
8 Correct 112 ms 8428 KB Output is correct
9 Correct 83 ms 7944 KB Output is correct
10 Incorrect 82 ms 6776 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2816 KB Output is correct
2 Correct 5 ms 2688 KB Output is correct
3 Execution timed out 1057 ms 1049600 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 95 ms 6796 KB Output is correct
2 Correct 99 ms 6680 KB Output is correct
3 Execution timed out 1164 ms 882116 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 945 ms 1049600 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 945 ms 1049600 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -