結果

問題 No.806 木を道に
ユーザー misora192misora192
提出日時 2020-05-10 14:47:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 541 bytes
コンパイル時間 2,446 ms
コンパイル使用メモリ 169,012 KB
実行使用メモリ 17,704 KB
最終ジャッジ日時 2023-09-22 00:47:36
合計ジャッジ時間 6,233 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 2 ms
4,376 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 19 ms
10,832 KB
testcase_25 AC 29 ms
14,616 KB
testcase_26 AC 20 ms
7,628 KB
testcase_27 AC 65 ms
17,112 KB
testcase_28 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

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

	int n;
	cin >> n;

	multiset<int> ms[n];
	rep(i, n - 1){
		int a, b;
		cin >> a >> b;
		a--;
		b--;

		ms[a].insert(b);
		ms[b].insert(a);
	}

	int ans = 0;
	rep(i, n){
		if(ms[i].size() >= 3){
			int m = ms[i].size();
			rep(j, m - 2){
				auto it = ms[i].begin();
				int p = *it;
				ms[i].erase(p);
				ms[p].erase(i);
				ans++;
			}
		}
	}

	cout << ans << endl;
}
0