Submission #844805

# Submission time Handle Problem Language Result Execution time Memory
844805 2023-09-06T01:25:30 Z irmuun Duathlon (APIO18_duathlon) C++17
0 / 100
45 ms 14384 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;
            }
        };
        for(ll i=1;i<=n;i++){
            if(cnt[i]==0){
                dfs(i,-1);
            }
        }
        cout<<ans;
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 5724 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 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 412 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Incorrect 1 ms 348 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 33 ms 7224 KB Output is correct
2 Correct 32 ms 7248 KB Output is correct
3 Correct 32 ms 7260 KB Output is correct
4 Correct 32 ms 7260 KB Output is correct
5 Correct 31 ms 7260 KB Output is correct
6 Correct 39 ms 14384 KB Output is correct
7 Correct 45 ms 12304 KB Output is correct
8 Correct 37 ms 11092 KB Output is correct
9 Correct 38 ms 9808 KB Output is correct
10 Incorrect 31 ms 6492 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 33 ms 7260 KB Output is correct
2 Correct 34 ms 7040 KB Output is correct
3 Incorrect 29 ms 6740 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -