結果

問題 No.2638 Initial fare
ユーザー ゆにぽけゆにぽけ
提出日時 2024-02-19 21:28:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 86 ms / 2,000 ms
コード長 1,056 bytes
コンパイル時間 1,343 ms
コンパイル使用メモリ 132,148 KB
実行使用メモリ 16,612 KB
最終ジャッジ日時 2024-02-19 21:28:56
合計ジャッジ時間 4,036 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 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 73 ms
15,476 KB
testcase_05 AC 73 ms
16,132 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 70 ms
15,976 KB
testcase_08 AC 59 ms
15,556 KB
testcase_09 AC 61 ms
16,552 KB
testcase_10 AC 65 ms
16,596 KB
testcase_11 AC 1 ms
6,676 KB
testcase_12 AC 72 ms
15,868 KB
testcase_13 AC 58 ms
14,892 KB
testcase_14 AC 86 ms
16,468 KB
testcase_15 AC 77 ms
16,612 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 66 ms
16,252 KB
testcase_18 AC 65 ms
15,908 KB
testcase_19 AC 69 ms
16,196 KB
testcase_20 AC 78 ms
16,160 KB
testcase_21 AC 75 ms
15,768 KB
testcase_22 AC 2 ms
6,676 KB
testcase_23 AC 75 ms
15,508 KB
testcase_24 AC 72 ms
15,876 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 82 ms
15,876 KB
testcase_27 AC 76 ms
15,852 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <array>
#include <iterator>
#include <string>
#include <cctype>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cmath>
#include <ctime>
#include <iomanip>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <bitset>
#include <random>
#include <utility>
#include <functional>
using namespace std;
void Main()
{
	int N;
	cin >> N;
	vector<int> U(N),V(N);
	vector<vector<int>> G(N);
	for(int i = 1;i < N;i++)
	{
		cin >> U[i] >> V[i];
		U[i]--; V[i]--;
		G[U[i]].push_back(V[i]);
		G[V[i]].push_back(U[i]);
	}
	long long ans = 0;
	for(int i = 0;i < N;i++)
	{
		int deg = (int)G[i].size();
		ans += (long long)deg * (deg - 1) ;
		for(int j : G[i])
		{
			ans += (long long)(deg - 1) * ((int)G[j].size() - 1);
		}
	}
	ans /= 2;
	ans += N - 1;
	cout << ans << "\n";
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int tt = 1;
	/* cin >> tt; */
	while(tt--) Main();
}

0