253882026-02-19 18:00:30sarminÁtvágás (75 pont)cpp17Hibás válasz 45/75177ms25652 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
// const ll MOD = 1e9+7;

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

int ut = 0;
void dfs(vector<vector<int>>& g, vector<bool>& vis, int cur, int depth) {
	vis[cur] = true;
	ut = max(ut, depth);
	for (int i : g[cur]) {
		if (!vis[i]) {
			dfs(g, vis, i, depth+1);
		}
	}
}

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

    int n; cin >> n;
    vector<vector<int>> g(n);
    for (int i = 0; i < n-1; i++) {
    	int u, v; cin >> u >> v;
    	u--; v--;
    	g[u].push_back(v); g[v].push_back(u);
    }
    
    int mx = 0, start = 0;
    for (int i = 0; i < n; i++) {
    	if (mx < (int) g[i].size()) {
    		mx = (int) g[i].size();
    	}
    	if ((int) g[i].size() == 1) start = i;
    }
    
    vector<bool> vis(n, false);
    dfs(g, vis, start, 1);
    
    cout << n-ut << " " << n-1-mx << "\n";

    return 0;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base45/75
1Elfogadva0/01ms500 KiB
2Elfogadva0/01ms316 KiB
3Hibás válasz0/04ms820 KiB
4Elfogadva4/41ms316 KiB
5Részben helyes2/41ms316 KiB
6Elfogadva4/41ms316 KiB
7Részben helyes2/41ms316 KiB
8Részben helyes2/41ms316 KiB
9Részben helyes2/41ms324 KiB
10Elfogadva4/483ms12004 KiB
11Részben helyes2/4116ms12212 KiB
12Részben helyes2/4103ms12188 KiB
13Részben helyes2/4127ms12340 KiB
14Részben helyes2/4119ms12084 KiB
15Részben helyes2/4135ms11476 KiB
16Részben helyes2/4172ms11316 KiB
17Részben helyes2/4174ms11316 KiB
18Részben helyes3/5143ms11572 KiB
19Részben helyes3/6153ms17812 KiB
20Részben helyes3/6177ms25652 KiB
21Elfogadva2/21ms316 KiB