結果

問題 No.806 木を道に
ユーザー nn1k_nn1k_
提出日時 2019-03-22 21:33:38
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 2,405 bytes
コンパイル時間 935 ms
コンパイル使用メモリ 106,092 KB
実行使用メモリ 8,988 KB
最終ジャッジ日時 2023-10-19 06:32:57
合計ジャッジ時間 2,448 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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,500 KB
testcase_11 AC 8 ms
4,348 KB
testcase_12 AC 33 ms
7,932 KB
testcase_13 AC 24 ms
6,612 KB
testcase_14 AC 31 ms
7,668 KB
testcase_15 AC 34 ms
7,932 KB
testcase_16 AC 12 ms
5,028 KB
testcase_17 AC 28 ms
7,404 KB
testcase_18 AC 4 ms
4,348 KB
testcase_19 AC 10 ms
4,500 KB
testcase_20 AC 29 ms
7,404 KB
testcase_21 AC 16 ms
5,556 KB
testcase_22 AC 40 ms
8,724 KB
testcase_23 AC 41 ms
8,724 KB
testcase_24 AC 18 ms
6,084 KB
testcase_25 AC 25 ms
7,668 KB
testcase_26 AC 10 ms
5,032 KB
testcase_27 AC 28 ms
8,988 KB
testcase_28 AC 3 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <limits>
#include <algorithm>
#include <queue>
#include <set>
#include <unordered_map>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <stack>
#include <string>
#include <functional>
using namespace std;

using i64 = long long;
using ui64 = unsigned long long;

using P = pair<int, int>;

constexpr int INF = (1 << 30);
constexpr std::int64_t INF64 = (1LL << 60);
constexpr int MOD = 1e9 + 7;
constexpr double PI = 3.141592653589;

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

template <typename T, typename U>
static inline std::vector<U> makeNdVector(T n, U val) noexcept {
	static_assert(std::is_integral<T>::value, "[makeNdVector] 1st argument must be an integer type");
	return std::vector<U>(std::forward<T>(n), std::forward<U>(val));
}

template <typename T, typename ...Args>
static inline decltype(auto) makeNdVector(T n, Args... args) noexcept {
	static_assert(std::is_integral<T>::value, "[makeNdVector] 1st argument must be an integer type");
	return std::vector<decltype(makeNdVector(std::forward<Args>(args)...))>(std::forward<T>(n), makeNdVector(std::forward<Args>(args)...));
}

template <typename T>
void print(vector<T> vec)
{
	for (auto &e : vec)
		cout << e << " ";
	cout << endl;
}

void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
void yes(bool f) { cout << (f ? "yes" : "no") << endl; }

template <typename T>
T gcd(T x, T y) {
	if (x == 0 || y == 0) return 0;
	T r;
	while ((r = x % y) != 0) {
		x = y;
		y = r;
	}
	return y;
}

template <typename T>
T lcm(T x, T y) {
	if (x == 0 || y == 0) return 0;
	return (x / gcd(x, y) * y);
}

int next_combination(int sub)
{
	int x = sub & -sub, y = sub + x;
	return (((sub & ~y) / x) >> 1) | y;
}

std::uint64_t combination(int n, int r) {
	if (n < 0 || r < 0) return 0;
	if (n < r) return 0;
	std::uint64_t k = 1;
	for (std::uint64_t d = 1; d <= r; ++d) {
		k *= n--;
		k /= d;
	}
	return k;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	using P = pair<int, int>;

	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].emplace_back(b);
		G[b].emplace_back(a);
	}

	int cnt = 0;
	for (int i = 0; i < N; ++i) {
		if (G[i].size() == 1) cnt++;
	}

	cout << cnt - 2 << endl;
}
0