-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB.cpp
More file actions
64 lines (60 loc) · 1.55 KB
/
Copy pathB.cpp
File metadata and controls
64 lines (60 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
void err() { cerr << '\n'; }
template <class T, class ...A>
void err(T a, A ...b) {
cerr << " " << a; err(b...);
}
#define dbg(a...) cerr << __LINE__ << " [" << #a << "]:", err(a)
#else
#define dbg(a...) 0
#endif
#define all(v) (v).begin(), (v).end()
#define long int64_t
using vll = vector<long>;
using vi = vector<int>;
int main() {
ios::sync_with_stdio(false), cin.tie(nullptr);
long n; cin >> n;
vector<vll> g(n);
for (int i = 0; i < n - 1; ++i) {
int v, u; cin >> v >> u;
g[--v].emplace_back(--u);
g[u].emplace_back(v);
}
vector<bool> leaf(n), has_leaf(n);
long st = 0;
for (int i = 0; i < n; ++i) {
if ((int) g[i].size() <= 1) {
leaf[i] = true;
has_leaf[g[i][0]] = true;
} else {
st = i;
}
}
vector<bool> mark(n);
vll depth(n);
function<void(int)> Dfs = [&](int v) {
mark[v] = true;
for (auto &u : g[v]) {
if (!mark[u]) {
depth[u] = depth[v] + 1;
Dfs(u);
}
}
};
Dfs(st);
long cntl = (int) count(all(leaf), true);
long cntnl = (int) count(all(has_leaf), true);
vll parity(2);
for (int i = 0; i < n; ++i) {
if (leaf[i]) {
parity[depth[i] % 2]++;
}
}
cout << (parity[0] > 0 && parity[1] > 0 ? 3 : 1);
cout << ' ' << n - 1 - cntl + cntnl;
// what the fuck
return 0;
}