結果

問題 No.2638 Initial fare
ユーザー SSRSSSRS
提出日時 2024-02-19 21:21:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 171 ms / 2,000 ms
コード長 556 bytes
コンパイル時間 2,096 ms
コンパイル使用メモリ 205,096 KB
実行使用メモリ 15,020 KB
最終ジャッジ日時 2024-02-19 21:21:55
合計ジャッジ時間 7,141 ms
ジャッジサーバーID
(参考情報)
judge14 / judge16
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 163 ms
13,884 KB
testcase_05 AC 171 ms
14,508 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 159 ms
14,416 KB
testcase_08 AC 139 ms
14,100 KB
testcase_09 AC 147 ms
14,976 KB
testcase_10 AC 147 ms
15,004 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 157 ms
14,356 KB
testcase_13 AC 130 ms
13,508 KB
testcase_14 AC 162 ms
14,900 KB
testcase_15 AC 145 ms
15,020 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 154 ms
14,660 KB
testcase_18 AC 145 ms
14,348 KB
testcase_19 AC 155 ms
14,700 KB
testcase_20 AC 157 ms
14,680 KB
testcase_21 AC 157 ms
14,288 KB
testcase_22 AC 2 ms
6,676 KB
testcase_23 AC 159 ms
13,980 KB
testcase_24 AC 167 ms
14,252 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 171 ms
14,380 KB
testcase_27 AC 169 ms
14,244 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<vector<int>> E(N);
  for (int i = 0; i < N - 1; i++){
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    E[u].push_back(v);
    E[v].push_back(u);
  }
  long long ans = 0;
  ans += N - 1;
  for (int i = 0; i < N; i++){
    ans += (long long) E[i].size() * (E[i].size() - 1) / 2;
  }
  for (int i = 0; i < N; i++){
    for (int j : E[i]){
      if (i < j){
        ans += (long long) (E[i].size() - 1) * (E[j].size() - 1);
      }
    }
  }
  cout << ans << endl;
}
0