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>
#define suiii ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define co cout<<
//#pragma GCC optimize("O3,Ofast,unroll-loops")
//#pragma GCC target("avx2,sse3,sse4,avx")
using namespace std;
//stuff
ll n;
vector<ll>v[1000001];
ll mid;
bool dfs(ll x,ll last,ll num){
num+=mid;
bool ans=1;
num-=v[x].size();
if(x!=1) num++;
if(num<0) return 0;
for(auto i:v[x]){
if(i==last) continue;
ans&=dfs(i,x,num);
}
return ans;
}
void solve(){
cin>>n;
for(int i=0;i<n-1;i++){
ll a,b;
cin>>a>>b;
v[a].push_back(b);
v[b].push_back(a);
}
ll l,r,ans=0;
l=0,r=1e6;
while(l<=r){
mid=(l+r)/2;
if(dfs(1,-1,0)){
r=mid-1;
ans=mid;
}
else l=mid+1;
}
co ans;
}
int main()
{
suiii
int tt=1;
// cin>>tt;
while(tt--){
solve();
}
return 0;
}
# | 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... |