結果

問題 No.806 木を道に
ユーザー Bwambocos
提出日時 2019-03-22 21:57:54
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 56 ms / 2,000 ms
コード長 426 bytes
コンパイル時間 1,681 ms
コンパイル使用メモリ 168,280 KB
実行使用メモリ 5,760 KB
最終ジャッジ日時 2024-09-19 05:20:13
合計ジャッジ時間 2,913 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

int main()
{
	LL N;
	in >> N;
	std::vector<LL>a(N - 1), b(N - 1);
	rep(i, N - 1) in >> a[i] >> b[i];

	std::vector<LL>cnt(N + 1);
	rep(i, N - 1)
	{
		++cnt[a[i]];
		++cnt[b[i]];
	}

	LL ans = 0;
	for (LL i = 1; i <= N; ++i)
	{
		if (cnt[i] > 2) ans += cnt[i] - 2;
	}
	out << ans << std::endl;
}
0