답안 #401420

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
401420 2021-05-10T07:59:34 Z Hazem 철인 이종 경기 (APIO18_duathlon) C++14
0 / 100
96 ms 14048 KB
#include <bits/stdc++.h>
using namespace std;
 
#define LL long long
#define F first
#define S second
#define pii pair<int,int>
#define piii pair<pair<int,int>,int>

const int N = 2e5+10;
const int M = 200;
const LL INF = 1e9;
const LL LINF = 1e14;
const LL MOD = 1e9+7;
const double PI = 3.141592653589793;

vector<int>adj[N];
LL sizes[N],n,m;
bool vis[N];

LL dfs(int i,int pre){

    vis[i] = sizes[i] = 1;
    LL ret = 0;
    for(auto x:adj[i])
        if(x!=pre){
            ret += dfs(x,i);
            sizes[i] += sizes[x];
        }

    LL cur = n-1;
    for(auto x:adj[i]){
        LL v = 0;
        if(x==pre)v = n-sizes[i];
        else v = sizes[x];
        ret += (cur-v)*v;
    }

    return ret;
}

int main(){

    //freopen("out.txt","w",stdout);
    //freopen("out.txt","r",stdin);

    scanf("%d%d",&n,&m);
    assert(m==n-1);

    for(int i=1;i<=m;i++){
        int u,v;
        scanf("%d%d",&u,&v);
        adj[u].push_back(v);
        adj[v].push_back(u);        
    }

    LL ans = 0;
    for(int i=1;i<=n;i++)
        if(!vis[i])
            ans += dfs(i,i);

    printf("%lld",ans);
}   

Compilation message

count_triplets.cpp: In function 'long long int dfs(int, int)':
count_triplets.cpp:23:23: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   23 |     vis[i] = sizes[i] = 1;
      |              ~~~~~~~~~^~~
count_triplets.cpp: In function 'int main()':
count_triplets.cpp:47:13: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
   47 |     scanf("%d%d",&n,&m);
      |            ~^    ~~
      |             |    |
      |             int* long long int*
      |            %lld
count_triplets.cpp:47:15: warning: format '%d' expects argument of type 'int*', but argument 3 has type 'long long int*' [-Wformat=]
   47 |     scanf("%d%d",&n,&m);
      |              ~^     ~~
      |               |     |
      |               int*  long long int*
      |              %lld
count_triplets.cpp:47:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   47 |     scanf("%d%d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~
count_triplets.cpp:52:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   52 |         scanf("%d%d",&u,&v);
      |         ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 9 ms 9932 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 9 ms 9932 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 8 ms 9932 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4940 KB Output is correct
2 Correct 4 ms 4940 KB Output is correct
3 Correct 4 ms 4940 KB Output is correct
4 Correct 4 ms 5068 KB Output is correct
5 Correct 4 ms 5068 KB Output is correct
6 Correct 5 ms 5068 KB Output is correct
7 Correct 4 ms 5068 KB Output is correct
8 Correct 4 ms 5068 KB Output is correct
9 Correct 5 ms 5068 KB Output is correct
10 Runtime error 10 ms 9964 KB Execution killed with signal 6
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 70 ms 9008 KB Output is correct
2 Correct 68 ms 9100 KB Output is correct
3 Correct 96 ms 9100 KB Output is correct
4 Correct 91 ms 8984 KB Output is correct
5 Correct 80 ms 9100 KB Output is correct
6 Correct 80 ms 14048 KB Output is correct
7 Correct 82 ms 12428 KB Output is correct
8 Correct 85 ms 11460 KB Output is correct
9 Correct 83 ms 10624 KB Output is correct
10 Runtime error 9 ms 9936 KB Execution killed with signal 6
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4940 KB Output is correct
2 Correct 4 ms 4940 KB Output is correct
3 Runtime error 9 ms 9932 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 73 ms 9068 KB Output is correct
2 Correct 71 ms 8948 KB Output is correct
3 Runtime error 9 ms 9932 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 9 ms 9932 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 9 ms 9932 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -