Submission #674259

# Submission time Handle Problem Language Result Execution time Memory
674259 2022-12-23T15:12:11 Z Jarif_Rahman Duathlon (APIO18_duathlon) C++17
0 / 100
1000 ms 1048576 KB
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;

int n, m;
vector<vector<int>> graph;
vector<int> sz;
ll ans = 0;

int N = 0;
void dfs(int nd, int ss){
    N++;
    sz[nd] = 1;
    for(int x: graph[nd]) if(x != ss) dfs(x, nd), sz[nd]+=sz[x];
}
void dfs2(int nd, int ss){
    for(int x: graph[nd]) if(x != ss) dfs2(x, nd);

    ans+=ll(N-sz[nd])*ll(sz[nd]-1);
    for(int x: graph[nd]) if(x != ss) ans+=ll(N-sz[x]-1)*ll(sz[x]);
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> n >> m;
    graph.resize(n);
    sz.resize(n, 0);

    for(int i = 0; i < m; i++){
        int a, b; cin >> a >> b; a--, b--;
        graph[a].pb(b);
        graph[b].pb(a);
    }

    for(int i = 0; i < 1; i++) if(!sz[i]){
        N = 0;
        dfs(i, -1);
        dfs2(i, -1);
    }

    cout << ans << "\n";
}
# Verdict Execution time Memory Grader output
1 Runtime error 520 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 520 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1098 ms 486816 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Incorrect 1 ms 324 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 41 ms 6604 KB Output is correct
2 Correct 42 ms 7544 KB Output is correct
3 Correct 46 ms 7532 KB Output is correct
4 Correct 48 ms 7504 KB Output is correct
5 Correct 43 ms 7500 KB Output is correct
6 Correct 52 ms 10812 KB Output is correct
7 Correct 50 ms 9580 KB Output is correct
8 Correct 47 ms 9036 KB Output is correct
9 Correct 46 ms 8564 KB Output is correct
10 Incorrect 48 ms 7532 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Runtime error 598 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 45 ms 6604 KB Output is correct
2 Correct 50 ms 7480 KB Output is correct
3 Runtime error 733 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 520 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 520 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -