Submission #844811

# Submission time Handle Problem Language Result Execution time Memory
844811 2023-09-06T01:33:19 Z irmuun Duathlon (APIO18_duathlon) C++17
23 / 100
992 ms 1048576 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);
    }
    ll ans=0;
    vector<ll>cnt(n+1,0);
    ll cur=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(cur-cnt[x]);
        for(ll y:v){
            ans+=(cur-1-y)*y;
        }
    };
    function<void(ll,ll)> count=[&](ll x,ll p){
        cur++;
        for(auto y:adj[x]){
            if(y!=p){
                count(y,x);
            }
        }
    };
    for(ll i=1;i<=n;i++){
        if(cnt[i]==0){
            cur=0;
            count(i,-1);
            dfs(i,-1);
        }
    }
    cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Runtime error 674 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 674 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 992 ms 1048576 KB Execution killed with signal 9
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 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 7200 KB Output is correct
2 Correct 36 ms 8028 KB Output is correct
3 Correct 36 ms 8016 KB Output is correct
4 Correct 44 ms 7972 KB Output is correct
5 Correct 36 ms 8280 KB Output is correct
6 Correct 46 ms 14904 KB Output is correct
7 Correct 44 ms 12996 KB Output is correct
8 Correct 41 ms 11856 KB Output is correct
9 Correct 49 ms 10588 KB Output is correct
10 Correct 44 ms 8272 KB Output is correct
11 Correct 37 ms 8536 KB Output is correct
12 Correct 36 ms 8332 KB Output is correct
13 Correct 37 ms 8532 KB Output is correct
14 Correct 32 ms 8016 KB Output is correct
15 Correct 29 ms 7760 KB Output is correct
16 Correct 21 ms 6488 KB Output is correct
17 Correct 25 ms 10056 KB Output is correct
18 Correct 25 ms 9676 KB Output is correct
19 Correct 25 ms 9912 KB Output is correct
20 Correct 30 ms 9380 KB Output is correct
# 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 Runtime error 621 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 39 ms 7260 KB Output is correct
2 Correct 36 ms 7936 KB Output is correct
3 Runtime error 675 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 674 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 674 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -