結果

問題 No.806 木を道に
ユーザー ant2357ant2357
提出日時 2019-04-15 22:40:53
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 825 bytes
コンパイル時間 1,635 ms
コンパイル使用メモリ 171,196 KB
実行使用メモリ 9,032 KB
最終ジャッジ日時 2023-10-22 06:52:34
合計ジャッジ時間 5,214 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 9 ms
4,544 KB
testcase_11 AC 9 ms
4,348 KB
testcase_12 AC 36 ms
7,976 KB
testcase_13 AC 25 ms
6,656 KB
testcase_14 AC 33 ms
7,712 KB
testcase_15 AC 36 ms
7,976 KB
testcase_16 AC 12 ms
5,072 KB
testcase_17 AC 29 ms
7,448 KB
testcase_18 AC 4 ms
4,348 KB
testcase_19 AC 9 ms
4,544 KB
testcase_20 AC 30 ms
7,448 KB
testcase_21 AC 16 ms
5,600 KB
testcase_22 AC 40 ms
8,768 KB
testcase_23 AC 42 ms
8,768 KB
testcase_24 AC 18 ms
6,128 KB
testcase_25 AC 25 ms
7,712 KB
testcase_26 AC 10 ms
5,076 KB
testcase_27 AC 28 ms
9,032 KB
testcase_28 AC 3 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;

const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { -1, 0, 1, 0 };

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n;
	cin >> n;

	vector<vector<int>> g(n);
	for (int i = 0; i < n - 1; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		
		g[a].push_back(b);
		g[b].push_back(a);
	}


	int ans = 0;
	for (int i = 0; i < n; i++) {
		int deg = g[i].size();

		if (deg >= 2) {
			ans += abs(deg - 2);
		}
	}

	cout << ans << endl;
	return 0;
}
0