結果

問題 No.763 Noelちゃんと木遊び
ユーザー gazellegazelle
提出日時 2018-12-11 00:12:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,452 bytes
コンパイル時間 1,567 ms
コンパイル使用メモリ 135,960 KB
実行使用メモリ 11,876 KB
最終ジャッジ日時 2023-10-14 22:19:37
合計ジャッジ時間 4,309 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
11,384 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
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 -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<queue>
#include<iomanip>
#include<math.h>
#include<bitset>
#include<cassert>
#include<random>
#include<time.h>
#include<functional>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

/* --------------------------------------- */

ll n;
vector<vector<ll>> g;
vector<ll> cnt;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n;
	g.resize(n);
	cnt.resize(n, 0);
	REP(i, n - 1) {
		ll u, v;
		cin >> u >> v;
		u--; v--;
		g[u].pb(v); cnt[u]++;
		g[v].pb(u); cnt[v]++;
	}
	priority_queue<P> q;
	vector<bool> used(n, false);
	ll ans = 1;
	REP(i,n) q.push(P(cnt[i],i));
	while(!q.empty()) {
		ll cost = q.top().first;
		ll p = q.top().second;
		q.pop();
		if(cnt[p] != cost) continue;
		if(cost == 0) break;
		used[p] = true;
		ans += cost - 1;
		REP(i,g[p].size()) {
			if(used[g[p][i]]) continue;
			cnt[g[p][i]]--;
			q.push(P(cnt[g[p][i]], g[p][i]));
		}
	}
	cout << ans << endl;
 	return 0;
}

/* --------------------------------------- */

0