結果

問題 No.2638 Initial fare
ユーザー a01sa01to
提出日時 2024-12-21 00:32:05
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 151 ms / 2,000 ms
コード長 654 bytes
コンパイル時間 3,295 ms
コンパイル使用メモリ 249,536 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-12-21 00:32:15
合計ジャッジ時間 8,815 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
  #include "settings/debug.cpp"
#else
  #define Debug(...) void(0)
#endif
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using ull = unsigned long long;

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> Edges(n - 1);
  vector<ll> deg(n, 0);
  rep(i, n - 1) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    Edges[i] = { a, b };
    deg[a]++, deg[b]++;
  }
  ll ans = 0;
  ans += n - 1;
  rep(i, n) ans += deg[i] * (deg[i] - 1) / 2;
  rep(i, n - 1) {
    auto [a, b] = Edges[i];
    ans += (deg[a] - 1) * (deg[b] - 1);
  }
  cout << ans << endl;
  return 0;
}
0