#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
//#include <__msvc_all_public_headers.hpp>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
typedef long long ll;
#define press_F_to_pay_respect ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn for(int i=0;i<n;i++)
#define fore(i,a,b) for(int i = a; i < (b); i++)
#define pb push_back
#define pob pop_back()
#define mp make_pair
#define sc second
#define f first
#define ld long double
#define kek cout<<"\n";
#define rep(i,a,b) for(int i=a;i<b;i++)
#define all(v) ((v).begin()), ((v).end())
#define halt {cout<<"NO"; return 0;}
const ll MOD = 1e9 + 7;
const ll MOD1 = 998244353;
const int N = 5010;
const int INF = 1e8;
const ll LL_INF=1e18;
const long double pi=3.1415926535;
using namespace std;
using namespace __gnu_pbds;
typedef tree<ld,null_type,less<ld>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
int divide(int a, int b)
{
return (a+b-1)/b;
}
vector<vector<ll>> adj;
vector<ll> dp;
vector<ll> g;
ll diam=0;
vector<bool> nodes;
void dfs(int s, int e)
{
dp[s]=1;
vector<ll> val;
for(auto x: adj[s])
{
if(e==x) continue;
dfs(x,s);
val.pb(dp[x]);
}
sort(all(val));
if(val.size()) dp[s]+=val.back();
if(val.size()>=2) g[s]=1+val.back()+val[val.size()-2];
diam=max(diam, max(dp[s],g[s]));
}
void dfs1(int s, int e)
{
if(adj[s].size()==1) nodes[s]=true;
for(auto x: adj[s])
{
if(x==e) continue;
if(dp[x]==dp[s]-1)
dfs1(x,s);
}
}
int main()
{
#if defined(_DEBUG)
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
press_F_to_pay_respect;
// cout << fixed << setprecision(12) << ans;
// string al = "abcdefghijklmnopqrstuvwxyz";
int questions=1;
// cin>>questions;
while(questions--)
{
int n;
cin>>n;
if(n==1)
{
cout<<1;
return 0;
}
adj.resize(n+2);
dp.resize(n+2);
g.resize(n+2);
nodes.resize(n+2);
int z=n-1;
while(z--)
{
int a,b;
cin>>a>>b;
adj[a].pb(b);
adj[b].pb(a);
}
dfs(1,0);
vector<ll> d=dp;
// we have found diam == tree diameter
for(int i=1;i<=n;i++)
{
if(g[i]==diam)
{
dp.clear();
dp.resize(n+2);
g.clear();
g.resize(n+2);
// now lets root the tree on node i and count dp and g vectors
dfs(i,0);
vector<int> val;
// add in vector<int> val all dp values from other nodes
for(auto x: adj[i]) val.pb(dp[x]);
// then choose two maximum
sort(all(val));
int mx=val.back();
int mx1=val[val.size()-2];
// then do dfs1 to find leaves
for(auto x: adj[i])
{
if(dp[x]==mx || dp[x]==mx1) dfs1(x,0);
}
// if we have found needed nodes write them
}
}
dp=d;
// otherwise the tree is rooted in node 1 and we need to find leaves from here
for(int i=1;i<=n;i++)
{
if(dp[i]==diam)
{
// dfs from node i
//cout<<"aaa1"<<" "<<i;
nodes[i]=true;
dfs1(i,0);
break;
}
}
// we have found the answer, print it
for(int i=1;i<=n;i++)
{
if(nodes[i]) cout<<diam;
else cout<<diam-1;
kek;
}
}
// !!! LOOK AT NUMBER OF QUESTIONS IN A PROBLEM !!! (cin>>questions)
// cout <<"Runtime is:"<<clock() * 1.0 / CLOCKS_PER_SEC <<endl;
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNpbmNsdWRlIDxleHQvcGJfZHMvYXNzb2NfY29udGFpbmVyLmhwcD4KLy8jaW5jbHVkZSA8X19tc3ZjX2FsbF9wdWJsaWNfaGVhZGVycy5ocHA+CiAKI3ByYWdtYSBHQ0Mgb3B0aW1pemUoIk9mYXN0IikKI3ByYWdtYSBHQ0MgdGFyZ2V0KCJhdngsYXZ4MixmbWEiKQojcHJhZ21hIEdDQyBvcHRpbWl6YXRpb24gKCJ1bnJvbGwtbG9vcHMiKQogCnR5cGVkZWYgbG9uZyBsb25nICBsbDsKCiNkZWZpbmUgcHJlc3NfRl90b19wYXlfcmVzcGVjdCBpb3NfYmFzZTo6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09MDsKdmVjdG9yPGJvb2w+IG5vZGVzOwp2b2lkIGRmcyhpbnQgcywgaW50IGUpCnsKICAgICAgICAgIGRwW3NdPTE7CiAgICAgICAgICB2ZWN0b3I8bGw+IHZhbDsKICAgICAgICAgIGZvcihhdXRvIHg6IGFkaltzXSkKICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICBpZihlPT14KSBjb250aW51ZTsKICAgICAgICAgICAgICAgICAgICBkZnMoeCxzKTsKICAgICAgICAgICAgICAgICAgICB2YWwucGIoZHBbeF0pOwogICAgICAgICAgfQogICAgICAgICAgc29ydChhbGwodmFsKSk7CiAgICAgICAgICBpZih2YWwuc2l6ZSgpKSBkcFtzXSs9dmFsLmJhY2soKTsKICAgICAgICAgIGlmKHZhbC5zaXplKCk+PTIpIGdbc109MSt2YWwuYmFjaygpK3ZhbFt2YWwuc2l6ZSgpLTJdOwogICAgICAgICAgCiAgICAgICAgICBkaWFtPW1heChkaWFtLCBtYXgoZHBbc10sZ1tzXSkpOwp9CnZvaWQgZGZzMShpbnQgcywgaW50IGUpCnsKICAgICAgICAgaWYoYWRqW3NdLnNpemUoKT09MSkgbm9kZXNbc109dHJ1ZTsKICAgICAgICAgZm9yKGF1dG8geDogYWRqW3NdKQogICAgICAgICB7CiAgICAgICAgICAgICAgICAgICBpZih4PT1lKSBjb250aW51ZTsKICAgICAgICAgICAgICAgICAgIGlmKGRwW3hdPT1kcFtzXS0xKSAKICAgICAgICAgICAgICAgICAgIGRmczEoeCxzKTsKICAgICAgICAgICAgICAgICAgIAogICAgICAgICB9Cn0KaW50IG1haW4oKQp7CiAgICAjaWYgZGVmaW5lZChfREVCVUcpCglmcmVvcGVuKCJpbnB1dC50eHQiLCAiciIsIHN0ZGluKTsKCWZyZW9wZW4oIm91dHB1dC50eHQiLCAidyIsIHN0ZG91dCk7CiAgICAjZW5kaWYKIHByZXNzX0ZfdG9fcGF5X3Jlc3BlY3Q7CiAvLyBjb3V0IDw8IGZpeGVkIDw8IHNldHByZWNpc2lvbigxMikgPDwgYW5zOwogLy8gc3RyaW5nIGFsID0gImFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6IjsKIGludCBxdWVzdGlvbnM9MTsKIC8vIGNpbj4+cXVlc3Rpb25zOwogd2hpbGUocXVlc3Rpb25zLS0pCiB7CiAgICAgICAgICAgaW50IG47CiAgICAgICBjaW4+Pm47CiAgICAgICBpZihuPT0xKQogICAgICAgewogICAgICAgICAgICAgICAgIGNvdXQ8PDE7CiAgICAgICAgICAgICAgICAgcmV0dXJuIDA7CiAgICAgICB9CiAgICAgYWRqLnJlc2l6ZShuKzIpOwogICAgIGRwLnJlc2l6ZShuKzIpOwogICAgIGcucmVzaXplKG4rMik7CiAgICAgbm9kZXMucmVzaXplKG4rMik7CiAgICAgaW50IHo9bi0xOwogICAgIHdoaWxlKHotLSkKICAgICB7CiAgICAgICAgICAgICAgIGludCBhLGI7CiAgICAgICAgICAgICAgIGNpbj4+YT4+YjsKICAgICAgICAgICAgICAgYWRqW2FdLnBiKGIpOwogICAgICAgICAgICAgICBhZGpbYl0ucGIoYSk7CiAgICAgfQogICAgIGRmcygxLDApOwogICAgIHZlY3RvcjxsbD4gZD1kcDsKICAgICAvLyB3ZSBoYXZlIGZvdW5kIGRpYW0gPT0gdHJlZSBkaWFtZXRlciAKICAgICBmb3IoaW50IGk9MTtpPD1uO2krKykKICAgICB7CiAgICAgICAgICAgICAgIGlmKGdbaV09PWRpYW0pCiAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICAgIGRwLmNsZWFyKCk7CiAgICAgICAgICAgICAgICAgICAgICAgICBkcC5yZXNpemUobisyKTsKICAgICAgICAgICAgICAgICAgICAgICAgIGcuY2xlYXIoKTsKICAgICAgICAgICAgICAgICAgICAgICAgIGcucmVzaXplKG4rMik7CiAgICAgICAgICAgICAgICAgICAgICAgICAvLyBub3cgbGV0cyByb290IHRoZSB0cmVlIG9uIG5vZGUgaSBhbmQgY291bnQgZHAgYW5kIGcgdmVjdG9ycwogICAgICAgICAgICAgICAgICAgICAgICAgZGZzKGksMCk7CiAgICAgICAgICAgICAgICAgICAgICAgICB2ZWN0b3I8aW50PiB2YWw7CiAgICAgICAgICAgICAgICAgICAgICAgICAvLyBhZGQgaW4gdmVjdG9yPGludD4gdmFsIGFsbCBkcCB2YWx1ZXMgZnJvbSBvdGhlciBub2RlcwogICAgICAgICAgICAgICAgICAgICAgICAgZm9yKGF1dG8geDogYWRqW2ldKSB2YWwucGIoZHBbeF0pOwogICAgICAgICAgICAgICAgICAgICAgICAgLy8gdGhlbiBjaG9vc2UgdHdvIG1heGltdW0KICAgICAgICAgICAgICAgICAgICAgICAgIHNvcnQoYWxsKHZhbCkpOwogICAgICAgICAgICAgICAgICAgICAgICAgaW50IG14PXZhbC5iYWNrKCk7CiAgICAgICAgICAgICAgICAgICAgICAgICBpbnQgbXgxPXZhbFt2YWwuc2l6ZSgpLTJdOwogICAgICAgICAgICAgICAgICAgICAgICAgLy8gdGhlbiBkbyBkZnMxIHRvIGZpbmQgbGVhdmVzIAogICAgICAgICAgICAgICAgICAgICAgICAgZm9yKGF1dG8geDogYWRqW2ldKQogICAgICAgICAgICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmKGRwW3hdPT1teCB8fCBkcFt4XT09bXgxKSBkZnMxKHgsMCk7CiAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAvLyBpZiB3ZSBoYXZlIGZvdW5kIG5lZWRlZCBub2RlcyB3cml0ZSB0aGVtCiAgICAgICAgICAgICAgIH0KICAgICB9CiAgICAgZHA9ZDsKICAgICAvLyBvdGhlcndpc2UgdGhlIHRyZWUgaXMgcm9vdGVkIGluIG5vZGUgMSBhbmQgd2UgbmVlZCB0byBmaW5kIGxlYXZlcyBmcm9tIGhlcmUKICAgICBmb3IoaW50IGk9MTtpPD1uO2krKykKICAgICB7CiAgICAgICAgICAgICAgIGlmKGRwW2ldPT1kaWFtKQogICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgICAvLyBkZnMgZnJvbSBub2RlIGkKICAgICAgICAgICAgICAgICAgICAgICAgIC8vY291dDw8ImFhYTEiPDwiICI8PGk7CiAgICAgICAgICAgICAgICAgICAgICAgICBub2Rlc1tpXT10cnVlOwogICAgICAgICAgICAgICAgICAgICAgICAgZGZzMShpLDApOwogICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgIH0KICAgICB9CiAgICAgLy8gd2UgaGF2ZSBmb3VuZCB0aGUgYW5zd2VyLCBwcmludCBpdAogICAgIGZvcihpbnQgaT0xO2k8PW47aSsrKQogICAgIHsKICAgICAgICAgICAgICAgaWYobm9kZXNbaV0pIGNvdXQ8PGRpYW07CiAgICAgICAgICAgICAgIGVsc2UgY291dDw8ZGlhbS0xOwogICAgICAgICAgICAgICBrZWs7CiAgICAgfQogICAgIAogICAgIAogICAgIAogICAgIAogICAgICAgICAgCiAgICAgICAgICAgCiAgICAgICAgICAgCiAgICAgICAgICAgCiB9CiAKIAogCiAKIC8vICEhISBMT09LIEFUIE5VTUJFUiBPRiBRVUVTVElPTlMgSU4gQSBQUk9CTEVNICEhISAoY2luPj5xdWVzdGlvbnMpCiAKIAogCiAgLy8gY291dCA8PCJSdW50aW1lIGlzOiI8PGNsb2NrKCkgKiAxLjAgLyBDTE9DS1NfUEVSX1NFQyA8PGVuZGw7CiAgIHJldHVybiAwOwogICAKICAgCiAKfQ==