結果

問題 No.2638 Initial fare
ユーザー t98slider
提出日時 2024-03-08 03:50:29
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 73 ms / 2,000 ms
コード長 524 bytes
コンパイル時間 1,983 ms
コンパイル使用メモリ 197,820 KB
最終ジャッジ日時 2025-02-20 01:48:18
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    ll ans = n - 1;
    vector<ll> cnt(n);
    vector<pair<int,int>> edge(n - 1);
    for(auto &&[u, v] : edge){
        cin >> u >> v;
        cnt[--u]++;
        cnt[--v]++;
    }
    for(int i = 0; i < n; i++){
        ans += cnt[i] * (cnt[i] - 1) / 2;
    }
    for(auto &&[u, v] : edge){
        ans += (cnt[u] - 1) * (cnt[v] - 1);
    }
    cout << ans << '\n';
}
0