//
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=510000;
struct Node
{
int t;
int next;
};
int p[maxn];
Node G[maxn*2];
int l;
int ans[maxn];
int V,root;
void init()
{
memset(p,-1,sizeof(p));
memset(ans,0,sizeof(ans));
l=0;
}
void addedge(int u,int t,int l)
{
G[l].t=t;
G[l].next=p[u];
p[u]=l;
}
int c[maxn];
int n;
int lowbit(int x)
{
return x&(-x);
}
void update(int x,int val)
{
for(int i=x;i<=n;i+=lowbit(i))
{
c[i]+=val;
}
}
int getsum(int x)
{
if(x==0) return 0;
int cnt=0;
for(int i=x;i>=1;i-=lowbit(i))
{
cnt+=c[i];
}
return cnt;
}
int vis[maxn];
int stc[maxn];
int before[maxn];
int stp;
void calc()
{
memset(vis,0,sizeof(vis));
stp=0;
stc[++stp]=root;
while(stp>0)
{
int u=stc[stp];
if(vis[u]==0)
{
vis[u]=1;
before[u]=getsum(u-1);
for(int i=p[u];i!=-1;i=G[i].next)
{
int t=G[i].t;
if(vis[t]==0)
{
stc[++stp]=t;
}
}
continue;
}
int after=getsum(u-1);
ans[u]=after-before[u];
vis[u]=2;
stp--;
update(u,1);
}
}
int main()
{
while(scanf("%d%d",&V,&root)==2&&V)
{
init();n=V;
for(int i=0;i<V-1;i++)
{
int u,t;scanf("%d%d",&u,&t);
addedge(u,t,l++);
addedge(t,u,l++);
}
calc();
printf("%d",ans[1]);
for(int i=2;i<=V;i++) printf(" %d",ans[i]);printf("\n");
}
return 0;
}