結果

問題 No.2638 Initial fare
ユーザー charmychachachacharmychachacha
提出日時 2024-02-19 22:24:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 112 ms / 2,000 ms
コード長 608 bytes
コンパイル時間 2,553 ms
コンパイル使用メモリ 203,704 KB
実行使用メモリ 16,612 KB
最終ジャッジ日時 2024-02-19 22:24:48
合計ジャッジ時間 5,546 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
9,568 KB
testcase_01 AC 4 ms
9,568 KB
testcase_02 AC 4 ms
9,568 KB
testcase_03 AC 4 ms
9,572 KB
testcase_04 AC 78 ms
15,844 KB
testcase_05 AC 80 ms
16,228 KB
testcase_06 AC 4 ms
9,568 KB
testcase_07 AC 74 ms
15,964 KB
testcase_08 AC 64 ms
15,948 KB
testcase_09 AC 96 ms
16,472 KB
testcase_10 AC 63 ms
16,460 KB
testcase_11 AC 4 ms
9,568 KB
testcase_12 AC 72 ms
15,972 KB
testcase_13 AC 60 ms
15,580 KB
testcase_14 AC 72 ms
16,412 KB
testcase_15 AC 69 ms
16,476 KB
testcase_16 AC 4 ms
9,572 KB
testcase_17 AC 71 ms
16,612 KB
testcase_18 AC 70 ms
16,356 KB
testcase_19 AC 70 ms
16,612 KB
testcase_20 AC 79 ms
16,612 KB
testcase_21 AC 74 ms
16,228 KB
testcase_22 AC 4 ms
9,572 KB
testcase_23 AC 71 ms
15,844 KB
testcase_24 AC 76 ms
15,972 KB
testcase_25 AC 4 ms
9,572 KB
testcase_26 AC 112 ms
16,100 KB
testcase_27 AC 76 ms
15,972 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int N; cin >> N;
	int U[200010], V[200010];
	vector<int> E[200010];
	for(int i = 0; i < N-1; i++){
		cin >> U[i] >> V[i]; U[i] --; V[i] --;
		E[U[i]].push_back(V[i]);
		E[V[i]].push_back(U[i]);
	}
	long long ans[5] = {};
	ans[1] = N-1;
	for(int i = 0; i < N; i++){
		long long a = E[i].size(); 
		ans[2] += a * (a-1) / 2;
	}
	for(int i = 0; i < N-1; i++){
		long long a = E[U[i]].size();
		long long b = E[V[i]].size(); 
		ans[3] += (a-1) * (b-1);		
	}
	cout << ans[1] + ans[2] + ans[3] << "\n";
}
0