제출 #372694

#제출 시각아이디문제언어결과실행 시간메모리
372694BartolM철인 이종 경기 (APIO18_duathlon)C++17
23 / 100
1130 ms1048580 KiB
#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;
}

컴파일 시 표준 에러 (stderr) 메시지

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);
      |         ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...