結果
| 問題 |
No.2638 Initial fare
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-02-19 21:27:25 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 160 ms / 2,000 ms |
| コード長 | 503 bytes |
| コンパイル時間 | 2,133 ms |
| コンパイル使用メモリ | 198,320 KB |
| 最終ジャッジ日時 | 2025-02-19 16:36:30 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 |
ソースコード
#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';
}