답안 #372694

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
372694 2021-03-01T10:03:05 Z BartolM 철인 이종 경기 (APIO18_duathlon) C++17
23 / 100
1000 ms 1048580 KB
#include <bits/stdc++.h>

using namespace std;

#define X first
#define Y second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <int, pii> pip;
typedef pair <pii, int> ppi;
typedef pair <ll, ll> pll;

const int INF=0x3f3f3f3f;
const int N=1e5+5;

int n, m;
ll sol=0;
int cnt[N], bio[N];
vector <int> ls[N];

void dfs(int node, int par) {
    cnt[node]=1;
    for (int sus:ls[node]) {
        if (sus==par) continue;
        dfs(sus, node);
        cnt[node]+=cnt[sus];
    }
}

void calc(int node, int par, int uk) {
    int iz=uk-1;
    for (int sus:ls[node]) {
        if (sus==par) continue;
        calc(sus, node, uk);
        iz-=cnt[sus];
        sol+=(ll)cnt[sus]*(uk-cnt[sus]-1);
    }
    sol+=(ll)iz*(uk-iz-1);
}

void solve() {
    for (int i=1; i<=n; ++i) {
        if (cnt[i]) continue;
        dfs(i, 0);
        calc(i, 0, cnt[i]);
    }
    printf("%lld\n", sol);
}

void load() {
    scanf("%d %d", &n, &m);
    for (int i=0; i<m; ++i) {
        int a, b;
        scanf("%d %d", &a, &b);
        ls[a].pb(b); ls[b].pb(a);
    }
}

int main() {
    load();
    solve();
    return 0;
}

Compilation message

count_triplets.cpp: In function 'void load()':
count_triplets.cpp:53:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   53 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
count_triplets.cpp:56:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   56 |         scanf("%d %d", &a, &b);
      |         ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 618 ms 1048580 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 618 ms 1048580 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1130 ms 442348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2668 KB Output is correct
2 Correct 3 ms 2668 KB Output is correct
3 Correct 3 ms 2668 KB Output is correct
4 Correct 4 ms 2796 KB Output is correct
5 Correct 4 ms 2796 KB Output is correct
6 Correct 3 ms 2796 KB Output is correct
7 Correct 3 ms 2796 KB Output is correct
8 Correct 2 ms 2796 KB Output is correct
9 Correct 3 ms 2796 KB Output is correct
10 Correct 2 ms 2668 KB Output is correct
11 Correct 3 ms 2668 KB Output is correct
12 Correct 3 ms 2668 KB Output is correct
13 Correct 2 ms 2668 KB Output is correct
14 Correct 3 ms 2668 KB Output is correct
15 Correct 2 ms 2668 KB Output is correct
16 Correct 2 ms 2668 KB Output is correct
17 Correct 2 ms 2668 KB Output is correct
18 Correct 2 ms 2668 KB Output is correct
19 Correct 2 ms 2796 KB Output is correct
20 Correct 2 ms 2668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 69 ms 7532 KB Output is correct
2 Correct 89 ms 7808 KB Output is correct
3 Correct 77 ms 7532 KB Output is correct
4 Correct 73 ms 7660 KB Output is correct
5 Correct 66 ms 7532 KB Output is correct
6 Correct 85 ms 11756 KB Output is correct
7 Correct 84 ms 10348 KB Output is correct
8 Correct 83 ms 9580 KB Output is correct
9 Correct 94 ms 8940 KB Output is correct
10 Correct 67 ms 7532 KB Output is correct
11 Correct 67 ms 7628 KB Output is correct
12 Correct 68 ms 7612 KB Output is correct
13 Correct 77 ms 7532 KB Output is correct
14 Correct 60 ms 7552 KB Output is correct
15 Correct 54 ms 7148 KB Output is correct
16 Correct 31 ms 5996 KB Output is correct
17 Correct 42 ms 7908 KB Output is correct
18 Correct 43 ms 7908 KB Output is correct
19 Correct 43 ms 7776 KB Output is correct
20 Correct 45 ms 7788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2668 KB Output is correct
2 Correct 3 ms 2668 KB Output is correct
3 Runtime error 740 ms 1048580 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 7532 KB Output is correct
2 Correct 84 ms 7532 KB Output is correct
3 Runtime error 880 ms 1048580 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 618 ms 1048580 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 618 ms 1048580 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -