답안 #402154

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
402154 2021-05-11T11:34:15 Z A_D 철인 이종 경기 (APIO18_duathlon) C++14
0 / 100
120 ms 11580 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()
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 5196 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 5196 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 5196 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2636 KB Output is correct
2 Correct 3 ms 2636 KB Output is correct
3 Correct 3 ms 2636 KB Output is correct
4 Correct 3 ms 2636 KB Output is correct
5 Correct 3 ms 2636 KB Output is correct
6 Correct 3 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 Runtime error 5 ms 5196 KB Execution killed with signal 6
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 112 ms 7904 KB Output is correct
2 Correct 108 ms 7932 KB Output is correct
3 Correct 101 ms 7872 KB Output is correct
4 Correct 101 ms 7848 KB Output is correct
5 Correct 111 ms 7924 KB Output is correct
6 Correct 120 ms 11580 KB Output is correct
7 Correct 119 ms 10608 KB Output is correct
8 Correct 117 ms 9924 KB Output is correct
9 Correct 116 ms 9284 KB Output is correct
10 Runtime error 5 ms 5172 KB Execution killed with signal 6
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 Grader output
1 Correct 104 ms 7836 KB Output is correct
2 Correct 111 ms 7716 KB Output is correct
3 Runtime error 5 ms 5196 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 5196 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 5196 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -