結果

問題 No.806 木を道に
ユーザー misora192
提出日時 2020-05-10 14:47:57
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 541 bytes
コンパイル時間 1,313 ms
コンパイル使用メモリ 171,284 KB
実行使用メモリ 17,536 KB
最終ジャッジ日時 2024-07-07 17:42:18
合計ジャッジ時間 3,753 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 9 WA * 18
権限があれば一括ダウンロードができます

ソースコード

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