Submission #402159

# Submission time Handle Problem Language Result Execution time Memory
402159 2021-05-11T11:37:11 Z A_D Duathlon (APIO18_duathlon) C++14
0 / 100
126 ms 11576 KB

#include <bits/stdc++.h>

#define int long long

using namespace std;
const int N=1e5+100;
vector<int> g[N];
int dep[N];
int a[N];
int n,ans;
void dfs2(int u,int p)
{
    for(auto x:g[u]){
        if(x==p)continue;
        dep[x]=dep[u]+1;
        dfs2(x,u);
        a[u]+=a[x];
    }
}
void dfs(int u,int p,int ann)
{
    ans+=ann-(n);
    //cout<<u<<" "<<ann<<endl;
    ans+=1;
    for(auto x:g[u]){
        if(x==p)continue;
        dfs(x,u,ann+(n-a[x])-a[x]);
    }
}
void solve()
{
    int m,ann=0;
    cin>>n>>m;
    if(m>n-1)assert(0);
    for(int i=1;i<=n;i++)a[i]=1;
    while(m--){
        int a,b;
        cin>>a>>b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    dfs2(1,1);
    for(int i=1;i<=n;i++){
        ann+=dep[i];
    }
    dfs(1,1,ann);
    cout<<ans<<endl;
}

main()
{
    int t=1;
//    cin>>t;
    while(t--)solve();
}

Compilation message

count_triplets.cpp:52:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   52 | main()
      | ^~~~
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 5196 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 5196 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 5192 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2680 KB Output is correct
2 Correct 3 ms 2636 KB Output is correct
3 Correct 3 ms 2636 KB Output is correct
4 Correct 4 ms 2636 KB Output is correct
5 Correct 3 ms 2636 KB Output is correct
6 Correct 4 ms 2636 KB Output is correct
7 Correct 3 ms 2636 KB Output is correct
8 Correct 3 ms 2636 KB Output is correct
9 Correct 3 ms 2636 KB Output is correct
10 Incorrect 3 ms 2636 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 100 ms 7928 KB Output is correct
2 Correct 101 ms 7908 KB Output is correct
3 Correct 106 ms 7840 KB Output is correct
4 Correct 101 ms 7884 KB Output is correct
5 Correct 122 ms 7876 KB Output is correct
6 Correct 126 ms 11576 KB Output is correct
7 Correct 119 ms 10648 KB Output is correct
8 Correct 112 ms 9924 KB Output is correct
9 Correct 116 ms 9216 KB Output is correct
10 Incorrect 103 ms 7848 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2636 KB Output is correct
2 Correct 3 ms 2636 KB Output is correct
3 Runtime error 5 ms 5196 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 106 ms 7912 KB Output is correct
2 Correct 110 ms 7768 KB Output is correct
3 Runtime error 5 ms 5196 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 5196 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 5196 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -