Submission #844804

# Submission time Handle Problem Language Result Execution time Memory
844804 2023-09-06T01:19:35 Z irmuun Duathlon (APIO18_duathlon) C++17
0 / 100
43 ms 14172 KB
#include<bits/stdc++.h>
 
using namespace std;
 
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    ll n,m;
    cin>>n>>m;
    vector<ll>adj[n+1];
    for(ll i=1;i<=m;i++){
        ll u,v;
        cin>>u>>v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    if(m==n-1){
        ll ans=0;
        vector<ll>cnt(n+1,0);
        function <void(ll,ll)> dfs=[&](ll x,ll p){
            cnt[x]=1;
            vector<ll>v;
            for(ll y:adj[x]){
                if(y!=p){
                    dfs(y,x);
                    v.pb(cnt[y]);
                    cnt[x]+=cnt[y];
                }
            }
            v.pb(n-cnt[x]);
            for(ll y:v){
                ans+=(n-1-y)*y;
            }
        };
        dfs(1,-1);
        cout<<ans;
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 26 ms 5720 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Incorrect 1 ms 344 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 33 ms 7256 KB Output is correct
2 Correct 31 ms 7256 KB Output is correct
3 Correct 31 ms 7248 KB Output is correct
4 Correct 31 ms 7256 KB Output is correct
5 Correct 32 ms 7248 KB Output is correct
6 Correct 43 ms 14172 KB Output is correct
7 Correct 38 ms 12380 KB Output is correct
8 Correct 36 ms 11088 KB Output is correct
9 Correct 34 ms 9808 KB Output is correct
10 Incorrect 23 ms 6480 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Incorrect 0 ms 344 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 32 ms 7256 KB Output is correct
2 Correct 34 ms 6992 KB Output is correct
3 Incorrect 28 ms 6732 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -