이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |