This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxn = 300005;
int mx = 0;
vector<int>adj[maxn];
void dfs(int v, int p, int dpth){
// cout << v << ' ' << mx << ' ' << adj[v].size() - 1 << ' ' << mx - dpth << '\n';
mx += max(0ll, (int)(adj[v].size() - (p != -1 ? 1 : 0) - max(mx - dpth, 0ll) - dpth));
for(int i : adj[v]){
if(i == p) continue;
dfs(i, v, dpth + 1);
}
}
signed main()
{
cin.tie(0) -> sync_with_stdio(0);
int n;
cin >> n;
for(int i = 0; i < n - 1; i++){
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
// cout << '\n';
dfs(1, -1, 0);
cout << mx;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |