結果

問題 No.1752 Up-Down Tree
ユーザー kabipoyokabipoyo
提出日時 2021-11-19 22:30:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,633 bytes
コンパイル時間 3,324 ms
コンパイル使用メモリ 209,708 KB
実行使用メモリ 19,532 KB
最終ジャッジ日時 2023-08-30 09:17:00
合計ジャッジ時間 5,252 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 105 ms
19,532 KB
testcase_01 AC 109 ms
19,380 KB
testcase_02 AC 66 ms
10,072 KB
testcase_03 AC 64 ms
10,076 KB
testcase_04 AC 92 ms
14,872 KB
testcase_05 AC 99 ms
16,572 KB
testcase_06 AC 86 ms
13,600 KB
testcase_07 AC 87 ms
13,352 KB
testcase_08 AC 55 ms
6,776 KB
testcase_09 AC 86 ms
8,360 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
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 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
typedef int64_t lint;
#define rep(i, n) for(int i=0; i<n; i++)
#define repx(i, l, n) for(int i=l; i<n; i++)
#define all(v) v.begin(), v.end()
#define show(x) cout << #x << ": " << x << endl;
#define list(x) cout << #x << ": " << x << "  ";
#define pb push_back
using vi = vector<lint>;
using vvi = vector<vector<lint>>;
template<class T> inline void vin(vector<T>& v) { rep(i, v.size()) cin >> v.at(i); }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline void drop(T x) { cout << x << endl; exit(0); }
template<class T> void vout(vector<T> v) { rep(i, v.size()) { cout << v.at(i) << ' '; } cout << endl; }
constexpr lint LINF = LLONG_MAX/2;
using pint = pair<lint, lint>;
using vp = vector<pint>;

vector<vector<int>> G;
void make_graph(int N) {
	G.resize(N);
	int x, y;
	rep(i, N-1) {
		cin >> x >> y;
		x--, y--;
		G[x].push_back(y);
		G[y].push_back(x);
	}
}

pint rec(int x, int from) {
	vi v;
	lint y, z, a=0;
	for (auto t : G[x]) {
		if (t == from) continue;
		tie(y, z) = rec(t, x);
		a += y+z;
		if (y%2 == 0) y--;
		v.pb(y);
	}
	if (v.size() == 0) return {1, 0};
	sort(all(v), greater());
	if (v.size() == 1) {
		if (a-v[0]) return {v[0]+2, a-v[0]-1};
		else return {v[0]+1, a-v[0]};
	}
	else return {v[0]+v[1]+1, a-v[0]-v[1]};
}

int main() {
	lint N;
	cin >> N;
	make_graph(N);

	lint a=0, b=0, c=0, x, y, z;
	tie(x, y) = rec(0, -1);
	std::cout << x << '\n';
}
0