結果

問題 No.1582 Vertexes vs Edges
ユーザー uzzyuzzy
提出日時 2021-07-03 04:37:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 1,067 bytes
コンパイル時間 2,262 ms
コンパイル使用メモリ 184,612 KB
実行使用メモリ 9,196 KB
最終ジャッジ日時 2023-09-12 10:07:45
合計ジャッジ時間 4,942 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,756 KB
testcase_01 AC 3 ms
5,776 KB
testcase_02 AC 3 ms
5,800 KB
testcase_03 AC 3 ms
5,912 KB
testcase_04 AC 4 ms
6,040 KB
testcase_05 AC 28 ms
8,644 KB
testcase_06 AC 4 ms
5,860 KB
testcase_07 AC 7 ms
6,156 KB
testcase_08 AC 16 ms
7,200 KB
testcase_09 AC 27 ms
8,396 KB
testcase_10 AC 18 ms
7,448 KB
testcase_11 AC 5 ms
5,916 KB
testcase_12 AC 13 ms
6,856 KB
testcase_13 AC 21 ms
7,580 KB
testcase_14 AC 21 ms
7,616 KB
testcase_15 AC 28 ms
8,536 KB
testcase_16 AC 16 ms
7,236 KB
testcase_17 AC 21 ms
7,480 KB
testcase_18 AC 34 ms
8,756 KB
testcase_19 AC 20 ms
7,600 KB
testcase_20 AC 20 ms
7,400 KB
testcase_21 AC 17 ms
7,404 KB
testcase_22 AC 28 ms
8,436 KB
testcase_23 AC 13 ms
6,760 KB
testcase_24 AC 7 ms
6,248 KB
testcase_25 AC 18 ms
7,448 KB
testcase_26 AC 13 ms
6,852 KB
testcase_27 AC 27 ms
8,276 KB
testcase_28 AC 10 ms
6,580 KB
testcase_29 AC 24 ms
7,828 KB
testcase_30 AC 16 ms
7,136 KB
testcase_31 AC 27 ms
7,876 KB
testcase_32 AC 13 ms
6,676 KB
testcase_33 AC 37 ms
8,988 KB
testcase_34 AC 37 ms
9,196 KB
testcase_35 AC 37 ms
8,988 KB
testcase_36 AC 3 ms
5,720 KB
testcase_37 AC 3 ms
5,812 KB
testcase_38 AC 4 ms
5,720 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ("O2")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
//#include<atcoder/all>
//using namespace atcoder;


using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

vector<int> E[100100];
pair<int, int> dfs(int u, int mae) {
	int ret1 = 0, ret2 = 1;
	for (auto to : E[u]) if (to != mae) {
		auto p = dfs(to, u);
		ret1 += p.second;
		ret2 += min(p.first, p.second);
	}
	return mp(ret1, ret2);
}

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


	int N;
	cin >> N;
	rep(i, N - 1) {
		int u, v;
		cin >> u >> v;
		E[u].pb(v);
		E[v].pb(u);
	}

	auto p = dfs(1, -1);

	co(min(p.second, p.first));


	Would you please return 0;
}
0