結果

問題 No.2638 Initial fare
ユーザー daiotadaiota
提出日時 2024-02-20 06:43:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 103 ms / 2,000 ms
コード長 601 bytes
コンパイル時間 2,114 ms
コンパイル使用メモリ 170,084 KB
実行使用メモリ 16,468 KB
最終ジャッジ日時 2024-02-20 06:43:28
合計ジャッジ時間 5,140 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
8,276 KB
testcase_01 AC 4 ms
8,276 KB
testcase_02 AC 3 ms
8,276 KB
testcase_03 AC 3 ms
8,276 KB
testcase_04 AC 80 ms
15,316 KB
testcase_05 AC 85 ms
15,700 KB
testcase_06 AC 4 ms
8,276 KB
testcase_07 AC 74 ms
15,204 KB
testcase_08 AC 57 ms
15,096 KB
testcase_09 AC 61 ms
15,748 KB
testcase_10 AC 67 ms
15,864 KB
testcase_11 AC 4 ms
8,276 KB
testcase_12 AC 72 ms
15,160 KB
testcase_13 AC 57 ms
14,728 KB
testcase_14 AC 66 ms
15,688 KB
testcase_15 AC 71 ms
15,752 KB
testcase_16 AC 4 ms
8,276 KB
testcase_17 AC 103 ms
16,212 KB
testcase_18 AC 65 ms
15,444 KB
testcase_19 AC 83 ms
16,468 KB
testcase_20 AC 75 ms
15,956 KB
testcase_21 AC 75 ms
15,828 KB
testcase_22 AC 3 ms
8,276 KB
testcase_23 AC 75 ms
14,292 KB
testcase_24 AC 79 ms
14,548 KB
testcase_25 AC 3 ms
8,276 KB
testcase_26 AC 83 ms
15,572 KB
testcase_27 AC 80 ms
14,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;
#define REP(i,n) for(int i=0;i<int(n);i++)


vector<ll> G[200010];


int main(){
	cin.tie(nullptr);  ios_base::sync_with_stdio(false);
   ll i,j;

	ll N;
	cin >> N;

	for(i=1;i<N;i++){
		ll a,b;
		cin >> a >> b;
		G[a].push_back(b);
		G[b].push_back(a);
	}


	ll ans=N-1;
	for(i=1;i<=N;i++){
		ll n=G[i].size();
		if(n==0) continue;

		ans+=n*(n-1)/2;

		for(j=0;j<n;j++){
			if(i>G[i][j]) continue;
			ll k=G[i][j];
			ll m=G[k].size();
			ans+=(n-1)*(m-1);
		}
	}


	cout << ans << endl;


	return 0;

}
0