답안 #771789

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
771789 2023-07-03T09:20:04 Z gagik_2007 철인 이종 경기 (APIO18_duathlon) C++17
0 / 100
102 ms 16348 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

ll ttt;
const ll INF=1e18;
const ll MOD=1e9+7;
const ll N=3e5+7;
ll n,m,k;
vector<int>g[N];
ll sz[N];

void dfs(int v, int par=-1){
    sz[v]=1;
    for(int to:g[v]){
        if(to!=par){
            dfs(to,v);
            sz[v]+=sz[to];
        }
    }
}

void calc_ans(int c, int v, ll& ans, int par=-1){
    ll sum=0;
    for(int to:g[v]){
        if(to!=par){
            calc_ans(c,to,ans,v);
            ans+=sz[to]*(c-sz[to]-1);
            sum+=sz[to];
        }
    }
    ans+=sum*(c-sum-1);
}

int main() {
    cin>>n>>m;
    assert(m==n-1);
    for(int i=0;i<m;i++){
        int x,y;
        cin>>x>>y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    ll ans=0;
    for(int v=1;v<=n;v++){
        if(sz[v]==0){
            dfs(v);
            calc_ans(sz[v],v,ans);
        }
    }
    cout<<ans<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 9 ms 14676 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 9 ms 14676 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 8 ms 14676 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 5 ms 7312 KB Output is correct
3 Correct 3 ms 7380 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 4 ms 7380 KB Output is correct
6 Correct 3 ms 7380 KB Output is correct
7 Correct 3 ms 7380 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Correct 6 ms 7380 KB Output is correct
10 Runtime error 9 ms 14652 KB Execution killed with signal 6
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 69 ms 11352 KB Output is correct
2 Correct 66 ms 11348 KB Output is correct
3 Correct 93 ms 11340 KB Output is correct
4 Correct 87 ms 11332 KB Output is correct
5 Correct 80 ms 11304 KB Output is correct
6 Correct 102 ms 16348 KB Output is correct
7 Correct 78 ms 14632 KB Output is correct
8 Correct 71 ms 13788 KB Output is correct
9 Correct 74 ms 12836 KB Output is correct
10 Runtime error 8 ms 14740 KB Execution killed with signal 6
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 7380 KB Output is correct
2 Correct 3 ms 7380 KB Output is correct
3 Runtime error 9 ms 14676 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 66 ms 11268 KB Output is correct
2 Correct 64 ms 11244 KB Output is correct
3 Runtime error 9 ms 14676 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 9 ms 14676 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 9 ms 14676 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -