結果

問題 No.2638 Initial fare
ユーザー ゆにぽけゆにぽけ
提出日時 2024-02-19 21:26:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,187 bytes
コンパイル時間 1,090 ms
コンパイル使用メモリ 132,404 KB
実行使用メモリ 16,132 KB
最終ジャッジ日時 2024-02-19 21:26:36
合計ジャッジ時間 5,758 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 76 ms
15,476 KB
testcase_05 AC 118 ms
16,132 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 TLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます

ソースコード

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 = 1;i < N;i++)
	{
		int a = 0,b = 0;
		int u = U[i],v = V[i];
		for(int nu : G[u])
		{
			if(nu != v)
			{
				a++;
			}
		}
		for(int nv : G[v])
		{
			if(nv != u)
			{
				b++;
			}
		}
		ans += (long long) a * b;
		ans++;
	}
	for(int i = 0;i < N;i++)
	{
		int deg = (int)G[i].size();
		ans += (long long)deg * (deg - 1) / 2;
	}
	cout << ans << "\n";
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int tt = 1;
	/* cin >> tt; */
	while(tt--) Main();
}

0