https://ac.nowcoder.com/acm/contest/82526/F
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
#define oz 998244353
#define N 200010
#define INF 0x3f3f3f3f
typedef long long ll;
#define endl '\n'
const int mod = 1e9 + 7;
int f[N], vis[N]; //f存答案 vis存边的访问状态
vector<pair<int, int>> v[N]; //pair存邻边和边的编号
int n;
void dfs(int x, int dep) {
if (x == n) {
for (int i = 1; i <= n; i++) {
if (!vis[i])f[i] = min(f[i], dep); //此条路径上没有的边,删除之后最短路为当前深度
}
return ;
}
for (auto [now, idx] : v[x]) {
if (!vis[idx]) {
vis[idx] = 1;
dfs(now, dep + 1);
vis[idx] = 0;
}
}
}
void solve() {
// int n;
cin >> n;
for (int i = 1; i <= n; i++) {
int x, y;
cin >> x >> y;
f[i] = 1e9;
v[x].push_back({y, i});
v[y].push_back({x, i});
}
dfs(1, 0);
for (int i = 1; i <= n; i++) {
if(f[i] > 1e6)cout << -1 << endl;
else cout << f[i] << endl;
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int T = 1;
// cin >> T;
while (T --)
solve();
return 0;
}