#include <iostream>
#include <vector>
#include <cstdio>
#include <stack>
#define si(a) scanf("%d",&a)

using namespace std;

vector<vector<int> > graph;
int par[3005],p=-1,q,D,hu;
bool is[3005];
stack<int> _p,_q;
int dis[3005];

void dfs(int from,int now)
{
    //cout<<from<<" "<<now<<endl;
    is[now]=true;
    par[now]=from;
    int i,len=graph[now].size();
    for(i=0;i<len;i++){
        if(graph[now][i]==from)
            continue;
        if(is[graph[now][i]]){
            if(p==-1){
                p=now;
                q=graph[now][i];
            }
            continue;
        }
        dfs(now,graph[now][i]);
    }
    return ;
}

void distance(int from,int now,int dist)
{
    if(dis[now]!=-1){
        D=dist+dis[now];
        hu=1;
        return ;
    }
    if(is[now]){
        hu=1;
        D=dist;
        return ;
    }
    int i,len=graph[now].size();
    for(i=0;i<len;i++){
        if(graph[now][i]==from)
            continue;
        distance(now,graph[now][i],dist+1);
        if(hu)
            return ;
    }
    return ;
}

int main()
{
    //freopen("input.txt","r",stdin);
    int n,i;
    si(n);
    vector<int> t;
    for(i=0;i<n;i++)
        graph.push_back(t);
    for(i=0;i<n;i++){
        int x,y;
        si(x);
        si(y);
        graph[x-1].push_back(y-1);
        graph[y-1].push_back(x-1);
    }
    for(i=0;i<n;i++)
        is[i]=false;
    dfs(-1,0);
    for(i=0;i<n;i++)
        is[i]=false;
    is[p]=true,is[q]=true;
    i=p;
    while(par[i]!=q){
        is[par[i]]=true;
        i=par[i];
    }
    for(i=0;i<n;i++)
        dis[i]=-1;
    for(i=0;i<n;i++){
        D=0;
        hu=0;
        distance(-1,i,0);
        dis[i]=D;
        printf("%d ",D);
    }
    printf("\n");
    return 0;
}


#include <bits/stdc++.h>
#define LL long long
#define mp make_pair
#define pb push_back
using namespace std;

LL n,d[5000],point;
bool cycle[5000]={0},visited[5000];
vector<LL> graph[5000];

bool dfs(LL u,LL parent){
	visited[u]=1;
	for(int i=0;i<graph[u].size();i++){
		LL v = graph[u][i];
		if(v==parent) continue;
		if(!visited[v]){
			if(dfs(v,u) && point!=v){
				cycle[u]=1;
				return true;
			}
		}
		else if(v!=parent && !cycle[v]){
			cycle[v] = 1;
			cycle[u] = 1;
			point = v;
			return true;
		}
	}
	return false;
}

int main (){
	cin>>n;
	LL x,y,ans[5000]={0};
	queue<LL> q;
	for(int i=1;i<=n;i++){
		cin>>x>>y;
		d[i]=999999;
		graph[x].pb(y);
		graph[y].pb(x);
	}
	memset(visited,0,sizeof(visited));
	for(int i=1;i<=n;i++){
		if(!visited[i]){
			dfs(i,-1);
		}
	}
	for(int i=1;i<=n;i++){
		if(!cycle[i]){
			q.push(i);
			for(int j=1;j<=n;j++) d[j]=999999;
			d[i]=0;
			bool check=false;
			while(!q.empty()){
				x = q.front();
				q.pop();
				for(int j=0;j<graph[x].size();j++){
					y = graph[x][j];
					if(d[x]+1<d[y]){
						d[y]=d[x]+1;
						if(cycle[y]){
							ans[i] = d[y];
							check=true;
							break;
						}
						q.push(y);
					}
				}
				if(check) break;
			}
		}
	}
	for(int i=1;i<=n;i++){
		if(i>1) cout<<" ";
		if(cycle[i]) cout<<"0";
		else cout<<ans[i];
	}

    return 0;
}


#include <bits/stdc++.h>
#define LL long long
#define mp make_pair
#define pb push_back
using namespace std;

LL n,d[5000],point;
bool cycle[5000]={0},visited[5000];
vector<LL> graph[5000];

bool dfs(LL u,LL parent){
	visited[u]=1;
	for(int i=0;i<graph[u].size();i++){
		LL v = graph[u][i];
		if(v==parent) continue;
		if(!visited[v]){
			if(dfs(v,u) && point!=v){
				cycle[u]=1;
				return true;
			}
		}
		else if(v!=parent){
			cycle[v] = 1;
			cycle[u] = 1;
			point = v;
			return true;
		}
	}
	return false;
}

int main (){
	cin>>n;
	LL x,y,ans[5000]={0};
	queue<LL> q;
	for(int i=1;i<=n;i++){
		cin>>x>>y;
		d[i]=999999;
		graph[x].pb(y);
		graph[y].pb(x);
	}
	memset(visited,0,sizeof(visited));
	for(int i=1;i<=n;i++){
		if(!visited[i]){
			if(dfs(i,-1)) break;
		}
	}
	for(int i=1;i<=n;i++){
		if(!cycle[i]){
			q.push(i);
			for(int j=1;j<=n;j++) d[j]=999999;
			d[i]=0;
			bool check=false;
			while(!q.empty()){
				x = q.front();
				q.pop();
				for(int j=0;j<graph[x].size();j++){
					y = graph[x][j];
					if(d[x]+1<d[y]){
						d[y]=d[x]+1;
						if(cycle[y]){
							ans[i] = d[y];
							check=true;
							break;
						}
						q.push(y);
					}
				}
				if(check) break;
			}
		}
	}
	for(int i=1;i<=n;i++){
		if(i>1) cout<<" ";
		if(cycle[i]) cout<<"0";
		else cout<<ans[i];
	}

    return 0;
}


#include <bits/stdc++.h>
#define LL long long
#define mp make_pair
#define pb push_back
using namespace std;

LL n,d[5000];
bool cycle[5000]={0},visited[5000];
vector<LL> graph[5000];

bool dfs(LL u,LL parent){
	visited[u]=1;
	for(int i=0;i<graph[u].size();i++){
		LL v = graph[u][i];
		if(!visited[v]){
			if(dfs(v,u)){
				cycle[v] = 1;
				cycle[u] = 1;
			return true;
			}
		}
		else if(v!=parent){
			cycle[v] = 1;
			cycle[u] = 1;
			return true;
		}
	}
	return false;
}

int main (){
	cin>>n;
	LL x,y,ans[5000]={0};
	queue<LL> q;
	for(int i=1;i<=n;i++){
		cin>>x>>y;
		d[i]=999999;
		graph[x].pb(y);
		graph[y].pb(x);
	}
	memset(visited,0,sizeof(visited));
	for(int i=1;i<=n;i++){
		if(!visited[i]){
			if(dfs(i,-1)) break;
		}
	}
	for(int i=1;i<=n;i++){
		if(!cycle[i]){
			q.push(i);
			for(int j=1;j<=n;j++) d[j]=999999;
			d[i]=0;
			bool check=false;
			while(!q.empty()){
				x = q.front();
				q.pop();
				for(int j=0;j<graph[x].size();j++){
					y = graph[x][j];
					if(d[x]+1<d[y]){
						d[y]=d[x]+1;
						if(cycle[y]){
							ans[i] = d[y];
							check=true;
							break;
						}
						q.push(y);
					}
				}
				if(check) break;
			}
		}
	}
	for(int i=1;i<=n;i++){
		if(i) cout<<" ";
		if(cycle[i]) cout<<"0";
		else cout<<ans[i];
	}

    return 0;
}


#include<bits/stdc++.h>
#define pb push_back
#define pob pop_back
#define bs binary_search
#define mp make_pair
#define F first
#define S second
#define It iterator
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define rint register int
#define en "\n"
#define br break
#define con continue
#define fri(n) for(register int i=0;i<n;i++)
#define frj(n) for(register int j=0;j<n;j++)
#define T(i) int i=1;cin>>i;while(i--)
#define fast ios_base::sync_with_stdio(0);cin.tie();cout.tie();
#define C(i) int i=1;cin>>i;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi>vii;
typedef map<int,int> mi;
typedef set<int> S;
typedef list<int> L;
typedef stack<int> St;
typedef queue<int> Qu;
typedef deque<int> Dq;
typedef map<string,int> msi;
vi res;
int dfs(int x,vi v[],vi &vis,int parent)
{
    vis[x]=1;
    res.pb(x);
    fri(v[x].size())
    {
        if(vis[v[x][i]]==0){
           int temp=dfs(v[x][i],v,vis,x);
           if(temp!=-1)return temp;
        }
        else{
            if(v[x][i]!=parent){
                res.pb(v[x][i]);
                return v[x][i];
            }
        }
    }
    res.pob();
    return -1;
}
void solve(int x,vi v[],vi &vis,vi &d,int parent)
{
    vis[x]=1;
    if(d[x]==-1)d[x]=d[parent]+1;
    fri(v[x].size()){
        if(vis[v[x][i]]==0){
            solve(v[x][i],v,vis,d,x);
        }
    }
}
int main()
{
    fast;
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    C(n);
    vi v[n];
    fri(n)
    {
        C(x);C(y);
        x--;y--;
        v[x].pb(y);
        v[y].pb(x);
    }
    vi vis(n),st(n);
    int a=dfs(0,v,vis,-1);
    //cout<<res.size()<<" ";
    mi m;
    for(int i=res.size()-1;i>=0;i--){
        if(m[res[i]]==0)m[res[i]]++;
        else break;
    }
    vi d(n),ring;
    fri(n)d[i]=-1;
    fri(n){
        if(m[i]!=0){
            d[i]=0;
            ring.pb(i);
        }
    }
    fri(n)vis[i]=0;
    //cout<<ring.size()<<" ";
    fri(ring.size())
    {
        solve(ring[i],v,vis,d,-1);
    }
    fri(n)cout<<d[i]<<" ";
}


#include<bits/stdc++.h>
#define pb push_back
#define pob pop_back
#define bs binary_search
#define mp make_pair
#define F first
#define S second
#define It iterator
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define rint register int
#define en "\n"
#define br break
#define con continue
#define fri(n) for(register int i=0;i<n;i++)
#define frj(n) for(register int j=0;j<n;j++)
#define T(i) int i=1;cin>>i;while(i--)
#define fast ios_base::sync_with_stdio(0);cin.tie();cout.tie();
#define C(i) int i=1;cin>>i;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi>vii;
typedef map<int,int> mi;
typedef set<int> S;
typedef list<int> L;
typedef stack<int> St;
typedef queue<int> Qu;
typedef deque<int> Dq;
typedef map<string,int> msi;
vi res;
int dfs(int x,vi v[],vi &vis,int parent)
{
    vis[x]=1;
    res.pb(x);
    fri(v[x].size())
    {
        if(vis[v[x][i]]==0){
           int temp=dfs(v[x][i],v,vis,x);
           if(temp!=-1)return temp;
        }
        else{
            if(v[x][i]!=parent)return v[x][i];
        }
    }
    res.pob();
    return -1;
}
void solve(int x,vi v[],vi &vis,vi &d,int parent)
{
    vis[x]=1;
    if(d[x]==-1)d[x]=d[parent]+1;
    fri(v[x].size()){
        if(vis[v[x][i]]==0){
            solve(v[x][i],v,vis,d,x);
        }
    }
}
int main()
{
    fast;
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    C(n);
    vi v[n];
    fri(n)
    {
        C(x);C(y);
        x--;y--;
        v[x].pb(y);
        v[y].pb(x);
    }
    vi vis(n),st(n);
    int a=dfs(0,v,vis,-1);
    //cout<<res.size();
    mi m;
    fri(res.size()){
        if(m[res[i]]==0)m[res[i]]++;
        else break;
    }
    vi d(n),ring;
    fri(n)d[i]=-1;
    fri(n){
        if(m[i]!=0){
            d[i]=0;
            ring.pb(i);
        }
    }
    fri(n)vis[i]=0;
    fri(ring.size())
    {
        solve(ring[i],v,vis,d,-1);
    }
    fri(n)cout<<d[i]<<" ";
}


/*...Bohot Zyada Mara Gaya Hai...*/
#include<bits/stdc++.h>
#define lli long long int
#define FOR(i,a,b) for(i=a;i<b;i++)
#define FORB(i,b,a) for(i=b;i>=a;i--)
#define mod 1000000007
#define PI 2*acos(0.0)
#define gs getline(cin,s)
#define pii pair<int,int>
#define pli pair<long long int,int>
#define pll pair<long long int,long long int>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 1e9
#define INF 1e18
#define io ios_base::sync_with_stdio(0);
using namespace std;
int par[3001],vis[3001]={0},dist[3001]={0},cycle[3001]={0};
vector <int> adj[3001];
int flag=0;
int yahan=-1,shuru=-1;
pii dfs(int v)
{
    vis[v]=1;
    int i,sz=adj[v].size();
    if(yahan>-1 && shuru>-1)
        return {yahan,shuru};
    //int flag=0;
    FOR(i,0,sz)
    {
        int x=adj[v][i];
        if(vis[x] && par[v]!=x && flag==0)
        {
            yahan=v;
            shuru=x;
            flag=1;
            break;
            //cout<<yahan<<" "<<shuru<<"\n";
           // return {yahan,shuru};
        }
        if(vis[x])
            continue;
        if(yahan>-1 && shuru>-1)
            return {yahan,shuru};
        par[x]=v;
        dfs(x);
    }
    if(flag)
        return {yahan,shuru};
}
int main()
{
    io;
    int i,j,n,m,x,y;
    cin>>n;
    FOR(i,0,n)
    {
        cin>>x>>y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    par[1]=1;
    pii p=dfs(1);
    x=p.first,y=p.second;
   // cout<<x<<" "<<y;
    while(par[x]!=y)
    {
        cycle[x]=1;
        x=par[x];
    }
   // cout<<"fqcsa";
    cycle[x]=cycle[y]=1;
    queue <int> q;
    fill(vis,vis+n+1,0);
    FOR(i,1,n+1)
    {
        if(cycle[i])
        {
            q.push(i);
            vis[i]=1;
        }
    }
   // cout<<q.size();
    while(!q.empty())
    {
        x=q.front();
        q.pop();
        int sz=adj[x].size();
        FOR(i,0,sz)
        {
            y=adj[x][i];
            if(vis[y])
                continue;
            vis[y]=1;
            dist[y]=dist[x]+1;
            q.push(y);
        }
    }
    FOR(i,1,n+1)
    {
        if(cycle[i])
        {
            cout<<0<<" ";
            continue;
        }
        cout<<dist[i]<<" ";
    }
    return 0;
}


/*...Bohot Zyada Mara Gaya Hai...*/
#include<bits/stdc++.h>
#define lli long long int
#define FOR(i,a,b) for(i=a;i<b;i++)
#define FORB(i,b,a) for(i=b;i>=a;i--)
#define mod 1000000007
#define PI 2*acos(0.0)
#define gs getline(cin,s)
#define pii pair<int,int>
#define pli pair<long long int,int>
#define pll pair<long long int,long long int>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 1e9
#define INF 1e18
#define io ios_base::sync_with_stdio(0);
using namespace std;
int par[1001],vis[1001]={0},dist[1001]={inf},cycle[1001]={0};
vector <int> adj[1001];
int yahan=-1,shuru=-1;
pii dfs(int v)
{
    vis[v]=1;
    int i,sz=adj[v].size();
    if(yahan>-1 && shuru>-1)
    return {yahan,shuru};
    FOR(i,0,sz)
    {
        int x=adj[v][i];
        if(vis[x] && par[v]!=x)
        {
            yahan=v;
            shuru=x;
            return {yahan,shuru};
        }
        if(vis[x])
            continue;
        par[x]=v;
        dfs(x);
    }
}
int main()
{
   // io;
    int i,j,n,m,x,y;
    cin>>n;
    FOR(i,0,n)
    {
        cin>>x>>y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    par[1]=1;
    pii p=dfs(1);
  //  cout<<x;
    x=p.first,y=p.second;
    swap(x,y);
  //  cout<<x<<" "<<y;
    while(par[x]!=y)
    {
        cycle[x]=1;
        x=par[x];
    }
   // cout<<"fqcsa";
    cycle[x]=cycle[y]=1;
    queue <int> q;
    fill(dist,dist+n+1,inf);
    FOR(j,1,n+1)
    {
        if(cycle[j]==0)
            continue;
        fill(vis,vis+n+1,0);
        q.push(j);
        dist[j]=0;
        vis[j]=1;
        while(!q.empty())
        {
            x=q.front();
            q.pop();
            int sz=adj[x].size();
            FOR(i,0,sz)
            {
                y=adj[x][i];
                if(vis[y])
                    continue;
                vis[y]=1;
                dist[y]=min(dist[y],dist[x]+1);
                q.push(y);
            }
        }
    }
    FOR(i,1,n+1)
    cout<<dist[i]<<" ";
    return 0;
}


/*...Bohot Zyada Mara Gaya Hai...*/
#include<bits/stdc++.h>
#define lli long long int
#define FOR(i,a,b) for(i=a;i<b;i++)
#define FORB(i,b,a) for(i=b;i>=a;i--)
#define mod 1000000007
#define PI 2*acos(0.0)
#define gs getline(cin,s)
#define pii pair<int,int>
#define pli pair<long long int,int>
#define pll pair<long long int,long long int>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 1e9
#define INF 1e18
#define io ios_base::sync_with_stdio(0);
using namespace std;
int par[3001],vis[3001]={0},dist[3001],cycle[3001]={0};
vector <int> adj[3001];
int yahan=-1,shuru=-1;
pii dfs(int v)
{
    vis[v]=1;
    int i,sz=adj[v].size();
    if(yahan>-1 && shuru>-1)
    return {yahan,shuru};
    FOR(i,0,sz)
    {
        int x=adj[v][i];
        if(vis[x] && par[v]!=x)
        {
            yahan=v;
            shuru=x;
            return {yahan,shuru};
        }
        if(vis[x])
            continue;
        par[x]=v;
        dfs(x);
    }
}
int main()
{
   // io;
    int i,j,n,m,x,y;
    cin>>n;
    FOR(i,0,n)
    {
        cin>>x>>y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    par[1]=1;
    pii p=dfs(1);
  //  cout<<x;
    x=p.first,y=p.second;
    swap(x,y);
  //  cout<<x<<" "<<y;
    while(par[x]!=y)
    {
        cycle[x]=1;
        x=par[x];
    }
   // cout<<"fqcsa";
    cycle[x]=cycle[y]=1;
    queue <int> q;
    fill(dist,dist+n+1,inf);
    FOR(j,1,n+1)
    {
        if(cycle[j]==0)
            continue;
        fill(vis,vis+n+1,0);
        q.push(j);
        dist[j]=0;
        vis[j]=1;
        while(!q.empty())
        {
            x=q.front();
            q.pop();
            int sz=adj[x].size();
            FOR(i,0,sz)
            {
                y=adj[x][i];
                if(vis[y])
                    continue;
                vis[y]=1;
                dist[y]=min(dist[y],dist[x]+1);
                q.push(y);
            }
        }
    }
    FOR(i,1,n+1)
    cout<<dist[i]<<" ";
    return 0;
}


/*...Bohot Zyada Mara Gaya Hai...*/
#include<bits/stdc++.h>
#define lli long long int
#define FOR(i,a,b) for(i=a;i<b;i++)
#define FORB(i,b,a) for(i=b;i>=a;i--)
#define mod 1000000007
#define PI 2*acos(0.0)
#define gs getline(cin,s)
#define pii pair<int,int>
#define pli pair<long long int,int>
#define pll pair<long long int,long long int>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 1e9
#define INF 1e18
#define io ios_base::sync_with_stdio(0);
using namespace std;
int par[3001],vis[3001]={0},dist[3001]={0},cycle[3001]={0};
vector <int> adj[3001];
int flag=0;
int yahan=-1,shuru=-1;
pii dfs(int v)
{
    vis[v]=1;
    int i,sz=adj[v].size();
    if(yahan>-1 && shuru>-1)
        return {yahan,shuru};
    //int flag=0;
    FOR(i,0,sz)
    {
        int x=adj[v][i];
        if(vis[x] && par[v]!=x && flag==0)
        {
            yahan=v;
            shuru=x;
            flag=1;
            break;
            //cout<<yahan<<" "<<shuru<<"\n";
           // return {yahan,shuru};
        }
        if(vis[x])
            continue;
        if(yahan>-1 && shuru>-1)
            return {yahan,shuru};
        par[x]=v;
        dfs(x);
    }
    if(flag)
        return {yahan,shuru};
}
int main()
{
    io;
    int i,j,n,m,x,y;
    cin>>n;
    FOR(i,0,n)
    {
        cin>>x>>y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    par[1]=1;
    pii p=dfs(1);
    x=p.first,y=p.second;
   // cout<<x<<" "<<y;
    while(par[x]!=y)
    {
        cycle[x]=1;
        x=par[x];
    }
   // cout<<"fqcsa";
    cycle[x]=cycle[y]=1;
    queue <int> q;
    fill(vis,vis+n+1,0);
    FOR(i,1,n+1)
    {
        if(cycle[i])
        {
            q.push(i);
            vis[i]=1;
        }
    }
   // cout<<q.size();
    while(!q.empty())
    {
        x=q.front();
        q.pop();
        int sz=adj[x].size();
        FOR(i,0,sz)
        {
            y=adj[x][i];
            if(vis[y])
                continue;
            vis[y]=1;
            dist[y]=dist[x]+1;
            q.push(y);
        }
    }
    FOR(i,1,n+1)
    {
        if(cycle[i])
        {
            cout<<0<<" ";
            continue;
        }
        cout<<dist[i]<<" ";
    }
    return 0;
}
    cycle[x]=cycle[y]=1;
    queue <int> q;
    fill(vis,vis+n+1,0);
    FOR(i,1,n+1)
    {
        if(cycle[i])
        {
            q.push(i);
            vis[i]=1;
        }
    }
   // cout<<q.size();
    while(!q.empty())
    {
        x=q.front();
        q.pop();
        int sz=adj[x].size();
        FOR(i,0,sz)
        {
            y=adj[x][i];
            if(vis[y])
                continue;
            vis[y]=1;
            dist[y]=dist[x]+1;
            q.push(y);
        }
    }
    FOR(i,1,n+1)
    {
        if(cycle[i])
        {
            cout<<0<<" ";
            continue;
        }
        cout<<dist[i]<<" ";
    }
    return 0;
}


/*...Bohot Zyada Mara Gaya Hai...*/
#include<bits/stdc++.h>
#define lli long long int
#define FOR(i,a,b) for(i=a;i<b;i++)
#define FORB(i,b,a) for(i=b;i>=a;i--)
#define mod 1000000007
#define PI 2*acos(0.0)
#define gs getline(cin,s)
#define pii pair<int,int>
#define pli pair<long long int,int>
#define pll pair<long long int,long long int>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 1e9
#define INF 1e18
#define io ios_base::sync_with_stdio(0);
using namespace std;
int par[3001],vis[3001]={0},dist[3001]={0},cycle[3001]={0};
vector <int> adj[3001];
int yahan=-1,shuru=-1;
pii dfs(int v)
{
    vis[v]=1;
    int i,sz=adj[v].size();
    if(yahan>-1 && shuru>-1)
        return {yahan,shuru};
    FOR(i,0,sz)
    {
        int x=adj[v][i];
        if(vis[x] && par[v]!=x )
        {
            yahan=v;
            shuru=x;
            //flag=1;
            break;
        }
        if(vis[x])
            continue;
        if(yahan>-1 && shuru>-1)
            return {yahan,shuru};
        par[x]=v;
        dfs(x);
    }
    if(yahan>-1 && shuru>-1)
        return {yahan,shuru};
}
int main()
{
   // io;
    int i,j,n,m,x,y;
    cin>>n;
    FOR(i,0,n)
    {
        cin>>x>>y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    par[1]=1;
    pii p=dfs(1);
    x=p.first,y=p.second;
  //  cout<<x<<" "<<y;
    while(par[x]!=y)
    {
        cycle[x]=1;
        x=par[x];
    }
   // cout<<"fqcsa";
    cycle[x]=cycle[y]=1;
    queue <int> q;
    fill(vis,vis+n+1,0);
    FOR(i,1,n+1)
    {
        if(cycle[i])
        {
            q.push(i);
            vis[i]=1;
        }
    }
   // cout<<q.size();
    while(!q.empty())
    {
        x=q.front();
        q.pop();
        int sz=adj[x].size();
        FOR(i,0,sz)
        {
            y=adj[x][i];
            if(vis[y])
                continue;
            vis[y]=1;
            dist[y]=dist[x]+1;
            q.push(y);
        }
    }
    FOR(i,1,n+1)
    {
        if(cycle[i])
        {
            cout<<0<<" ";
            continue;
        }
        cout<<dist[i]<<" ";
    }
    return 0;
}


/*...Bohot Zyada Mara Gaya Hai...*/
#include<bits/stdc++.h>
#define lli long long int
#define FOR(i,a,b) for(i=a;i<b;i++)
#define FORB(i,b,a) for(i=b;i>=a;i--)
#define mod 1000000007
#define PI 2*acos(0.0)
#define gs getline(cin,s)
#define pii pair<int,int>
#define pli pair<long long int,int>
#define pll pair<long long int,long long int>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 1e9
#define INF 1e18
#define io ios_base::sync_with_stdio(0);
using namespace std;
int par[3001],vis[3001]={0},dist[3001],cycle[3001]={0};
vector <int> adj[3001];
int yahan=-1,shuru=-1;
pii dfs(int v)
{
    vis[v]=1;
    int i,sz=adj[v].size();
    if(yahan>-1 && shuru>-1)
    return {yahan,shuru};
    FOR(i,0,sz)
    {
        int x=adj[v][i];
        if(vis[x] && par[v]!=x)
        {
            yahan=v;
            shuru=x;
            return {yahan,shuru};
        }
        if(vis[x])
            continue;
        par[x]=v;
        dfs(x);
    }
}
int main()
{
   // io;
    int i,j,n,m,x,y;
    cin>>n;
    FOR(i,0,n)
    {
        cin>>x>>y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    par[1]=1;
    pii p=dfs(1);
  //  cout<<x;
    x=p.first,y=p.second;
    swap(x,y);
  //  cout<<x<<" "<<y;
    while(par[x]!=y)
    {
        cycle[x]=1;
        x=par[x];
    }
   // cout<<"fqcsa";
    cycle[x]=cycle[y]=1;
    queue <int> q;
    fill(dist,dist+n+1,inf);
    FOR(j,1,n+1)
    {
        if(cycle[j]==0)
            continue;
        fill(vis,vis+n+1,0);
        q.push(j);
        dist[j]=0;
        vis[j]=1;
        while(!q.empty())
        {
            x=q.front();
            q.pop();
            int sz=adj[x].size();
            FOR(i,0,sz)
            {
                y=adj[x][i];
                if(vis[y])
                    continue;
                vis[y]=1;
                dist[y]=min(dist[y],dist[x]+1);
                q.push(y);
            }
        }
    }
    FOR(i,1,n+1)
    {
        if(cycle[i])
        {
            cout<<0<<" ";
            continue;
        }
        cout<<dist[i]<<" ";
    }
    return 0;
}


/*...Bohot Zyada Mara Gaya Hai...*/
#include<bits/stdc++.h>
#define lli long long int
#define FOR(i,a,b) for(i=a;i<b;i++)
#define FORB(i,b,a) for(i=b;i>=a;i--)
#define mod 1000000007
#define PI 2*acos(0.0)
#define gs getline(cin,s)
#define pii pair<int,int>
#define pli pair<long long int,int>
#define pll pair<long long int,long long int>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 1e9
#define INF 1e18
#define io ios_base::sync_with_stdio(0);
using namespace std;
int par[3001],vis[3001]={0},dist[3001]={0},cycle[3001]={0};
vector <int> adj[3001];
int flag=0;
int yahan=-1,shuru=-1;
pii dfs(int v)
{
    vis[v]=1;
    int i,sz=adj[v].size();
    if(yahan>-1 && shuru>-1)
        return {yahan,shuru};
    //int flag=0;
    FOR(i,0,sz)
    {
        int x=adj[v][i];
        if(vis[x] && par[v]!=x && flag==0)
        {
            yahan=v;
            shuru=x;
            flag=1;
            break;
            //cout<<yahan<<" "<<shuru<<"\n";
           // return {yahan,shuru};
        }
        if(vis[x])
            continue;
        if(yahan>-1 && shuru>-1)
            return {yahan,shuru};
        par[x]=v;
        dfs(x);
    }
    if(flag)
        return {yahan,shuru};
}
int main()
{
   // io;
    int i,j,n,m,x,y;
    cin>>n;
    FOR(i,0,n)
    {
        cin>>x>>y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    par[1]=1;
    pii p=dfs(1);
    x=p.first,y=p.second;
   // cout<<x<<" "<<y;
    while(par[x]!=y)
    {
        cycle[x]=1;
        x=par[x];
    }
   // cout<<"fqcsa";
    cycle[x]=cycle[y]=1;
    queue <int> q;
    fill(vis,vis+n+1,0);
    FOR(i,1,n+1)
    {
        if(cycle[i])
        {
            q.push(i);
            vis[i]=1;
        }
    }
   // cout<<q.size();
    while(!q.empty())
    {
        x=q.front();
        q.pop();
        int sz=adj[x].size();
        FOR(i,0,sz)
        {
            y=adj[x][i];
            if(vis[y])
                continue;
            vis[y]=1;
            dist[y]=dist[x]+1;
            q.push(y);
        }
    }
    FOR(i,1,n+1)
    {
        if(cycle[i])
        {
            cout<<0<<" ";
            continue;
        }
        cout<<dist[i]<<" ";
    }
    return 0;
}


/*...Bohot Zyada Mara Gaya Hai...*/
#include<bits/stdc++.h>
#define lli long long int
#define FOR(i,a,b) for(i=a;i<b;i++)
#define FORB(i,b,a) for(i=b;i>=a;i--)
#define mod 1000000007
#define PI 2*acos(0.0)
#define gs getline(cin,s)
#define pii pair<int,int>
#define pli pair<long long int,int>
#define pll pair<long long int,long long int>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 1e9
#define INF 1e18
#define io ios_base::sync_with_stdio(0);
using namespace std;
int par[1001],vis[1001]={0},dist[1001],cycle[1001]={0};
vector <int> adj[1001];
int yahan=-1,shuru=-1;
pii dfs(int v)
{
    vis[v]=1;
    int i,sz=adj[v].size();
    if(yahan>-1 && shuru>-1)
    return {yahan,shuru};
    FOR(i,0,sz)
    {
        int x=adj[v][i];
        if(vis[x] && par[v]!=x)
        {
            yahan=v;
            shuru=x;
            return {yahan,shuru};
        }
        if(vis[x])
            continue;
        par[x]=v;
        dfs(x);
    }
}
int main()
{
   // io;
    int i,j,n,m,x,y;
    cin>>n;
    FOR(i,0,n)
    {
        cin>>x>>y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    par[1]=1;
    pii p=dfs(1);
  //  cout<<x;
    x=p.first,y=p.second;
    swap(x,y);
  //  cout<<x<<" "<<y;
    while(par[x]!=y)
    {
        cycle[x]=1;
        x=par[x];
    }
   // cout<<"fqcsa";
    cycle[x]=cycle[y]=1;
    queue <int> q;
    fill(dist,dist+n+1,inf);
    FOR(j,1,n+1)
    {
        if(cycle[j]==0)
            continue;
        fill(vis,vis+n+1,0);
        q.push(j);
        dist[j]=0;
        vis[j]=1;
        while(!q.empty())
        {
            x=q.front();
            q.pop();
            int sz=adj[x].size();
            FOR(i,0,sz)
            {
                y=adj[x][i];
                if(vis[y])
                    continue;
                vis[y]=1;
                dist[y]=min(dist[y],dist[x]+1);
                q.push(y);
            }
        }
    }
    FOR(i,1,n+1)
    cout<<dist[i]<<" ";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
vector<int> adj[3002];
bool vis[3002];
bool isCycle[3002];
stack<int> recu;

int dist[3002];
void dfs(int s,int p)
{
    for(int node:adj[s])
    {
        if(isCycle[node] ||node==p)
            continue;
        dist[node]=dist[s]+1;
        dfs(node,s);
    }
}
bool noDFS = false;
void dfsCycle(int s,int p)
{
    recu.push(s);
    vis[s]=1;
    for(int node:adj[s])
    {
        if(node==p)
            continue;
        if(vis[node]==false && noDFS==false)
            dfsCycle(node,s);

        else if(vis[node]) // cyclic
        {
            noDFS =true;
            // node starts the cycle
            while(!recu.empty()&&recu.top()!=node)
            {
                isCycle[recu.top()]=true;
                recu.pop();
            }
            isCycle[recu.top()]=true;
        }
    }
    recu.pop();
    vis[s]=0;
}
int main()
{
    int n;
    int i;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        int x,y;
        cin>>x>>y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    dfsCycle(1,-1);
    for(i=1;i<=n;i++)
        if(isCycle[i])
            dfs(i,-1);
    for(i=1;i<=n;i++)
        cout<<dist[i]<<" ";

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
vector<int> adj[3002];
bool vis[3002];
bool isCycle[3002];
stack<int> rec;

int dist[3002];
void dfs(int s,int p)
{
    for(int node:adj[s])
    {
        if(isCycle[node] ||node==p)
            continue;
        dist[node]=dist[s]+1;
        dfs(node,s);
    }
}
bool noDFS = false;
void dfsCycle(int s,int p)
{
    rec.push(s);
    vis[s]=1;
    for(int node:adj[s])
    {
        if(node==p)
            continue;
        if(vis[node]==false && noDFS==false)
            dfsCycle(node,s);

        else if(vis[node]) // cyclic
        {
            noDFS =true;
            // node starts the cycle
            while(rec.top()!=node)
            {
                isCycle[rec.top()]=true;
                rec.pop();
            }
            isCycle[rec.top()]=true;
        }
    }
    rec.pop();
    vis[s]=0;
}
int main()
{
    int n;
    int i;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        int x,y;
        cin>>x>>y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    dfsCycle(1,-1);

    for(int i=1;i<=n;i++)
        if(isCycle[i])
            cout<<i<<" ";
    cout<<"\n";
    for(i=1;i<=n;i++)
        if(isCycle[i])
            dfs(i,-1);
    for(i=1;i<=n;i++)
        cout<<dist[i]<<" ";

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
vector<int> adj[3002];
bool vis[3002];
bool isCycle[3002];
stack<int, vector<int> > recu;

int dist[3002];
void dfs(int s,int p)
{
    for(int node:adj[s])
    {
        if(isCycle[node] ||node==p)
            continue;
        dist[node]=dist[s]+1;
        dfs(node,s);
    }
}
bool noDFS = false;
void dfsCycle(int s,int p)
{
    recu.push(s);
    vis[s]=1;
    for(int node:adj[s])
    {
        if(node==p)
            continue;
        if(vis[node]==false && noDFS==false)
            dfsCycle(node,s);

        else if(vis[node]) // cyclic
        {
            noDFS =true;
            // node starts the cycle
            while(!recu.empty()&&recu.top()!=node)
            {
                isCycle[recu.top()]=true;
                recu.pop();
            }
            isCycle[recu.top()]=true;
        }
    }
    recu.pop();
    vis[s]=0;
}
int main()
{
    int n;
    int i;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        int x,y;
        cin>>x>>y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    dfsCycle(1,-1);
    for(i=1;i<=n;i++)
        if(isCycle[i])
            dfs(i,-1);
    for(i=1;i<=n;i++)
        cout<<dist[i]<<" ";

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
vector<int> adj[3002];
bool vis[3002];
bool isCycle[3002];
stack<int> rec;

int dist[3002];
void dfs(int s,int p)
{
    for(int node:adj[s])
    {
        if(isCycle[node] ||node==p)
            continue;
        dist[node]=dist[s]+1;
        dfs(node,s);
    }
}
bool noDFS = false;
void dfsCycle(int s,int p)
{
    rec.push(s);
    vis[s]=1;
    for(int node:adj[s])
    {
        if(node==p)
            continue;
        if(vis[node]==false && noDFS==false)
            dfsCycle(node,s);

        else if(vis[node]) // cyclic
        {
            noDFS =true;
            // node starts the cycle
            while(rec.top()!=node)
            {
                isCycle[rec.top()]=true;
                rec.pop();
            }
            isCycle[rec.top()]=true;
        }
    }
    rec.pop();
    vis[s]=0;
}
int main()
{
    int n;
    int i;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        int x,y;
        cin>>x>>y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    dfsCycle(1,-1);
    for(i=1;i<=n;i++)
        if(isCycle[i])
            dfs(i,-1);
    for(i=1;i<=n;i++)
        cout<<dist[i]<<" ";

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
vector<int> adj[3002];
bool vis[3002];
bool isCycle[3002];
stack<int> recu;

int dist[3002];
void dfs(int s,int p)
{
    for(int node:adj[s])
    {
        if(isCycle[node] ||node==p)
            continue;
        dist[node]=dist[s]+1;
        dfs(node,s);
    }
}
bool noDFS = false;
void dfsCycle(int s,int p)
{
    recu.push(s);
    vis[s]=1;
    for(int node:adj[s])
    {
        if(node==p)
            continue;
        if(vis[node]==false && noDFS==false)
            dfsCycle(node,s);

        else if(vis[node]) // cyclic
        {
            noDFS =true;
            // node starts the cycle
            while(recu.top()!=node)
            {
                isCycle[recu.top()]=true;
                recu.pop();
            }
            isCycle[recu.top()]=true;
        }
    }
    recu.pop();
    vis[s]=0;
}
int main()
{
    int n;
    int i;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        int x,y;
        cin>>x>>y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    dfsCycle(1,-1);
    for(i=1;i<=n;i++)
        if(isCycle[i])
            dfs(i,-1);
    for(i=1;i<=n;i++)
        cout<<dist[i]<<" ";

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
vector<int> adj[3002];
bool vis[3002];
bool isCycle[3002];
vector<int> rec;

int dist[3002];
void dfs(int s,int p)
{
    for(int node:adj[s])
    {
        if(isCycle[node] ||node==p)
            continue;
        dist[node]=dist[s]+1;
        dfs(node,s);
    }
}
bool noDFS = false;
void dfsCycle(int s,int p)
{
    rec.push_back(s);
    vis[s]=1;
    for(int node:adj[s])
    {
        if(node==p)
            continue;
        if(vis[node]==false && noDFS==false)
            dfsCycle(node,s);

        else if(vis[node]) // cyclic
        {
            noDFS =true;
            // node starts the cycle
            while( rec.size()&&rec.back()!=node)
            {
                isCycle[rec.back()]=true;
                rec.pop_back();
            }
            isCycle[rec.back()]=true;
        }
    }
    rec.pop_back();
    vis[s]=0;
}
int main()
{
    int n;
    int i;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        int x,y;
        cin>>x>>y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    dfsCycle(1,-1);
    for(i=1;i<=n;i++)
        if(isCycle[i])
            dfs(i,-1);
    for(i=1;i<=n;i++)
        cout<<dist[i]<<" ";

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e3 + 3;

int n;
vector< int > G[ MAXN ];

int par[ MAXN ];
int findAnyInCycle( int u, int fa ){
    par[ u ] = fa;
    for( int v : G[ u ] ){
        if( v == fa ) continue;
        if( par[ v ] != -1 ){
            par[ v ] = u;
            return v;
        }
        int res = findAnyInCycle( v, u );
        if( res ) return res;
    }
    return 0;
}

int dis[ MAXN ];

void solve(){
    memset( par, -1, sizeof(par) );
    int _u = findAnyInCycle( 1, -1 );
    queue< int > que;
    memset( dis, 0x3f3f3f3f, sizeof(dis) );
    for( int u = _u; ; ){
        que.push( u );
        dis[ u ] = 0;
        u = par[ u ];
        if( u == _u ) break;
    }
    while( !que.empty() ){
        int u = que.front();
        que.pop();
        for( int v : G[ u ] ){
            if( dis[ v ] > dis[ u ] + 1 )
                dis[ v ] = dis[ u ] + 1,
                que.push( v );
        }
    }
    for( int u = 1; u <= n; ++u )
        printf("%d%c", dis[ u ], u == n ? '\n' : ' ');
}

int main(){
    scanf("%d", &n);
    for( int i = 0; i < n; ++i ){
        int u, v; scanf("%d%d", &u, &v);
        G[ u ].push_back( v );
        G[ v ].push_back( u );
    }
    solve();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e3 + 3;

int n;
vector< int > G[ MAXN ];

int nxt[ MAXN ];
int findAnyInCycle( int u, int fa ){
    for( int v : G[ u ] ){
        if( v == fa ) continue;
        nxt[ u ] = v;
        if( nxt[ v ] != -1 ) return v;
        int res = findAnyInCycle( v, u );
        if( res ) return res;
    }
    return 0;
}

int dis[ MAXN ];

void solve(){
    memset( nxt, -1, sizeof(nxt) );
    int _u = findAnyInCycle( 1, -1 );
    // for( int u = 1; u <= n; ++u ) printf("par[ %d ] = %d\n", u, par[ u ]);
    queue< int > que;
    memset( dis, 0x3f3f3f3f, sizeof(dis) );
    for( int u = _u; ; ){
        que.push( u );
        dis[ u ] = 0;
        u = nxt[ u ];
        if( u == _u ) break;
    }
    while( !que.empty() ){
        int u = que.front();
        que.pop();
        for( int v : G[ u ] ){
            if( dis[ v ] > dis[ u ] + 1 )
                dis[ v ] = dis[ u ] + 1,
                que.push( v );
        }
    }
    for( int u = 1; u <= n; ++u )
        printf("%d%c", dis[ u ], u == n ? '\n' : ' ');
}

int main(){
    scanf("%d", &n);
    for( int i = 0; i < n; ++i ){
        int u, v; scanf("%d%d", &u, &v);
        G[ u ].push_back( v );
        G[ v ].push_back( u );
    }
    solve();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e3 + 3;

int n;
vector< int > G[ MAXN ];

int par[ MAXN ];
int findAnyInCycle( int u, int fa ){
    par[ u ] = fa;
    for( int v : G[ u ] ){
        if( v == fa ) continue;
        if( par[ v ] != -1 ){
            par[ v ] = u;
            return u;
        }
        int res = findAnyInCycle( v, u );
        if( res ) return res;
    }
    return 0;
}

int dis[ MAXN ];

void solve(){
    memset( par, -1, sizeof(par) );
    int _u = findAnyInCycle( 1, -1 );
    // for( int u = 1; u <= n; ++u ) printf("par[ %d ] = %d\n", u, par[ u ]);
    queue< int > que;
    memset( dis, 0x3f3f3f3f, sizeof(dis) );
    for( int u = _u; ; ){
        que.push( u );
        dis[ u ] = 0;
        u = par[ u ];
        if( u == _u ) break;
    }
    while( !que.empty() ){
        int u = que.front();
        que.pop();
        for( int v : G[ u ] ){
            if( dis[ v ] > dis[ u ] + 1 )
                dis[ v ] = dis[ u ] + 1,
                que.push( v );
        }
    }
    for( int u = 1; u <= n; ++u )
        printf("%d%c", dis[ u ], u == n ? '\n' : ' ');
}

int main(){
    scanf("%d", &n);
    for( int i = 0; i < n; ++i ){
        int u, v; scanf("%d%d", &u, &v);
        G[ u ].push_back( v );
        G[ v ].push_back( u );
    }
    solve();
    return 0;
}


#include <iostream>
#include <vector>
#include <cstdio>
#include <stack>
#define si(a) scanf("%d",&a)

using namespace std;

vector<vector<int> > graph;
int par[3005],p,q,D,hu;
bool is[3005];
stack<int> _p,_q;
int dis[3005];

void dfs(int from,int now)
{
    //cout<<from<<" "<<now<<endl;
    is[now]=true;
    par[now]=from;
    int i,len=graph[now].size();
    for(i=0;i<len;i++){
        if(graph[now][i]==from)
            continue;
        if(is[graph[now][i]]){
            p=now;
            q=graph[now][i];
            continue;
        }
        dfs(now,graph[now][i]);
    }
    return ;
}

void distance(int from,int now)
{
    if(dis[now]!=-1){
        D+=dis[now];
        hu=1;
        return ;
    }
    if(is[now]){
        hu=1;
        return ;
    }
    D++;
    int i,len=graph[now].size();
    for(i=0;i<len;i++){
        if(graph[now][i]==from)
            continue;
        distance(now,graph[now][i]);
        if(hu)
            return ;
    }
    return ;
}

int main()
{
    //freopen("input.txt","r",stdin);
    int n,i;
    si(n);
    vector<int> t;
    for(i=0;i<n;i++)
        graph.push_back(t);
    for(i=0;i<n;i++){
        int x,y;
        si(x);
        si(y);
        graph[x-1].push_back(y-1);
        graph[y-1].push_back(x-1);
    }
    for(i=0;i<n;i++)
        is[i]=false;
    dfs(-1,0);
    _p.push(p),_q.push(q);
    i=p;
    while(par[i]!=-1){
        _p.push(par[i]);
        i=par[i];
    }
    i=q;
    while(par[i]!=-1){
        _q.push(par[i]);
        i=par[i];
    }
    int temp;
    while(_p.top()==_q.top()){
        temp=_p.top();
        _p.pop(),_q.pop();
        if(_p.empty() || _q.empty())
            break;
    }
    for(i=0;i<n;i++)
        is[i]=false;
    is[temp]=true;
    is[p]=is[q]=true;
    i=p;
    while(par[i]!=temp){
        is[par[i]]=true;
        i=par[i];
    }
    i=q;
    while(par[i]!=temp){
        is[par[i]]=true;
        i=par[i];
    }
    for(i=0;i<n;i++)
        dis[i]=-1;
    for(i=0;i<n;i++){
        D=0;
        hu=0;
        distance(-1,i);
        printf("%d ",D);
    }
    printf("\n");
    return 0;
}


#include <iostream>
#include <vector>
#include <cstdio>
#include <stack>
#define si(a) scanf("%d",&a)

using namespace std;

vector<vector<int> > graph;
int par[3005],p,q,D,hu;
bool is[3005];
stack<int> _p,_q;

void dfs(int from,int now)
{
    //cout<<from<<" "<<now<<endl;
    is[now]=true;
    par[now]=from;
    int i,len=graph[now].size();
    for(i=0;i<len;i++){
        if(graph[now][i]==from)
            continue;
        if(is[graph[now][i]]){
            p=now;
            q=graph[now][i];
            continue;
        }
        dfs(now,graph[now][i]);
    }
    return ;
}

void distance(int from,int now)
{
    if(is[now]){
        hu=1;
        return ;
    }
    D++;
    int i,len=graph[now].size();
    for(i=0;i<len;i++){
        if(graph[now][i]==from)
            continue;
        distance(now,graph[now][i]);
        if(hu)
            return ;
    }
    return ;
}

int main()
{
    //freopen("input.txt","r",stdin);
    int n,i;
    si(n);
    vector<int> t;
    for(i=0;i<n;i++)
        graph.push_back(t);
    for(i=0;i<n;i++){
        int x,y;
        si(x);
        si(y);
        graph[x-1].push_back(y-1);
        graph[y-1].push_back(x-1);
    }
    for(i=0;i<n;i++)
        is[i]=false;
    dfs(-1,0);
    _p.push(p),_q.push(q);
    i=p;
    while(par[i]!=-1){
        _p.push(par[i]);
        i=par[i];
    }
    i=q;
    while(par[i]!=-1){
        _q.push(par[i]);
        i=par[i];
    }
    int temp;
    while(_p.top()==_q.top()){
        temp=_p.top();
        _p.pop(),_q.pop();
        if(_p.empty() || _q.empty())
            break;
    }
    for(i=0;i<n;i++)
        is[i]=false;
    is[temp]=true;
    is[p]=is[q]=true;
    i=p;
    while(par[i]!=temp){
        is[par[i]]=true;
        i=par[i];
    }
    i=q;
    while(par[i]!=temp){
        is[par[i]]=true;
        i=par[i];
    }
    for(i=0;i<n;i++){
        D=0;
        hu=0;
        distance(-1,i);
        printf("%d ",D);
    }
    printf("\n");
    return 0;
}


#include <iostream>
#include <vector>
#include <cstdio>
#include <stack>
#define si(a) scanf("%d",&a)

using namespace std;

vector<vector<int> > graph;
int par[3005],p=-1,q,D,hu;
bool is[3005];
stack<int> _p,_q;

void dfs(int from,int now)
{
    //cout<<from<<" "<<now<<endl;
    is[now]=true;
    par[now]=from;
    int i,len=graph[now].size();
    for(i=0;i<len;i++){
        if(graph[now][i]==from)
            continue;
        if(is[graph[now][i]]){
            if(p==-1){
                p=now;
                q=graph[now][i];
            }
            continue;
        }
        dfs(now,graph[now][i]);
    }
    return ;
}

void distance(int from,int now,int dist)
{
    if(is[now]){
        hu=1;
        D=dist;
        return ;
    }
    int i,len=graph[now].size();
    for(i=0;i<len;i++){
        if(graph[now][i]==from)
            continue;
        distance(now,graph[now][i],dist+1);
        if(hu)
            return ;
    }
    return ;
}

int main()
{
    //freopen("input.txt","r",stdin);
    int n,i;
    si(n);
    vector<int> t;
    for(i=0;i<n;i++)
        graph.push_back(t);
    for(i=0;i<n;i++){
        int x,y;
        si(x);
        si(y);
        graph[x-1].push_back(y-1);
        graph[y-1].push_back(x-1);
    }
    for(i=0;i<n;i++)
        is[i]=false;
    dfs(-1,0);
    for(i=0;i<n;i++)
        is[i]=false;
    is[p]=true,is[q]=true;
    i=p;
    while(par[i]!=q){
        is[par[i]]=true;
        i=par[i];
    }
    for(i=0;i<n;i++){
        D=0;
        hu=0;
        distance(-1,i,0);
        printf("%d ",D);
    }
    printf("\n");
    return 0;
}


#include <iostream>
#include <vector>
#include <cstdio>
#include <stack>
#define si(a) scanf("%d",&a)

using namespace std;

vector<vector<int> > graph;
int par[3005],p=-1,q,D,hu;
bool is[3005];
stack<int> _p,_q;
int dis[3005];

void dfs(int from,int now)
{
    //cout<<from<<" "<<now<<endl;
    is[now]=true;
    par[now]=from;
    int i,len=graph[now].size();
    for(i=0;i<len;i++){
        if(graph[now][i]==from)
            continue;
        if(is[graph[now][i]]){
            if(p==-1){
                p=now;
                q=graph[now][i];
            }
            continue;
        }
        dfs(now,graph[now][i]);
    }
    return ;
}

void distance(int from,int now)
{
    if(dis[now]!=-1){
        D+=dis[now];
        hu=1;
        return ;
    }
    if(is[now]){
        hu=1;
        return ;
    }
    D++;
    int i,len=graph[now].size();
    for(i=0;i<len;i++){
        if(graph[now][i]==from)
            continue;
        distance(now,graph[now][i]);
        if(hu)
            return ;
    }
    return ;
}

int main()
{
    //freopen("input.txt","r",stdin);
    int n,i;
    si(n);
    vector<int> t;
    for(i=0;i<n;i++)
        graph.push_back(t);
    for(i=0;i<n;i++){
        int x,y;
        si(x);
        si(y);
        graph[x-1].push_back(y-1);
        graph[y-1].push_back(x-1);
    }
    for(i=0;i<n;i++)
        is[i]=false;
    dfs(-1,0);
    for(i=0;i<n;i++)
        is[i]=false;
    is[p]=true,is[q]=true;
    i=p;
    while(par[i]!=q){
        is[par[i]]=true;
        i=par[i];
    }
    for(i=0;i<n;i++)
        dis[i]=-1;
    for(i=0;i<n;i++){
        D=0;
        hu=0;
        distance(-1,i);
        printf("%d ",D);
    }
    printf("\n");
    return 0;
}


#include<iostream>
#include<stdio.h>
#include<string.h>
#include<map>
#include<vector>
#include<algorithm>
#include<math.h>
#include <queue>
#define ll long long
using namespace std;
const double pi = acos(-1.0);
const ll mod = 1000000007;
const ll inf = 1ll << 60;
ll visited[1000005] = {};
ll father[1000005] = {};
ll lev[1000005] = {};
ll a, b,flag=1;
vector<ll> v[3005];
queue<ll>p;
void dfs(ll t)
{

    visited[t] = 1;
    for (ll i = 0; i < v[t].size(); i++)
    {
        if (!father[v[t][i]] && v[t][i]!=1)
        {
            father[v[t][i]] = t;
        }
        if (v[t][i] == father[t])
        {
            continue;
        }
        if (visited[v[t][i]] && flag)
        {
            a = v[t][i];
            b = t;
            flag = 0;
        }
        else if (!visited[v[t][i]])
        {
            dfs(v[t][i]);
        }
    }
}
void bfs(ll t)
{
    p.push(t);
    visited[t] = 1;
    while (!p.empty())
    {
        ll node = p.front();
        for (ll i = 0; i < v[node].size(); i++)
        {
            if (!visited[v[node][i]])
            {
                p.push(v[node][i]);
                visited[v[node][i]] = 1;
                lev[v[node][i]] = min(lev[v[node][i]], lev[node] + 1);
            }
        }
        p.pop();

    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        cin >> a >> b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    dfs(1);
    fill(lev, lev + n+5, inf);
    while (b != a)
    {
        lev[b] = 0;
        b = father[b];
    }
    lev[a] = 0;
    memset(visited, 0, sizeof(visited));
    bfs(a);
    for (int i = 1; i <= n; ++i)
    {
        cout << lev[i] << " ";
    }
    cout << "\n";
    return 0;
}


#include<iostream>
#include<stdio.h>
#include<string.h>
#include<map>
#include<vector>
#include<algorithm>
#include<math.h>
#include <queue>
#define ll long long
using namespace std;
const double pi = acos(-1.0);
const ll mod = 1000000007;
const ll inf = 1ll << 60;
ll visited[3005] = {};
ll father[3005] = {};
ll lev[3005] = {};
ll a, b;
vector<ll> v[3005];
queue<ll>p;
void dfs(ll t)
{

    visited[t] = 1;
    for (ll i = 0; i < v[t].size(); i++)
    {
        if (!father[v[t][i]])
        {
            father[v[t][i]] = t;
        }
        if (v[t][i] == father[t])
        {
            continue;
        }
        if (visited[v[t][i]])
        {
            a = v[t][i];
            b = t;
            father[a] = b;
        }
        else
        {
            dfs(v[t][i]);
        }
    }
}
void bfs(ll t)
{
    p.push(t);
    visited[t] = 1;
    while (!p.empty())
    {
        ll node = p.front();
        for (ll i = 0; i < v[node].size(); i++)
        {
            if (!visited[v[node][i]])
            {
                p.push(v[node][i]);
                visited[v[node][i]] = 1;
                lev[v[node][i]] = min(lev[v[node][i]], lev[node] + 1);
            }
        }
        p.pop();

    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        cin >> a >> b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    dfs(1);
    fill(lev, lev + n+5, inf);
    while (b != a)
    {
        lev[b] = 0;
        b = father[b];
    }
    lev[a] = 0;
    memset(visited, 0, sizeof(visited));
    bfs(a);
    for (int i = 1; i <= n; ++i)
    {
        cout << lev[i] << " ";
    }
    cout << "\n";
    return 0;
}


#include<iostream>
#include<stdio.h>
#include<string>
#include<map>
#include<vector>
#include<algorithm>
#include<math.h>
#include <queue>
#define ll long long
using namespace std;
const double pi = acos(-1.0);
const ll mod = 1000000007;
const ll inf = 1ll << 60;
ll visited[1000005] = {};
ll father[1000005] = {};
ll lev[1000005] = {};
ll a, b;
vector<ll> v[3005];
queue<ll>p;
void dfs(ll t)
{

    visited[t] = 1;
    for (ll i = 0; i < v[t].size(); i++)
    {
        if (!father[v[t][i]])
        {
            father[v[t][i]] = t;
        }
        if (v[t][i] == father[t])
        {
            continue;
        }
        if (visited[v[t][i]])
        {
            a = v[t][i];
            b = t;
            father[a] = b;
        }
        else
        {
            dfs(v[t][i]);
        }
    }
}
void bfs(ll t)
{
    p.push(t);
    visited[t] = 1;
    while (!p.empty())
    {
        ll node = p.front();
        for (ll i = 0; i < v[node].size(); i++)
        {
            if (!visited[v[node][i]])
            {
                p.push(v[node][i]);
                visited[v[node][i]] = 1;
                lev[v[node][i]] = min(lev[v[node][i]], lev[node] + 1);
            }
        }
        p.pop();

    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        cin >> a >> b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    dfs(1);
    fill(lev, lev + n+5, inf);
    while (b != a)
    {
        lev[b] = 0;
        b = father[b];
    }
    lev[a] = 0;
    memset(visited, 0, sizeof(visited));
    bfs(a);
    for (int i = 1; i <= n; ++i)
    {
        cout << lev[i] << " ";
    }
    cout << "\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
vector<int> adj[3001];
int cyc[3001]={0};
int ans[3001]={0};
int vis[3001]={0};
int cnt[3001]={0};
int dfs1(int pos, int par){
	if(vis[pos])	return 1;
	vis[pos]=1;
	for(int i : adj[pos]){
		if(i==par)	continue;
		cyc[pos]|=dfs1(i,pos);
	}
	return cyc[pos];
}
void dfs2(int pos, int par,int dis){

	for(int i : adj[pos]){
		if(i==par || cyc[i]==1)	continue;
		ans[i]=dis;
		dfs2(i,pos,dis+1);
	}
}
int main() {
	// your code goes here
	int n;
	cin>>n;
	int maxpos=1;
	for(int i = 0 ; i< n ; i++){
		int x,y;
		cin>>x>>y;
		adj[x].push_back(y);
		adj[y].push_back(x);
		cnt[x]++;
		cnt[y]++;
		if(cnt[x]>cnt[maxpos])	maxpos=x;
		if(cnt[y]>cnt[maxpos])	maxpos=y;
	}
	dfs1(maxpos,maxpos);
	for(int i = 1; i<=n ; i++){
		if(cyc[i]==1)
			dfs2(i,i,1);
	}
	for(int i = 1; i<=n; i++){
		cout<<ans[i]<<" ";
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
vector<int> adj[3001];
int cyc[3001]={0};
int ans[3001]={0};
int lvis[3001]={0};
int vis[3001]={0};
int location;
void dfs(int pos, int par){
	if(lvis[pos]){
		location = pos;
		return;
	}
	lvis[pos]=1;
	for(int i : adj[pos]){
		if(i==par)	continue;
		dfs(i,pos);
	}
}
int dfs1(int pos, int par){
	if(vis[pos])	return 1;
	vis[pos]=1;
	for(int i : adj[pos]){
		if(i==par)	continue;
		cyc[pos]|=dfs1(i,pos);
	}
	return cyc[pos];
}
void dfs2(int pos, int par,int dis){

	for(int i : adj[pos]){
		if(i==par || cyc[i]==1)	continue;
		ans[i]=dis;
		dfs2(i,pos,dis+1);
	}
}
int main() {
	// your code goes here
	int n;
	cin>>n;
	int maxpos=1;
	for(int i = 0 ; i< n ; i++){
		int x,y;
		cin>>x>>y;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	dfs(1,1);
	dfs1(location,location);
	for(int i = 1; i<=n ; i++){
		if(cyc[i]==1)
			dfs2(i,i,1);
	}
	for(int i = 1; i<=n; i++){
		cout<<ans[i]<<" ";
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
vector<int> adj[3001];
int cyc[3001]={0};
int ans[3001]={0};
int vis[3001]={0};
int dfs1(int pos, int par){
	if(vis[pos])	return 1;
	vis[pos]=1;
	for(int i : adj[pos]){
		if(i==par)	continue;
		cyc[pos]|=dfs1(i,pos);
	}
	return cyc[pos];
}
void dfs2(int pos, int par,int dis){

	for(int i : adj[pos]){
		if(i==par || cyc[i]==1)	continue;
		ans[i]=dis;
		dfs2(i,pos,dis+1);
	}
}
int main() {
	// your code goes here
	int n;
	cin>>n;
	for(int i = 0 ; i< n ; i++){
		int x,y;
		cin>>x>>y;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	dfs1(1,1);
	for(int i = 1; i<=n ; i++){
		if(cyc[i]==1)
			dfs2(i,i,1);
	}
	for(int i = 1; i<=n; i++){
		cout<<ans[i]<<" ";
	}
	return 0;
}


#include <iostream>
#include <vector>

using namespace std;

int n;
vector <vector <int>> g;
vector <int> used, ans;

bool dfs(int v, int p) {
	used[v] = true;
	for (int u : g[v]) {
		if (u != p) {
			if (used[u]) {
				ans[u] = 0;
				return true;
			}
			if (dfs(u, v)) {
				ans[u] = 0;
				return ans[v] != 0;
			}
		}
	}
	return false;
}

int gen(int v, int p) {
	if (ans[v] != -1) {
		return ans[v];
	}
	for (int u : g[v]) {
		if (u != p) {
			return ans[v] = gen(u, v) + 1;
		}
	}
}

int main() {
	cin >> n;
	g.resize(n + 1);
	used.resize(n + 1, 0);
	ans.resize(n + 1, -1);
	int v, u;
	for (int i = 0; i < n; i++) {
		cin >> v >> u;
		g[v].push_back(u);
		g[u].push_back(v);
	}
	dfs(1, -1);
	for (int i = 1; i <= n; i++) {
		if (ans[i] == -1) {
			gen(i, -1);
		}
	}
	for (int i = 1; i <= n; i++) {
		cout << ans[i] << ' ';
	}
	return 0;
}


#include <iostream>
#include <vector>

using namespace std;

int n;
vector <vector <int>> g;
vector <int> used, ans;

bool dfs(int v, int p) {
	used[v] = true;
	for (int u : g[v]) {
		if (u != p) {
			if (used[u]) {
				ans[u] = 0;
				return true;
			}
			if (dfs(u, v)) {
				ans[u] = 0;
				return ans[v] != 0;
			}
		}
	}
	return false;
}

int gen(int v, int p) {
	if (ans[v] != -1) {
		return ans[v];
	}
	for (int u : g[v]) {
		if (u != p) {
			return ans[v] = gen(u, v) + 1;
		}
	}
	return 0;
}

int main() {
	cin >> n;
	g.resize(n + 1);
	used.resize(n + 1, 0);
	ans.resize(n + 1, -1);
	int v, u;
	for (int i = 0; i < n; i++) {
		cin >> v >> u;
		g[v].push_back(u);
		g[u].push_back(v);
	}
	dfs(1, -1);
	for (int i = 1; i <= n; i++) {
		if (ans[i] == -1) {
			gen(i, -1);
		}
	}
	for (int i = 1; i <= n; i++) {
		cout << ans[i] << ' ';
	}
	return 0;
}


#include <iostream>
#include <vector>

using namespace std;

int n;
vector <vector <int>> g;
vector <int> used, ans;

bool dfs(int v, int p) {
	used[v] = true;
	for (int u : g[v]) {
		if (u != p) {
			if (used[u]) {
				ans[u] = 0;
				return true;
			}
			if (dfs(u, v)) {
				ans[u] = 0;
				return ans[v] != 0;
			}
		}
	}
	return false;
}

bool gen(int v, int p) {
	if (ans[v] != -1) {
		return true;
	}
	for (int u : g[v]) {
		if (u != p) {
			if (gen(u, v)) {
				ans[v] = ans[u] + 1;
				return true;
			}
		}
	}
	return false;
}

int main() {
	cin >> n;
	g.resize(n + 1);
	used.resize(n + 1, 0);
	ans.resize(n + 1, -1);
	int v, u;
	for (int i = 0; i < n; i++) {
		cin >> v >> u;
		g[v].push_back(u);
		g[u].push_back(v);
	}
	dfs(1, -1);
	for (int i = 1; i <= n; i++) {
		if (ans[i] == -1) {
			gen(i, -1);
		}
	}
	for (int i = 1; i <= n; i++) {
		cout << ans[i] << ' ';
	}
	return 0;
}


#include <iostream>
#include <vector>

using namespace std;

int n;
vector <vector <int>> g;
vector <int> used, ans;

bool dfs(int v, int p) {
	used[v] = true;
	for (int u : g[v]) {
		if (u != p) {
			if (used[u]) {
				ans[u] = 0;
				return true;
			}
			if (dfs(u, v)) {
				ans[u] = 0;
				return ans[v] != 0;
			}
		}
	}
	return false;
}

bool gen(int v, int p) {
	if (ans[v] != -1) {
		return true;
	}
	for (int u : g[v]) {
		if (u != p) {
			if (dfs(u, v)) {
				ans[v] = ans[u] + 1;
				return true;
			}
		}
	}
	return false;
}

int main() {
	cin >> n;
	g.resize(n + 1);
	used.resize(n + 1, 0);
	ans.resize(n + 1, -1);
	int v, u;
	for (int i = 0; i < n; i++) {
		cin >> v >> u;
		g[v].push_back(u);
		g[u].push_back(v);
	}
	dfs(1, -1);
	for (int i = 1; i <= n; i++) {
		if (ans[i] == -1) {
			gen(i, -1);
		}
	}
	for (int i = 1; i <= n; i++) {
		cout << ans[i] << ' ';
	}
	return 0;
}


#include <iostream>
#include <vector>

using namespace std;

int n;
vector <vector <int>> g;
vector <int> used, ans;

bool dfs(int v, int p) {
	used[v] = true;
	for (int u : g[v]) {
		if (u != p) {
			if (used[u]) {
				ans[u] = 0;
				return true;
			}
			if (dfs(u, v)) {
				ans[u] = 0;
				return ans[v] != 0;
			}
		}
	}
	return false;
}

int gen(int v, int p) {
	if (ans[v] != -1) {
		return ans[v];
	}
	for (int u : g[v]) {
		if (u != p) {
			return ans[v] = gen(u, v) + 1;
		}
	}
	return -1e9;
}

int main() {
	cin >> n;
	g.resize(n + 1);
	used.resize(n + 1, 0);
	ans.resize(n + 1, -1);
	int v, u;
	for (int i = 0; i < n; i++) {
		cin >> v >> u;
		g[v].push_back(u);
		g[u].push_back(v);
	}
	dfs(1, -1);
	for (int i = 1; i <= n; i++) {
		if (ans[i] < 0) {
			gen(i, -1);
		}
	}
	for (int i = 1; i <= n; i++) {
		cout << ans[i] << ' ';
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <queue>
#include <stdio.h>

using namespace std;

int n;
vector < vector< int > > adj;
vector < vector< int > > adjt;
vector < vector< bool > > adjo;
vector <int> visited;
vector <int> dis;

void bfs(int v) {
    queue <int> q;
    q.push(v);
    dis[v] = 0;
    while (!q.empty()) {
        v = q.front();
        q.pop();
        for (int j = 0;j < adj[v].size();++j)
            if (dis[adj[v][j]] == -1) {
                dis[adj[v][j]] = dis[v] + 1;
                q.push(adj[v][j]);
                //cout << adj[v][j] << " " < v << " "
            }
    }
}

int owl(int a) {
    int sum = 0;
    for (int j = 0;j < n;++j)
        sum += adjo[a][j];
    return sum;
}

bool adt() {
    for (int i = 0;i < n;++i) {
        int sum = 0;
        for (int j = 0;j < n;++j)
            sum += adjo[i][j];
        if (sum == 1)
            return false;
    }
    return true;
}

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    dis.resize(n + 1);
    adj.resize(n);
    visited.resize(n);
    adjo.resize(n);
    for (int i = 0;i < n;++i)
        adjo[i].resize(n);
    for (int i = 0;i < n;++i) {
        int a,b;
        cin >> a >> b;
        adj[a - 1].push_back(b - 1);
        adj[b - 1].push_back(a - 1);
        adjo[a - 1][b - 1] = true;
        adjo[b - 1][a - 1] = true;
    }
    //
    while (adt() == false) {
        for (int i = 0;i < n;++i)
            if (owl(i) == 1) {
                for (int j = 0;j < n;++j) {
                    adjo[j][i] = 0;
                    adjo[i][j] = 0;
                }
                break;
            }
    }
    //
    cout << endl;
    vector <int> cyc;
    vector <bool> ow;
    ow.resize(n);
    for (int i = 0;i < n;++i)
        for (int j = 0;j < n;++j)
            if (adjo[i][j] == 1) {
                cyc.push_back(i);
                ow[i] = true;
            }

    adj.resize(n + 1);

    for (int i = 0;i < cyc.size();++i)
        for (int j = 0;j < adj[cyc[i]].size();++j)
            if (ow[adj[cyc[i]][j]] == false)
                adj[n].push_back(adj[cyc[i]][j]);
    for (int i = 0;i < n;++i)
        if (ow[i] == true)
            adj[i].clear();

    for (int i = 0;i < n;++i)
        for (int j = 0;j < adj[i].size();++j)
            if ( ow[adj[i][j]] == true ) {
                adj[i].erase(adj[i].begin() + j);
                adj[i].push_back(n);
            }
    /*

    adjt.resize(n + 1);

    for (int i = 0;i < n;++i) {
        for (int j = 0;j < adj[i].size();++j) {
            if (ow[adj[i][j]] == false)
                adjt[i].push_back(adj[i][j]);
            else
                adjt[i].push_back(n);
        }
    }

    for (int i = 0;i < cyc.size();++i)
        for (int j = 0;j < adj[cyc[i]].size();++j)
            adjt[n].push_back(adj[cyc[i]][j]);
         */
    for (int i = 0;i < n + 1;++i)
        dis[i] = -1;
        bfs(n);

    for (int i = 0;i < n;++i)
        if (dis[i] == -1)
            printf("%d %s",0," ");
        else
            printf("%d %s",dis[i]," ");

}


#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int n;
vector < vector< int > > adj;
vector <bool> visited;
vector <int> parent;
vector <int> cycle;
int ow,wo;
vector <int> dis;

void bfs() {
    int v;
    queue <int> q;
    for (int i = 0;i < cycle.size();++i) {
        q.push(cycle[i]);
        //cout << "omg"  << cycle[i] << endl;
        dis[cycle[i]] = 0;
    }
    while (!q.empty()) {
        v = q.front();
        q.pop();
        for (int j = 0;j < adj[v].size();++j) {

            if (dis[adj[v][j]] == -1) {
                dis[adj[v][j]] = dis[v] + 1;
                q.push(adj[v][j]);

            }
        }
    }
}

bool dfs(int a) {
    visited[a] = true;
    for (int i = 0;i < adj[a].size();++i) {
        if (visited[adj[a][i]] == true && parent[a] != adj[a][i]) {
            ow = a;
            wo = adj[a][i];
            /*if (to == true) {
                int ra = parent[a];
                while (ra != adj[a][i]) {
                    cout << ra << endl;
                    ra = parent[ra];
                }
            }*/
        }
        if (visited[adj[a][i]] == false) {
            parent[adj[a][i]] = a;
            dfs(adj[a][i]);
        }
    }
}

int main() {
    //
    cin >> n;
    adj.resize(n + 1);
    visited.resize(n + 1);
    dis.resize(n + 1);

    for (int i = 1;i <= n;++i)   dis[i] = -1;
    parent.resize(n + 1);
    for (int i = 0;i < n;++i) {
        int a,b;
        cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    //
    dfs(1);
    //
    if (parent[ow] == 0)
        swap(ow,wo);
    int na = ow;
    while (na != wo) {
        cycle.push_back(na);
        na = parent[na];
    }
    cycle.push_back(wo);
    //
    bfs();
    for (int i = 1;i <= n;++i)
        cout << dis[i] << " ";

}


#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int n;
vector < vector< int > > adj;
vector < vector< int > > adjt;
vector < vector< bool > > adjo;
vector <int> visited;
vector <int> dis;

void bfs(int v) {
    queue <int> q;
    q.push(v);
    dis[v] = 0;
    while (!q.empty()) {
        v = q.front();
        q.pop();
        for (int j = 0;j < adj[v].size();++j)
            if (dis[adj[v][j]] == -1) {
                dis[adj[v][j]] = dis[v] + 1;
                q.push(adj[v][j]);
                //cout << adj[v][j] << " " < v << " "
            }
    }
}

int owl(int a) {
    int sum = 0;
    for (int j = 0;j < n;++j)
        sum += adjo[a][j];
    return sum;
}

bool adt() {
    for (int i = 0;i < n;++i) {
        int sum = 0;
        for (int j = 0;j < n;++j)
            sum += adjo[i][j];
        if (sum == 1)
            return false;
    }
    return true;
}

int main() {
    cin >> n;
    dis.resize(n + 1);
    adj.resize(n);
    visited.resize(n);
    adjo.resize(n);
    for (int i = 0;i < n;++i)
        adjo[i].resize(n);
    for (int i = 0;i < n;++i) {
        int a,b;
        cin >> a >> b;
        adj[a - 1].push_back(b - 1);
        adj[b - 1].push_back(a - 1);
        adjo[a - 1][b - 1] = true;
        adjo[b - 1][a - 1] = true;
    }
    //
    while (adt() == false) {
        for (int i = 0;i < n;++i)
            if (owl(i) == 1) {
                for (int j = 0;j < n;++j) {
                    adjo[j][i] = 0;
                    adjo[i][j] = 0;
                }
                break;
            }
    }
    //
    cout << endl;
    vector <int> cyc;
    vector <bool> ow;
    ow.resize(n);
    for (int i = 0;i < n;++i)
        for (int j = 0;j < n;++j)
            if (adjo[i][j] == 1) {
                cyc.push_back(i);
                ow[i] = true;
            }

    adj.resize(n + 1);

    for (int i = 0;i < cyc.size();++i)
        for (int j = 0;j < adj[cyc[i]].size();++j)
            if (ow[adj[cyc[i]][j]] == false)
                adj[n].push_back(adj[cyc[i]][j]);
    for (int i = 0;i < n;++i)
        if (ow[i] == true)
            adj[i].clear();

    for (int i = 0;i < n;++i)
        for (int j = 0;j < adj[i].size();++j)
            if ( ow[adj[i][j]] == true ) {
                adj[i].erase(adj[i].begin() + j);
                adj[i].push_back(n);
            }
    /*

    adjt.resize(n + 1);

    for (int i = 0;i < n;++i) {
        for (int j = 0;j < adj[i].size();++j) {
            if (ow[adj[i][j]] == false)
                adjt[i].push_back(adj[i][j]);
            else
                adjt[i].push_back(n);
        }
    }

    for (int i = 0;i < cyc.size();++i)
        for (int j = 0;j < adj[cyc[i]].size();++j)
            adjt[n].push_back(adj[cyc[i]][j]);
         */
    for (int i = 0;i < n + 1;++i)
        dis[i] = -1;
        bfs(n);

    for (int i = 0;i < n;++i)
        if (dis[i] == -1)
            cout << 0 << " ";
        else
            cout << dis[i] << " ";
    cout << endl;

}


#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int n;
vector < vector< int > > adj;
vector <bool> visited;
vector <int> parent;
vector <int> cycle;
int ow,wo;
vector <int> dis;

void bfs() {
    int v;
    queue <int> q;
    for (int i = 0;i < cycle.size();++i) {
        q.push(cycle[i]);
        //cout << "omg"  << cycle[i] << endl;
        dis[cycle[i]] = 0;
    }
    while (!q.empty()) {
        v = q.front();
        q.pop();
        for (int j = 0;j < adj[v].size();++j) {

            if (dis[adj[v][j]] == -1) {
                dis[adj[v][j]] = dis[v] + 1;
                q.push(adj[v][j]);

            }
        }
    }
}

bool dfs(int a) {
    visited[a] = true;
    for (int i = 0;i < adj[a].size();++i) {
        if (visited[adj[a][i]] == true && parent[a] != adj[a][i]) {
            ow = a;
            wo = adj[a][i];
            /*if (to == true) {
                int ra = parent[a];
                while (ra != adj[a][i]) {
                    cout << ra << endl;
                    ra = parent[ra];
                }
            }*/
        }
        if (visited[adj[a][i]] == false) {
            parent[adj[a][i]] = a;
            dfs(adj[a][i]);
        }
    }
}

int main() {
    //
    cin >> n;
    adj.resize(n + 1);
    visited.resize(n + 1);
    dis.resize(n + 1);

    for (int i = 1;i <= n;++i)   dis[i] = -1;
    parent.resize(n + 1);
    for (int i = 0;i < n;++i) {
        int a,b;
        cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    //
    dfs(1);
    //
    //if (parent[ow] == 0)
    //    swap(ow,wo);
    int na = wo;
    while (na != ow) {
        cycle.push_back(na);
        na = parent[na];
    }
    cycle.push_back(ow);
    bfs();
    for (int i = 1;i <= n;++i)
        cout << dis[i] << " ";

}


#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int n;
vector < vector< int > > adj;
vector < vector< int > > adjt;
vector < vector< bool > > adjo;
vector <int> visited;
vector <int> dis;

void bfs(int v) {
    queue <int> q;
    q.push(v);
    dis[v] = 0;
    while (!q.empty()) {
        v = q.front();
        q.pop();
        for (int j = 0;j < adj[v].size();++j)
            if (dis[adj[v][j]] == -1) {
                dis[adj[v][j]] = dis[v] + 1;
                q.push(adj[v][j]);
                //cout << adj[v][j] << " " < v << " "
            }
    }
}

int owl(int a) {
    int sum = 0;
    for (int j = 0;j < n;++j)
        sum += adjo[a][j];
    return sum;
}

bool adt() {
    for (int i = 0;i < n;++i) {
        int sum = 0;
        for (int j = 0;j < n;++j)
            sum += adjo[i][j];
        if (sum == 1)
            return false;
    }
    return true;
}

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    dis.resize(n + 1);
    adj.resize(n);
    visited.resize(n);
    adjo.resize(n);
    for (int i = 0;i < n;++i)
        adjo[i].resize(n);
    for (int i = 0;i < n;++i) {
        int a,b;
        cin >> a >> b;
        adj[a - 1].push_back(b - 1);
        adj[b - 1].push_back(a - 1);
        adjo[a - 1][b - 1] = true;
        adjo[b - 1][a - 1] = true;
    }
    //
    while (adt() == false) {
        for (int i = 0;i < n;++i)
            if (owl(i) == 1) {
                for (int j = 0;j < n;++j) {
                    adjo[j][i] = 0;
                    adjo[i][j] = 0;
                }
                break;
            }
    }
    //
    cout << endl;
    vector <int> cyc;
    vector <bool> ow;
    ow.resize(n);
    for (int i = 0;i < n;++i)
        for (int j = 0;j < n;++j)
            if (adjo[i][j] == 1) {
                cyc.push_back(i);
                ow[i] = true;
            }

    adj.resize(n + 1);

    for (int i = 0;i < cyc.size();++i)
        for (int j = 0;j < adj[cyc[i]].size();++j)
            if (ow[adj[cyc[i]][j]] == false)
                adj[n].push_back(adj[cyc[i]][j]);
    for (int i = 0;i < n;++i)
        if (ow[i] == true)
            adj[i].clear();

    for (int i = 0;i < n;++i)
        for (int j = 0;j < adj[i].size();++j)
            if ( ow[adj[i][j]] == true ) {
                adj[i].erase(adj[i].begin() + j);
                adj[i].push_back(n);
            }
    /*

    adjt.resize(n + 1);

    for (int i = 0;i < n;++i) {
        for (int j = 0;j < adj[i].size();++j) {
            if (ow[adj[i][j]] == false)
                adjt[i].push_back(adj[i][j]);
            else
                adjt[i].push_back(n);
        }
    }

    for (int i = 0;i < cyc.size();++i)
        for (int j = 0;j < adj[cyc[i]].size();++j)
            adjt[n].push_back(adj[cyc[i]][j]);
         */
    for (int i = 0;i < n + 1;++i)
        dis[i] = -1;
        bfs(n);

    for (int i = 0;i < n;++i)
        if (dis[i] == -1)
            cout << 0 << " ";
        else
            cout << dis[i] << " ";
    cout << endl;

}


#include <stack>
#include <cstring>
#include <vector>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>

namespace IO
{
//	inline char gc(){
//        static char s[1<<20|1]={0},*p1=s,*p2=s;
//        return (p1==p2)&&(p2=(p1=s)+fread(s,1,1<<20,stdin),p1==p2)?EOF:*(p1++);
//    }
	inline char gc() { return getchar(); }
	inline int read()
	{
		register int ret=0;bool flag=0;register char c=gc();
		while ((c<'0')|(c>'9')) flag ^= !(c^'-'),c=gc();
		while ((c>='0')&(c<='9')) ret=(ret<<1)+(ret<<3)+(c^'0'),c=gc();
		return flag?-ret:ret;
 	}
 	char OutputAns[1<<20|1],*OutputCur = OutputAns;
 	inline void output() { OutputCur -= fwrite(OutputAns,1,OutputCur - OutputAns,stdout); }
 	inline void print(int ans)
 	{
 		char s[20]={0};
 		if (OutputCur - OutputAns + sprintf(s,"%d",ans) >> 20) output();
 		OutputCur += sprintf(OutputCur,"%d",ans);
	}
	inline void putc(char c)
	{
		if (OutputCur - OutputAns + 1 >> 20) output();
		*(OutputCur++) = c;
	}
}

using IO::read;
using IO::print;
using IO::output;
using IO::putc;

const int M = 3111 * 2;

int Nxt[M],To[M],Fir[M],Dis[M];

int nxt[M],to[M],fir[M],In[M];

bool Vis[M],G[M][M],IsOut[M];

int tot,n,_s;

std::priority_queue <std::pair <int,int> > Q;

namespace Tarjan
{
	int Low[M],Dfn[M],Stack[M],InBlock[M];

	std::vector <int> Block[M];

	int clock,kind,top;

	inline void Find(int u,int fa)
	{
		Dfn[u] = Low[u] = ++clock;
		Stack[++top] = u;

		for (int i = Fir[u];i;i = Nxt[i])
		{
			int go = To[i];
			if (!Dfn[go])
			{
				Find(go,u);
				Low[u] = std::min(Low[u],Low[go]);
			}
			else  if(go != fa) Low[u] = std::min(Dfn[go],Low[u]);
		}
		if (Low[u] == Dfn[u])
		{
			InBlock[u] = ++kind;Block[kind].push_back(u);
			while (Stack[top] != u)
				InBlock[Stack[top--]] = kind,Block[kind].push_back(Stack[top + 1]);
			--top;
		}
	}
}

using Tarjan::Find;
using Tarjan::InBlock;
using Tarjan::kind;

inline void AddEdge(int x,int y)
{
	Nxt[++tot] = Fir[x],To[tot] = y,Fir[x] = tot;
}

inline void Input()
{
	n = read();
	for (int i = 1;i <= n; ++i)
	{
		int u = read(),v = read();
		AddEdge(u,v);
		AddEdge(v,u);
	}
	Find(1,0);
}

inline void ReBuild(int u,int v)
{
	nxt[++tot] = fir[u],to[tot] = v,fir[u] = tot;
}

inline void GetAns()
{
	Q.push(std::make_pair(0,_s));
	memset(Dis,127,sizeof Dis);
	Dis[_s] = 0;

	while(Q.size())
    {
        int now = Q.top().second; Q.pop();

        if(Vis[now]) continue;
        Vis[now] = 1;
        for(int i = fir[now];i; i = nxt[i])
        {
            int go = to[i];
            int val = 1;
            if(Dis[go] > Dis[now] + val)
            {
                Dis[go] = Dis[now] + val;
                Q.push(std::make_pair(-Dis[go],go));
            }
        }
    }
}

inline void Solve()
{
	for (int i = 1;i <= kind;++i)
		if (Tarjan::Block[i].size() > 1)
		{
			_s = i;
			break;
		}
	tot = 0;

	for (int i = 1;i <= n; ++i)
		for (int j = Fir[i];j;j = Nxt[j])
		{
			int go = To[j];
			if (InBlock[i] != InBlock[go] && (!G[InBlock[i]][InBlock[go]]))
				ReBuild(InBlock[i],InBlock[go]),ReBuild(InBlock[go],InBlock[i]),
				G[InBlock[i]][InBlock[go]] =
				G[InBlock[go]][InBlock[i]] = 1;
		}
	GetAns();
	for (int i = 1;i <= n; ++i)
		printf("%d%c",Dis[InBlock[i]],i == n ? '\n' : ' ');
}

int main(void)
{
	Input();
	Solve();
	return 0;
}


#include <stack>
#include <cstring>
#include <vector>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>

namespace IO
{
//	inline char gc(){
//        static char s[1<<20|1]={0},*p1=s,*p2=s;
//        return (p1==p2)&&(p2=(p1=s)+fread(s,1,1<<20,stdin),p1==p2)?EOF:*(p1++);
//    }
	inline char gc() { return getchar(); }
	inline int read()
	{
		register int ret=0;bool flag=0;register char c=gc();
		while ((c<'0')|(c>'9')) flag ^= !(c^'-'),c=gc();
		while ((c>='0')&(c<='9')) ret=(ret<<1)+(ret<<3)+(c^'0'),c=gc();
		return flag?-ret:ret;
 	}
 	char OutputAns[1<<20|1],*OutputCur = OutputAns;
 	inline void output() { OutputCur -= fwrite(OutputAns,1,OutputCur - OutputAns,stdout); }
 	inline void print(int ans)
 	{
 		char s[20]={0};
 		if (OutputCur - OutputAns + sprintf(s,"%d",ans) >> 20) output();
 		OutputCur += sprintf(OutputCur,"%d",ans);
	}
	inline void putc(char c)
	{
		if (OutputCur - OutputAns + 1 >> 20) output();
		*(OutputCur++) = c;
	}
}

using IO::read;
using IO::print;
using IO::output;
using IO::putc;

const int M = 3111 * 2;

int Nxt[M],To[M],Fir[M],Dis[M];

int nxt[M],to[M],fir[M],In[M];

bool Vis[M],G[M][M],IsOut[M];

int tot,n,_s;

std::priority_queue <std::pair <int,int> > Q;

namespace Tarjan
{
	int Low[M],Dfn[M],Stack[M],InBlock[M];

	std::vector <int> Block[M];

	int clock,kind,top;

	inline void Find(int u,int fa)
	{
		Dfn[u] = Low[u] = ++clock;
		Stack[++top] = u;

		for (int i = Fir[u];i;i = Nxt[i])
		{
			int go = To[i];
			if (!Dfn[go])
			{
				Find(go,u);
				Low[u] = std::min(Low[u],Low[go]);
			}
			else  if(go != fa) Low[u] = std::min(Dfn[go],Low[u]);
		}
		if (Low[u] == Dfn[u])
		{
			InBlock[u] = ++kind;Block[kind].push_back(u);
			while (Stack[top] != u)
				InBlock[Stack[top--]] = kind,Block[kind].push_back(Stack[top + 1]);
			--top;
		}
	}
}

using Tarjan::Find;
using Tarjan::InBlock;
using Tarjan::kind;

inline void AddEdge(int x,int y)
{
	Nxt[++tot] = Fir[x],To[tot] = y,Fir[x] = tot;
}

inline void Input()
{
	n = read();
	for (int i = 1;i <= n; ++i)
	{
		int u = read(),v = read();
		AddEdge(u,v);
		AddEdge(v,u);
	}
	Find(1,0);
}

inline void ReBuild(int u,int v)
{
	nxt[++tot] = fir[u],to[tot] = v,fir[u] = tot;
}

inline void GetAns()
{
	Q.push(std::make_pair(0,_s));
	memset(Dis,127,sizeof Dis);
	Dis[_s] = 0;

	while(Q.size())
    {
        int now = Q.top().second; Q.pop();

        if(Vis[now]) continue;
        Vis[now] = 1;
        for(int i = fir[now];i; i = nxt[i])
        {
            int go = to[i];
            int val = 1;
            if(Dis[go] > Dis[now] + val)
            {
                Dis[go] = Dis[now] + val;
                Q.push(std::make_pair(-Dis[go],go));
            }
        }
    }
}

inline void Solve()
{
	for (int i = 1;i <= kind;++i)
		if (Tarjan::Block[i].size() > 1)
		{
			_s = i;
			break;
		}
	tot = 0;

	for (int i = 1;i <= n; ++i)
		for (int j = Fir[i];j;j = Nxt[j])
		{
			int go = To[j];
			if (InBlock[i] != InBlock[go] && (!G[InBlock[i]][InBlock[go]]))
				ReBuild(InBlock[i],InBlock[go]),ReBuild(InBlock[go],InBlock[i]),
				G[InBlock[i]][InBlock[go]] =
				G[InBlock[go]][InBlock[i]] = 1;
		}
	GetAns();
	for (int i = 1;i <= n; ++i)
		print(Dis[InBlock[i]]),putc(' ');
	output();
}

int main(void)
{
	Input();
	Solve();
	return 0;
}


#include <stack>
#include <cstring>
#include <vector>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>

namespace IO
{
//	inline char gc(){
//        static char s[1<<20|1]={0},*p1=s,*p2=s;
//        return (p1==p2)&&(p2=(p1=s)+fread(s,1,1<<20,stdin),p1==p2)?EOF:*(p1++);
//    }
	inline char gc() { return getchar(); }
	inline int read()
	{
		register int ret=0;bool flag=0;register char c=gc();
		while ((c<'0')|(c>'9')) flag ^= !(c^'-'),c=gc();
		while ((c>='0')&(c<='9')) ret=(ret<<1)+(ret<<3)+(c^'0'),c=gc();
		return flag?-ret:ret;
 	}
 	char OutputAns[1<<20|1],*OutputCur = OutputAns;
 	inline void output() { OutputCur -= fwrite(OutputAns,1,OutputCur - OutputAns,stdout); }
 	inline void print(int ans)
 	{
 		char s[20]={0};
 		if (OutputCur - OutputAns + sprintf(s,"%d",ans) >> 20) output();
 		OutputCur += sprintf(OutputCur,"%d",ans);
	}
	inline void putc(char c)
	{
		if (OutputCur - OutputAns + 1 >> 20) output();
		*(OutputCur++) = c;
	}
}

using IO::read;
using IO::print;
using IO::output;
using IO::putc;

const int M = 3111;

int Nxt[M],To[M],Fir[M],Dis[M];

int nxt[M],to[M],fir[M],In[M];

bool Vis[M],G[M][M],IsOut[M];

int tot,n,_s;

std::priority_queue <std::pair <int,int> > Q;

namespace Tarjan
{
	int Low[M],Dfn[M],Stack[M],InBlock[M];

	std::vector <int> Block[M];

	int clock,kind,top;

	inline void Find(int u,int fa)
	{
		Dfn[u] = Low[u] = ++clock;
		Stack[++top] = u;

		for (int i = Fir[u];i;i = Nxt[i])
		{
			int go = To[i];
			if (!Dfn[go])
			{
				Find(go,u);
				Low[u] = std::min(Low[u],Low[go]);
			}
			else  if(go != fa) Low[u] = std::min(Dfn[go],Low[u]);
		}
		if (Low[u] == Dfn[u])
		{
			InBlock[u] = ++kind;Block[kind].push_back(u);
			while (Stack[top] != u)
				InBlock[Stack[top--]] = kind,Block[kind].push_back(Stack[top + 1]);
			--top;
		}
	}
}

using Tarjan::Find;
using Tarjan::InBlock;
using Tarjan::kind;

inline void AddEdge(int x,int y)
{
	Nxt[++tot] = Fir[x],To[tot] = y,Fir[x] = tot;
}

inline void Input()
{
	n = read();
	for (int i = 1;i <= n; ++i)
	{
		int u = read(),v = read();
		AddEdge(u,v);
		AddEdge(v,u);
	}
	Find(1,0);
}

inline void ReBuild(int u,int v)
{
	nxt[++tot] = fir[u],to[tot] = v,fir[u] = tot;
}

inline void GetAns()
{
	Q.push(std::make_pair(0,_s));
	In[_s] = 0;
	memset(Dis,127,sizeof Dis);
	Dis[_s] = 0;

	while (!Q.empty())
	{
		int now = Q.top().second;Q.pop();
		if (IsOut[now]) continue;
		IsOut[now] = 1;
		for (int i = fir[now];i;i = nxt[i])
		{
			int go = to[i];
			if (Dis[go] > Dis[now] + 1)
			{
				Dis[go] = Dis[now] + 1;
				Q.push(std::make_pair(-Dis[go],go));
			}
		}
	}
}

inline void Solve()
{
	for (int i = 1;i <= kind;++i)
		if (Tarjan::Block[i].size() > 1)
		{
			_s = i;
			break;
		}
	tot = 0;

	for (int i = 1;i <= n; ++i)
		for (int j = Fir[i];j;j = Nxt[j])
		{
			int go = To[j];
			if (InBlock[i] != InBlock[go] && !G[InBlock[i]][InBlock[go]])
				ReBuild(InBlock[i],InBlock[go]),ReBuild(InBlock[go],InBlock[i]),
				G[InBlock[i]][InBlock[go]] =
				G[InBlock[go]][InBlock[i]] = 1;
		}
	GetAns();
	for (int i = 1;i <= n; ++i)
		printf("%d%c",Dis[InBlock[i]],i == n ? '\n' : ' ');
}

int main(void)
{
	Input();
	Solve();
	return 0;
}


#include <stack>
#include <cstring>
#include <vector>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>

namespace IO
{
//	inline char gc(){
//        static char s[1<<20|1]={0},*p1=s,*p2=s;
//        return (p1==p2)&&(p2=(p1=s)+fread(s,1,1<<20,stdin),p1==p2)?EOF:*(p1++);
//    }
	inline char gc() { return getchar(); }
	inline int read()
	{
		register int ret=0;bool flag=0;register char c=gc();
		while ((c<'0')|(c>'9')) flag ^= !(c^'-'),c=gc();
		while ((c>='0')&(c<='9')) ret=(ret<<1)+(ret<<3)+(c^'0'),c=gc();
		return flag?-ret:ret;
 	}
 	char OutputAns[1<<20|1],*OutputCur = OutputAns;
 	inline void output() { OutputCur -= fwrite(OutputAns,1,OutputCur - OutputAns,stdout); }
 	inline void print(int ans)
 	{
 		char s[20]={0};
 		if (OutputCur - OutputAns + sprintf(s,"%d",ans) >> 20) output();
 		OutputCur += sprintf(OutputCur,"%d",ans);
	}
	inline void putc(char c)
	{
		if (OutputCur - OutputAns + 1 >> 20) output();
		*(OutputCur++) = c;
	}
}

using IO::read;
using IO::print;
using IO::output;
using IO::putc;

const int M = 3111;

int Nxt[M],To[M],Fir[M],Dis[M];

int nxt[M],to[M],fir[M],In[M];

bool Vis[M],G[M][M],IsOut[M];

int tot,n,_s;

std::priority_queue <std::pair <int,int> > Q;

namespace Tarjan
{
	int Low[M],Dfn[M],Stack[M],InBlock[M];

	std::vector <int> Block[M];

	int clock,kind,top;

	inline void Find(int u,int fa)
	{
		Dfn[u] = Low[u] = ++clock;
		Stack[++top] = u;

		for (int i = Fir[u];i;i = Nxt[i])
		{
			int go = To[i];
			if (!Dfn[go])
			{
				Find(go,u);
				Low[u] = std::min(Low[u],Low[go]);
			}
			else  if(go != fa) Low[u] = std::min(Dfn[go],Low[u]);
		}
		if (Low[u] == Dfn[u])
		{
			InBlock[u] = ++kind;Block[kind].push_back(u);
			while (Stack[top] != u)
				InBlock[Stack[top--]] = kind,Block[kind].push_back(Stack[top + 1]);
			--top;
		}
	}
}

using Tarjan::Find;
using Tarjan::InBlock;
using Tarjan::kind;

inline void AddEdge(int x,int y)
{
	Nxt[++tot] = Fir[x],To[tot] = y,Fir[x] = tot;
}

inline void Input()
{
	n = read();
	for (int i = 1;i <= n; ++i)
	{
		int u = read(),v = read();
		AddEdge(u,v);
		AddEdge(v,u);
	}
	Find(1,0);
}

inline void ReBuild(int u,int v)
{
	nxt[++tot] = fir[u],to[tot] = v,fir[u] = tot;
}

inline void GetAns()
{
	Q.push(std::make_pair(0,_s));
	memset(Dis,127,sizeof Dis);
	Dis[_s] = 0;

	while(Q.size())
    {
        int now = Q.top().second; Q.pop();

        if(Vis[now]) continue;
        Vis[now] = 1;
        for(int i = fir[now];i; i = nxt[i])
        {
            int go = to[i];
            int val = 1;
            if(Dis[go] > Dis[now] + val)
            {
                Dis[go] = Dis[now] + val;
                Q.push(std::make_pair(-Dis[go],go));
            }
        }
    }
}

inline void Solve()
{
	for (int i = 1;i <= kind;++i)
		if (Tarjan::Block[i].size() > 1)
		{
			_s = i;
			break;
		}
	tot = 0;

	for (int i = 1;i <= n; ++i)
		for (int j = Fir[i];j;j = Nxt[j])
		{
			int go = To[j];
			if (InBlock[i] != InBlock[go] && (!G[InBlock[i]][InBlock[go]]))
				ReBuild(InBlock[i],InBlock[go]),ReBuild(InBlock[go],InBlock[i]),
				G[InBlock[i]][InBlock[go]] =
				G[InBlock[go]][InBlock[i]] = 1;
		}
	GetAns();
	for (int i = 1;i <= n; ++i)
		printf("%d%c",Dis[InBlock[i]],i == n ? '\n' : ' ');
}

int main(void)
{
	Input();
	Solve();
	return 0;
}


#include <stack>
#include <cstring>
#include <vector>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>

namespace IO
{
//	inline char gc(){
//        static char s[1<<20|1]={0},*p1=s,*p2=s;
//        return (p1==p2)&&(p2=(p1=s)+fread(s,1,1<<20,stdin),p1==p2)?EOF:*(p1++);
//    }
	inline char gc() { return getchar(); }
	inline int read()
	{
		register int ret=0;bool flag=0;register char c=gc();
		while ((c<'0')|(c>'9')) flag ^= !(c^'-'),c=gc();
		while ((c>='0')&(c<='9')) ret=(ret<<1)+(ret<<3)+(c^'0'),c=gc();
		return flag?-ret:ret;
 	}
 	char OutputAns[1<<20|1],*OutputCur = OutputAns;
 	inline void output() { OutputCur -= fwrite(OutputAns,1,OutputCur - OutputAns,stdout); }
 	inline void print(int ans)
 	{
 		char s[20]={0};
 		if (OutputCur - OutputAns + sprintf(s,"%d",ans) >> 20) output();
 		OutputCur += sprintf(OutputCur,"%d",ans);
	}
	inline void putc(char c)
	{
		if (OutputCur - OutputAns + 1 >> 20) output();
		*(OutputCur++) = c;
	}
}

using IO::read;
using IO::print;
using IO::output;
using IO::putc;

const int M = 3111;

int Nxt[M],To[M],Fir[M],Dis[M];

int nxt[M],to[M],fir[M],In[M];

bool Vis[M],G[M][M],IsOut[M];

int tot,n,_s;

std::priority_queue <std::pair <int,int> > Q;

namespace Tarjan
{
	int Low[M],Dfn[M],Stack[M],InBlock[M];

	std::vector <int> Block[M];

	int clock,kind,top;

	inline void Find(int u,int fa)
	{
		Dfn[u] = Low[u] = ++clock;
		Stack[++top] = u;

		for (int i = Fir[u];i;i = Nxt[i])
		{
			int go = To[i];
			if (!Dfn[go])
			{
				Find(go,u);
				Low[u] = std::min(Low[u],Low[go]);
			}
			else  if(go != fa) Low[u] = std::min(Dfn[go],Low[u]);
		}
		if (Low[u] == Dfn[u])
		{
			InBlock[u] = ++kind;Block[kind].push_back(u);
			while (Stack[top] != u)
				InBlock[Stack[top--]] = kind,Block[kind].push_back(Stack[top + 1]);
			--top;
		}
	}
}

using Tarjan::Find;
using Tarjan::InBlock;
using Tarjan::kind;

inline void AddEdge(int x,int y)
{
	Nxt[++tot] = Fir[x],To[tot] = y,Fir[x] = tot;
}

inline void Input()
{
	n = read();
	for (int i = 1;i <= n; ++i)
	{
		int u = read(),v = read();
		AddEdge(u,v);
		AddEdge(v,u);
	}
	Find(1,0);
}

inline void ReBuild(int u,int v)
{
	nxt[++tot] = fir[u],to[tot] = v,fir[u] = tot;
}

inline void GetAns()
{
	Q.push(std::make_pair(0,_s));
	memset(Dis,127,sizeof Dis);
	Dis[_s] = 0;

	while (!Q.empty())
	{
		int now = Q.top().second;Q.pop();
		if (IsOut[now]) continue;
		IsOut[now] = 1;
		for (int i = fir[now];i;i = nxt[i])
		{
			int go = to[i];
			if (Dis[go] > Dis[now] + 1)
			{
				Dis[go] = Dis[now] + 1;
				Q.push(std::make_pair(-Dis[go],go));
			}
		}
	}
}

inline void Solve()
{
	for (int i = 1;i <= kind;++i)
		if (Tarjan::Block[i].size() > 1)
		{
			_s = i;
			break;
		}
	tot = 0;

	for (int i = 1;i <= n; ++i)
		for (int j = Fir[i];j;j = Nxt[j])
		{
			int go = To[j];
			if (InBlock[i] != InBlock[go] && (!G[InBlock[i]][InBlock[go]]))
				ReBuild(InBlock[i],InBlock[go]),ReBuild(InBlock[go],InBlock[i]),
				G[InBlock[i]][InBlock[go]] =
				G[InBlock[go]][InBlock[i]] = 1;
		}
	GetAns();
	for (int i = 1;i <= n; ++i)
		printf("%d%c",Dis[InBlock[i]],i == n ? '\n' : ' ');
}

int main(void)
{
	Input();
	Solve();
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

bool dfs(vector<vector<int>>& adj, vector<bool>& visited, vector<bool>& cycle, int parent, int curr) {
    bool incycle = false;

    for(auto i : adj[curr]) {
        if(i == parent) {
            continue;
        }

        if(visited[i]) {
            cycle[i] = true;
            incycle = true;
            break;
        }

        else {
            visited[i] = true;
            incycle |= dfs(adj, visited, cycle, curr, i);
        }
    }

    // If already part of a cycle, everything else won't be
    if(cycle[curr]) {
        incycle = false;
    }

    // If in a cycle, mark it
    if(incycle) {
        cycle[curr] = true;
    }

    // Return whether in a cycle
    return incycle;
}

int inf = 1 << 30;

int main() {
    int n;
    cin >> n;

    vector<vector<int>> adj(n);
    for(int i = 0; i < n; i++) {
        int n1, n2;
        cin >> n1 >> n2;
        n1--;
        n2--;
        adj[n1].push_back(n2);
        adj[n2].push_back(n1);
    }

    vector<bool> cycle(n, false);
    vector<bool> visited(n, false);
    visited[0] = true;
    dfs(adj, visited, cycle, 0, 0);

    vector<int> dist(n,inf);

    queue<int> q;
    for(int i = 0; i < n; i++) {
        if(cycle[i]) {
            dist[i] = 0;
            q.push(i);
        }
    }

    while(!q.empty()) {
        int curr = q.front();
        q.pop();

        for(auto i : adj[curr]) {
            if(dist[curr] + 1 < dist[i]) {
                dist[i] = dist[curr]+1;
                q.push(i);
            }
        }
    }

    for(auto i : dist) {
        cout << i << " ";
    }
    cout << endl;
}


#include <bits/stdc++.h>

using namespace std;

bool dfs(vector<vector<int>>& adj, vector<bool>& visited, vector<bool>& cycle, int parent, int curr) {
    bool incycle = false;
    bool breakcycle = false;

    for(auto i : adj[curr]) {
        if(i == parent) {
            continue;
        }

        if(visited[i]) {
            cycle[i] = true;
            incycle = true;
            break;
        }

        else {
            visited[i] = true;
            incycle |= dfs(adj, visited, cycle, curr, i);
        }
    }

    if(cycle[curr]) {
        breakcycle = true;
    }

    if(incycle) {
        cycle[curr] = true;
    }

    return incycle && !breakcycle;
}

int inf = 1 << 30;

int main() {
    int n;
    cin >> n;

    vector<vector<int>> adj(n);
    for(int i = 0; i < n; i++) {
        int n1, n2;
        cin >> n1 >> n2;
        n1--;
        n2--;
        adj[n1].push_back(n2);
        adj[n2].push_back(n1);
    }

    vector<bool> cycle(n, false);
    vector<bool> visited(n, false);
    dfs(adj, visited, cycle, -1, 0);

    vector<int> dist(n,inf);

    queue<int> q;
    for(int i = 0; i < n; i++) {
        if(cycle[i]) {
            dist[i] = 0;
            q.push(i);
        }
    }

    while(!q.empty()) {
        int curr = q.front();
        q.pop();

        for(auto i : adj[curr]) {
            if(dist[curr] + 1 < dist[i]) {
                dist[i] = dist[curr]+1;
                q.push(i);
            }
        }
    }

    for(auto i : dist) {
        cout << i << " ";
    }
    cout << endl;
}


#include <bits/stdc++.h>

using namespace std;

bool dfs(vector<vector<int>>& adj, vector<bool>& visited, vector<bool>& cycle, int parent, int curr) {
    bool incycle = false;
    for(auto i : adj[curr]) {
        if(i == parent) {
            continue;
        }

        if(visited[i]) {
            cycle[i] = true;
            incycle = true;
        }
        else {
            visited[i] = true;
            cycle[i] = dfs(adj, visited, cycle, curr, i);
            incycle |= cycle[i];
        }
    }

    return incycle;
}

int inf = 1 << 30;

int main() {
    int n;
    cin >> n;

    vector<vector<int>> adj(n);
    for(int i = 0; i < n; i++) {
        int n1, n2;
        cin >> n1 >> n2;
        n1--;
        n2--;
        adj[n1].push_back(n2);
        adj[n2].push_back(n1);
    }

    vector<bool> cycle(n, false);
    vector<bool> visited(n, false);
    dfs(adj, visited, cycle, -1, 0);

    vector<int> dist(n,inf);

    queue<int> q;
    for(int i = 0; i < n; i++) {
        if(cycle[i]) {
            dist[i] = 0;
            q.push(i);
        }
    }

    while(!q.empty()) {
        int curr = q.front();
        q.pop();

        for(auto i : adj[curr]) {
            if(dist[curr] + 1 < dist[i]) {
                dist[i] = dist[curr]+1;
                q.push(i);
            }
        }
    }

    for(auto i : dist) {
        cout << i << " ";
    }
    cout << endl;
}


#include <bits/stdc++.h>

using namespace std;

bool dfs(vector<vector<int>>& adj, vector<bool>& visited, vector<bool>& cycle, int parent, int curr) {
    bool incycle = false;
    for(auto i : adj[curr]) {
        if(i == parent) {
            continue;
        }

        if(visited[i]) {
            cycle[i] = true;
            incycle = true;
            break;
        }
        else {
            visited[i] = true;
            cycle[i] = dfs(adj, visited, cycle, curr, i);
            incycle |= cycle[i];
        }
    }

    return incycle;
}

int inf = 1 << 30;

int main() {
    int n;
    cin >> n;

    vector<vector<int>> adj(n);
    for(int i = 0; i < n; i++) {
        int n1, n2;
        cin >> n1 >> n2;
        n1--;
        n2--;
        adj[n1].push_back(n2);
        adj[n2].push_back(n1);
    }

    vector<bool> cycle(n, false);
    vector<bool> visited(n, false);
    dfs(adj, visited, cycle, -1, 0);

    vector<int> dist(n,inf);

    queue<int> q;
    for(int i = 0; i < n; i++) {
        if(cycle[i]) {
            dist[i] = 0;
            q.push(i);
        }
    }

    while(!q.empty()) {
        int curr = q.front();
        q.pop();

        for(auto i : adj[curr]) {
            if(dist[curr] + 1 < dist[i]) {
                dist[i] = dist[curr]+1;
                q.push(i);
            }
        }
    }

    for(auto i : dist) {
        cout << i << " ";
    }
    cout << endl;
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;

int vis[3002],parent[3001];

list<int> adjlist[3002];

vector<int> v;

pair<int,int> dfs1(int s)
{
    vis[s]=1;

    pair<int,int>  r;

    for(list<int> ::iterator it= adjlist[s].begin() ; it!=adjlist[s].end() ; it++)
    {
        if(vis[*it]==0)
        {
            //cout<<*it<<endl;
            parent[*it]=s;
            r=dfs1(*it);

            if(r.first!=-1)
                return  r;

        }
        else if(vis[*it]==1 && *it!=parent[s])
            {
                //cout<<s<<endl;
                //cout<<parent[s]<<" "<<*it<<endl;
                return make_pair(s,*it);
            }
    }
    vis[s]=2;
    return make_pair(-1,-1);
}
int d[3001];
void dfs(int s)
{
    vis[s]=1;

    for(list<int> ::iterator it= adjlist[s].begin() ; it!=adjlist[s].end() ; it++)
    {
        if(vis[*it]==0)
        {

                if(binary_search(v.begin(),v.end(),s))
                    {
                        d[*it]=1;
                        //cout<<s<<endl;
                    }
                else
                    d[*it]=d[s]+1;

                 dfs(*it);

        }
    }

}

int main()
{
    int n,x,y,i;
    cin>>n;

    memset(vis , 0 , sizeof(vis));

    for(i=1;i<=n;i++)
    {
        cin>>x>>y;
        adjlist[x].push_back(y);
        adjlist[y].push_back(x);
    }

    pair<int,int> ans=dfs1(1);

   memset(vis , 0 , sizeof(vis));

    int u=ans.first;
     //cout<<ans.first<<" "<<ans.second<<endl;
    while(u!=ans.second)
    {
        v.push_back(u);
        u=parent[u];

    }
    v.push_back(u);
    d[ans.first]=0;
    dfs(ans.first);
    for(i=0;i<v.size();i++)
        d[v[i]]=0;

        //for(i=0;i<v.size();i++)
          //  cout<<v[i]<<endl;

    for(i=1;i<=n;i++)
    {

        cout<<d[i]<<" ";
    }

    return 0;
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;

int vis[3002],parent[3001];

list<int> adjlist[3002];

vector<int> v;

pair<int,int> dfs1(int s)
{
    vis[s]=1;

    pair<int,int>  r;

    for(list<int> ::iterator it= adjlist[s].begin() ; it!=adjlist[s].end() ; it++)
    {
        if(vis[*it]==0)
        {
            //cout<<*it<<endl;
            parent[*it]=s;
            r=dfs1(*it);

            if(r.first!=-1)
                return  r;

        }
        else if(vis[*it]==1 && *it!=parent[s])
            {
                //cout<<s<<endl;
                //cout<<parent[s]<<" "<<*it<<endl;
                return make_pair(s,*it);
            }
    }
    vis[s]=2;
    return make_pair(-1,-1);
}
int d[3001];
void dfs(int s)
{
    vis[s]=1;

    for(list<int> ::iterator it= adjlist[s].begin() ; it!=adjlist[s].end() ; it++)
    {
        if(vis[*it]==0)
        {

                d[*it]=d[s]+1;

            dfs(*it);

        }
    }

}

int main()
{
    int n,x,y,i;
    cin>>n;

    memset(vis , 0 , sizeof(vis));

    for(i=1;i<=n;i++)
    {
        cin>>x>>y;
        adjlist[x].push_back(y);
        adjlist[y].push_back(x);
    }

    pair<int,int> ans=dfs1(1);

   memset(vis , 0 , sizeof(vis));

    int u=ans.first;
     //cout<<ans.first<<" "<<ans.second<<endl;
    while(u!=ans.second)
    {

        u=parent[u];
        v.push_back(u);

    }
    d[ans.first]=0;
    dfs(ans.first);
    for(i=0;i<v.size();i++)
        d[v[i]]=0;
    for(i=1;i<=n;i++)
    {

        cout<<d[i]<<" ";
    }

    return 0;
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;

int vis[3002],parent[3001];

list<int> adjlist[3002];

vector<int> v;

pair<int,int> dfs1(int s)
{
    vis[s]=1;

    pair<int,int>  r;

    for(list<int> ::iterator it= adjlist[s].begin() ; it!=adjlist[s].end() ; it++)
    {
        if(vis[*it]==0)
        {
            //cout<<*it<<endl;
            parent[*it]=s;
            r=dfs1(*it);

            if(r.first!=-1)
                return  r;

        }
        else if(vis[*it]==1 && *it!=parent[s])
            {
                //cout<<s<<endl;
                //cout<<parent[s]<<" "<<*it<<endl;
                return make_pair(s,*it);
            }
    }
    vis[s]=2;
    return make_pair(-1,-1);
}
//int d[3001];
int  dfs(int s , int d)
{
    vis[s]=1;

    if(binary_search(v.begin(),v.end(),s))
        return d;

        int r;

    for(list<int> ::iterator it= adjlist[s].begin() ; it!=adjlist[s].end() ; it++)
    {
        if(vis[*it]==0)
        {
          r=dfs(*it,d+1);

          if(r!=-1)
            return r;
        }
    }
    return -1;

}

int main()
{
    int n,x,y,i;
    cin>>n;

    memset(vis , 0 , sizeof(vis));

    for(i=1;i<=n;i++)
    {
        cin>>x>>y;
        adjlist[x].push_back(y);
        adjlist[y].push_back(x);
    }

    pair<int,int> ans=dfs1(1);

    int u=ans.first;
     //cout<<ans.first<<" "<<ans.second<<endl;
    while(u!=ans.second)
    {
        v.push_back(u);
        u=parent[u];

    }
    v.push_back(u);
    sort(v.begin(),v.end());
    //d[ans.first]=0;
    //dfs(1);
    /*for(i=0;i<v.size();i++)
        d[v[i]]=0;

        for(i=0;i<v.size();i++)
            cout<<v[i]<<endl;*/

         for(i=1;i<=n;i++)
         {
             memset(vis , 0 , sizeof(vis));
             cout<<dfs(i,0)<<" ";
         }

    /*for(i=1;i<=n;i++)
    {

        cout<<d[i]<<" ";
    }*/

    return 0;
}