Submission #103634

# Submission time Handle Problem Language Result Execution time Memory
103634 2019-04-01T15:47:55 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;

void dfs(int v, int p){
    sz[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];
        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);
    }
    dfs(1, 0);
    cout << ans*2;

}

/**

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:18:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < g[v].size(); i++){
                     ~~^~~~~~~~~~~~~
count_triplets.cpp:26: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 Execution timed out 1002 ms 1049600 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1002 ms 1049600 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1084 ms 210088 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2816 KB Output is correct
2 Correct 6 ms 2816 KB Output is correct
3 Correct 5 ms 2688 KB Output is correct
4 Correct 6 ms 2816 KB Output is correct
5 Correct 4 ms 2688 KB Output is correct
6 Correct 5 ms 2816 KB Output is correct
7 Correct 5 ms 2688 KB Output is correct
8 Correct 5 ms 2816 KB Output is correct
9 Correct 6 ms 2816 KB Output is correct
10 Incorrect 6 ms 2716 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 113 ms 7776 KB Output is correct
2 Correct 105 ms 7932 KB Output is correct
3 Correct 132 ms 7932 KB Output is correct
4 Correct 101 ms 7932 KB Output is correct
5 Correct 98 ms 8028 KB Output is correct
6 Correct 131 ms 11256 KB Output is correct
7 Correct 129 ms 10144 KB Output is correct
8 Correct 130 ms 9624 KB Output is correct
9 Correct 108 ms 9000 KB Output is correct
10 Incorrect 77 ms 8004 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2688 KB Output is correct
2 Correct 5 ms 2816 KB Output is correct
3 Execution timed out 1065 ms 1049600 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 121 ms 7860 KB Output is correct
2 Correct 81 ms 7864 KB Output is correct
3 Execution timed out 1147 ms 915024 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1002 ms 1049600 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1002 ms 1049600 KB Time limit exceeded
2 Halted 0 ms 0 KB -