답안 #1087744

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1087744 2024-09-13T07:42:48 Z alexander707070 철인 이종 경기 (APIO18_duathlon) C++14
0 / 100
1000 ms 1048576 KB
#include<bits/stdc++.h>
#define MAXN 1000007
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);
    }

    dfs(1,0);

    for(int i=1;i<=n;i++){
        ans+=(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++){
      |                 ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 550 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 550 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1092 ms 893780 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 23896 KB Output is correct
2 Correct 10 ms 23900 KB Output is correct
3 Correct 10 ms 23900 KB Output is correct
4 Correct 11 ms 23900 KB Output is correct
5 Correct 10 ms 23900 KB Output is correct
6 Correct 10 ms 23812 KB Output is correct
7 Correct 12 ms 23900 KB Output is correct
8 Correct 11 ms 24008 KB Output is correct
9 Correct 12 ms 23900 KB Output is correct
10 Incorrect 11 ms 23960 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 39 ms 29988 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 24156 KB Output is correct
2 Correct 10 ms 23896 KB Output is correct
3 Runtime error 625 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 37 ms 29788 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 550 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 550 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -