답안 #1087752

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1087752 2024-09-13T07:49:52 Z alexander707070 철인 이종 경기 (APIO18_duathlon) C++14
0 / 100
36 ms 18012 KB
#include<bits/stdc++.h>
#define MAXN 200007
using namespace std;

int n,m,a,b;
vector<int> v[MAXN];
long long sz[MAXN],sum[MAXN],ans;

void dfs(int x,int p){
    sz[x]=1;

    for(int i=0;i<v[x].size();i++){
        if(v[x][i]==p)continue;
        dfs(v[x][i],x);

        sum[x]+=sz[v[x][i]]*(sz[v[x][i]]-1);
        sz[x]+=sz[v[x][i]];
    }

    sum[x]+=(n-sz[x])*(n-sz[x]-1);
}

int main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin>>n>>m;
    for(int i=1;i<=m;i++){
        cin>>a>>b;
        v[a].push_back(b);
        v[b].push_back(a);
    }

    if(m!=n-1)cout<<1/0;

    dfs(1,0);

    for(int i=1;i<=n;i++){
        ans+=(long long) (n-2)*(n-1)-sum[i];
    }

    cout<<ans<<"\n";

    return 0;
}

Compilation message

count_triplets.cpp: In function 'void dfs(int, int)':
count_triplets.cpp:12:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     for(int i=0;i<v[x].size();i++){
      |                 ~^~~~~~~~~~~~
count_triplets.cpp: In function 'int main()':
count_triplets.cpp:36:22: warning: division by zero [-Wdiv-by-zero]
   36 |     if(m!=n-1)cout<<1/0;
      |                     ~^~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 10076 KB Execution killed with signal 4
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 10076 KB Execution killed with signal 4
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 25 ms 17652 KB Execution killed with signal 4
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5208 KB Output is correct
2 Correct 4 ms 5212 KB Output is correct
3 Correct 2 ms 5212 KB Output is correct
4 Correct 3 ms 5212 KB Output is correct
5 Correct 3 ms 5212 KB Output is correct
6 Correct 2 ms 5212 KB Output is correct
7 Correct 2 ms 5092 KB Output is correct
8 Correct 2 ms 5212 KB Output is correct
9 Correct 2 ms 5212 KB Output is correct
10 Runtime error 5 ms 10076 KB Execution killed with signal 4
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 11100 KB Output is correct
2 Correct 27 ms 11080 KB Output is correct
3 Correct 28 ms 11100 KB Output is correct
4 Correct 27 ms 11060 KB Output is correct
5 Correct 27 ms 11048 KB Output is correct
6 Correct 29 ms 15188 KB Output is correct
7 Correct 29 ms 13740 KB Output is correct
8 Correct 29 ms 13144 KB Output is correct
9 Correct 28 ms 12380 KB Output is correct
10 Runtime error 36 ms 17792 KB Execution killed with signal 4
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5212 KB Output is correct
2 Correct 2 ms 5212 KB Output is correct
3 Runtime error 6 ms 10076 KB Execution killed with signal 4
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 11100 KB Output is correct
2 Correct 30 ms 11088 KB Output is correct
3 Runtime error 31 ms 18012 KB Execution killed with signal 4
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 10076 KB Execution killed with signal 4
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 10076 KB Execution killed with signal 4
2 Halted 0 ms 0 KB -