#include #include using namespace std; int main() { cin.tie(nullptr)->sync_with_stdio(false); int N; cin >> N; vector> to(N); for (int e = 0; e < N - 1; ++e) { int a, b; cin >> a >> b; --a, --b; to.at(a).push_back(b); to.at(b).push_back(a); } auto rec = [&](auto &&self, int now, int prv, bool f) -> int { int cur = f ? 0 : 1 << 20; int nch = 0; for (int nxt : to.at(now)) { if (nxt == prv) continue; ++nch; if (int tmp = self(self, nxt, now, !f) + 1; (f and cur < tmp) or (!f and cur > tmp)) cur = tmp; } return nch ? cur : 0; }; cout << rec(rec, 0, -1, true) << '\n'; cout << rec(rec, 0, -1, false) << '\n'; }