結果
問題 | No.2638 Initial fare |
ユーザー |
![]() |
提出日時 | 2024-02-19 21:57:52 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 151 ms / 2,000 ms |
コード長 | 610 bytes |
コンパイル時間 | 2,077 ms |
コンパイル使用メモリ | 196,288 KB |
最終ジャッジ日時 | 2025-02-19 16:58:16 |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 |
ソースコード
#include <bits/stdc++.h>#ifdef LOCAL#include "./debug.cpp"#else#define debug(...)#define print_line#endifusing namespace std;using ll = long long;int main() {int N;cin >> N;vector<pair<int, int>> E(N - 1);vector<ll> D(N);for (int i = 0; i < N - 1; i++) {int u, v;cin >> u >> v;u--;v--;E[i] = make_pair(u, v);D[u]++;D[v]++;}ll ans = 0;for (auto [u, v] : E) ans += (D[u] - 1) * (D[v] - 1);for (int i = 0; i < N; i++) ans += D[i] * (D[i] - 1) / 2;ans += N - 1;cout << ans << endl;}