Submission #980785

# Submission time Handle Problem Language Result Execution time Memory
980785 2024-05-12T11:53:58 Z Unforgettablepl Duathlon (APIO18_duathlon) C++17
23 / 100
1000 ms 1048576 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long

vector<int> adj[200001];
bool visited[200001];
int subsize[200001];
int ans,full;

int dfs(int x,int p,int depth){
    ans+=depth;
    subsize[x]=1;
    visited[x]=true;
    for(int&i:adj[x])if(i!=p)subsize[x]+=dfs(i,x,depth+1);
    return subsize[x];
}

int reroot(int x,int p,int currans){
    int tot = currans;
    for(int&i:adj[x])if(i!=p)tot+=reroot(i,x,currans+full-2*subsize[i]);
    return tot;
}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,m;
    cin >> n >> m;
    for(int i=1;i<=m;i++){
        int a,b;cin>>a>>b;
        adj[a].emplace_back(b);
        adj[b].emplace_back(a);
    }
    int myans = 0;
    for(int i=1;i<=n;i++)if(!visited[i]){
        ans = 0;
        full = dfs(i,0,-1);
        myans+=reroot(i,0,ans);
    }
    cout << myans+n << '\n';
}
# Verdict Execution time Memory Grader output
1 Runtime error 620 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 620 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1083 ms 1048576 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6748 KB Output is correct
2 Correct 2 ms 6748 KB Output is correct
3 Correct 2 ms 6748 KB Output is correct
4 Correct 2 ms 6748 KB Output is correct
5 Correct 2 ms 6748 KB Output is correct
6 Correct 2 ms 6748 KB Output is correct
7 Correct 2 ms 6744 KB Output is correct
8 Correct 2 ms 6748 KB Output is correct
9 Correct 2 ms 6748 KB Output is correct
10 Correct 2 ms 6748 KB Output is correct
11 Correct 2 ms 6748 KB Output is correct
12 Correct 2 ms 6748 KB Output is correct
13 Correct 2 ms 6744 KB Output is correct
14 Correct 2 ms 6748 KB Output is correct
15 Correct 2 ms 6748 KB Output is correct
16 Correct 1 ms 6748 KB Output is correct
17 Correct 2 ms 6748 KB Output is correct
18 Correct 2 ms 6748 KB Output is correct
19 Correct 1 ms 6748 KB Output is correct
20 Correct 1 ms 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 11148 KB Output is correct
2 Correct 31 ms 11868 KB Output is correct
3 Correct 30 ms 11788 KB Output is correct
4 Correct 30 ms 11860 KB Output is correct
5 Correct 33 ms 11864 KB Output is correct
6 Correct 35 ms 15444 KB Output is correct
7 Correct 34 ms 14600 KB Output is correct
8 Correct 36 ms 13904 KB Output is correct
9 Correct 33 ms 13184 KB Output is correct
10 Correct 29 ms 11868 KB Output is correct
11 Correct 30 ms 11868 KB Output is correct
12 Correct 30 ms 11632 KB Output is correct
13 Correct 39 ms 11864 KB Output is correct
14 Correct 27 ms 11356 KB Output is correct
15 Correct 23 ms 11096 KB Output is correct
16 Correct 16 ms 9712 KB Output is correct
17 Correct 21 ms 11984 KB Output is correct
18 Correct 20 ms 12080 KB Output is correct
19 Correct 21 ms 11884 KB Output is correct
20 Correct 22 ms 11852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6744 KB Output is correct
2 Correct 2 ms 6748 KB Output is correct
3 Runtime error 637 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 29 ms 10588 KB Output is correct
2 Correct 30 ms 11600 KB Output is correct
3 Runtime error 701 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 620 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 620 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -