結果

問題 No.806 木を道に
ユーザー wunderkammer2wunderkammer2
提出日時 2019-12-30 21:19:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 1,036 bytes
コンパイル時間 827 ms
コンパイル使用メモリ 94,424 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-27 15:22:44
合計ジャッジ時間 3,323 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 14 ms
6,944 KB
testcase_11 AC 12 ms
6,944 KB
testcase_12 AC 49 ms
6,940 KB
testcase_13 AC 37 ms
6,940 KB
testcase_14 AC 48 ms
6,944 KB
testcase_15 AC 50 ms
6,940 KB
testcase_16 AC 19 ms
6,940 KB
testcase_17 AC 44 ms
6,940 KB
testcase_18 AC 6 ms
6,940 KB
testcase_19 AC 15 ms
6,940 KB
testcase_20 AC 43 ms
6,940 KB
testcase_21 AC 25 ms
6,940 KB
testcase_22 AC 59 ms
6,940 KB
testcase_23 AC 58 ms
6,944 KB
testcase_24 AC 31 ms
6,940 KB
testcase_25 AC 46 ms
6,944 KB
testcase_26 AC 17 ms
6,940 KB
testcase_27 AC 57 ms
6,944 KB
testcase_28 AC 3 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<algorithm>
#include<cmath>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
const ll mod = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

int main()
{	
	int N;
	cin >> N;

	vector<int> counts(N, 0);
	rep(i, N - 1)
	{
		int a, b;
		cin >> a >> b;
		counts[--a]++;
		counts[--b]++;
	}

	//次数が1である頂点が2つのみの無向木
	//無向「木」を道にするので、次数が3以上の頂点を数えればよい。
	//次数1の頂点に接続する辺は、自明な場合を除いて必ず次数が2以上の頂点にも接続している。
	
	ll answer = 0;
	rep(i, N)
	{
		if (counts[i] >= 3) answer += (ll)(counts[i] - 2);
	}

	cout << answer << endl;

	return 0;
}
0