結果

問題 No.2638 Initial fare
ユーザー Diana773Diana773
提出日時 2024-02-22 22:36:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 69 ms / 2,000 ms
コード長 512 bytes
コンパイル時間 854 ms
コンパイル使用メモリ 74,168 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-02-22 22:36:27
合計ジャッジ時間 4,405 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 3 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 47 ms
6,676 KB
testcase_05 AC 52 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 51 ms
6,676 KB
testcase_08 AC 51 ms
6,676 KB
testcase_09 AC 49 ms
6,676 KB
testcase_10 AC 49 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 69 ms
6,676 KB
testcase_13 AC 48 ms
6,676 KB
testcase_14 AC 53 ms
6,676 KB
testcase_15 AC 52 ms
6,676 KB
testcase_16 AC 3 ms
6,676 KB
testcase_17 AC 53 ms
6,676 KB
testcase_18 AC 49 ms
6,676 KB
testcase_19 AC 48 ms
6,676 KB
testcase_20 AC 48 ms
6,676 KB
testcase_21 AC 49 ms
6,676 KB
testcase_22 AC 2 ms
6,676 KB
testcase_23 AC 54 ms
6,676 KB
testcase_24 AC 50 ms
6,676 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 55 ms
6,676 KB
testcase_27 AC 52 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<cstdio>
#include<utility>
#include<map>
#include<algorithm>
#include<set>
#include<vector>

using namespace std;

int _;
int n,m,q,ccf;
int l[200010];
int r[200010];
long long d[200010];
long long ans;

int main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for (int i=1; i<n; i++)
	{
		cin>>l[i]>>r[i];
		d[l[i]]++;
		d[r[i]]++;
	}
	ans=n-1;
	for (int i=1; i<=n; i++)
	  ans=ans+d[i]*(d[i]-1)/2;
	
	for (int i=1; i<n; i++)
	  ans=ans+(d[l[i]]-1)*(d[r[i]]-1);
	
	cout<<ans;
	return 0;
}
0