結果

問題 No.806 木を道に
ユーザー polylogKpolylogK
提出日時 2019-03-22 21:28:16
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 505 bytes
コンパイル時間 1,625 ms
コンパイル使用メモリ 170,580 KB
実行使用メモリ 9,088 KB
最終ジャッジ日時 2023-10-19 06:27:06
合計ジャッジ時間 3,227 ms
ジャッジサーバーID
(参考情報)
judge15 / 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 3 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,608 KB
testcase_11 AC 9 ms
4,380 KB
testcase_12 AC 41 ms
8,040 KB
testcase_13 AC 29 ms
6,720 KB
testcase_14 AC 39 ms
7,776 KB
testcase_15 AC 40 ms
8,040 KB
testcase_16 AC 14 ms
5,196 KB
testcase_17 AC 34 ms
7,512 KB
testcase_18 AC 4 ms
4,348 KB
testcase_19 AC 10 ms
4,608 KB
testcase_20 AC 34 ms
7,512 KB
testcase_21 AC 18 ms
5,664 KB
testcase_22 AC 48 ms
8,832 KB
testcase_23 AC 48 ms
8,832 KB
testcase_24 AC 18 ms
6,192 KB
testcase_25 AC 28 ms
7,776 KB
testcase_26 AC 11 ms
5,140 KB
testcase_27 AC 30 ms
9,088 KB
testcase_28 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

int main() {
	int n; scanf("%d", &n);
	std::vector<std::vector<int>> g(n);
	for(int i = 0; i < n - 1; i++) {
		int a, b; scanf("%d%d", &a, &b);
		
		g[a - 1].push_back(b - 1);
		g[b - 1].push_back(a - 1);
	}
	
	int ans = 0;
	for(int i = 0; i < g.size(); i++) {
		if(g[i].size() <= 2) continue;
		ans += g[i].size() - 2;
	}
	printf("%d\n", ans);
	return 0;
}
0