結果

問題 No.2638 Initial fare
ユーザー Nzt3Nzt3
提出日時 2024-02-19 21:27:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 503 bytes
コンパイル時間 1,831 ms
コンパイル使用メモリ 207,664 KB
実行使用メモリ 16,608 KB
最終ジャッジ日時 2024-02-19 21:27:30
合計ジャッジ時間 4,463 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 70 ms
15,444 KB
testcase_05 AC 79 ms
16,068 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 66 ms
15,972 KB
testcase_08 AC 54 ms
15,556 KB
testcase_09 AC 66 ms
16,552 KB
testcase_10 AC 58 ms
16,592 KB
testcase_11 AC 1 ms
6,676 KB
testcase_12 AC 70 ms
15,788 KB
testcase_13 AC 53 ms
14,892 KB
testcase_14 AC 62 ms
16,468 KB
testcase_15 AC 59 ms
16,608 KB
testcase_16 AC 1 ms
6,676 KB
testcase_17 AC 66 ms
16,220 KB
testcase_18 AC 64 ms
15,908 KB
testcase_19 AC 69 ms
16,260 KB
testcase_20 AC 78 ms
16,112 KB
testcase_21 AC 72 ms
15,720 KB
testcase_22 AC 2 ms
6,676 KB
testcase_23 AC 74 ms
15,412 KB
testcase_24 AC 78 ms
15,812 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 77 ms
15,940 KB
testcase_27 AC 76 ms
15,804 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin>>N;
  vector G(N,vector(0,0));
  vector D(N,0ll);
  for(int i=0;i<N-1;i++){
    int U,V;
    cin>>U>>V;
    --U,--V;
    G[U].push_back(V);
    G[V].push_back(U);
    D[U]+=1;
    D[V]+=1;
  }
  ll ans=0;
  for(int i=0;i<N;i++){
    ans+=D[i];
    ans+=D[i]*(D[i]-1);
    for(int v:G[i]){
      ans+=(D[i]-1)*(D[v]-1);
    }
  }
  ans/=2;
  cout<<ans<<'\n';
}
0