#include using namespace std; struct UnionFind{ vector par; vector rank; vector cnt; UnionFind(int n){ par.resize(n); rank.resize(n); cnt.resize(n, 0); for(int i = 0; i < n; i++){ par[i] = i; rank[i] = 1; } } int root(int x){ if(par[x] == x) return x; else return par[x] = root(par[x]); } bool same(int x, int y){ return root(x) == root(y); } void unite(int x, int y){ x = root(x); y = root(y); if(x == y) { cnt[x] += 1; return; } if(rank[x] < rank[y]) swap(x, y); par[y] = x; rank[x] += rank[y]; cnt[x] += cnt[y] + 1; } int size(int x) { return rank[root(x)]; } int count(int x){ return cnt[root(x)]; } }; int main(){ int N; cin >> N; vector A(N), B(N); UnionFind U(N); vector>> G(N); for(int i = 0; i < N; i++) { cin >> A[i] >> B[i]; A[i]--; B[i]--; U.unite(A[i], B[i]); G[A[i]].push_back({B[i], i}); G[B[i]].push_back({A[i], i}); } vector used(N, false); bool f = true; for(int i = 0; i < N; i++){ int t = U.root(i); if(used[t]) continue; used[t] = true; if(U.size(i) != U.count(i)) f = false; } if(!f) cout << "No" << endl; else{ cout << "Yes" << endl; vector ans(N, -1); vector use(N, false); used.assign(N, false); vector used_root(N, false); auto dfs = [&](auto dfs, int now) -> void{ for(auto [to, ind] : G[now]){ if(use[ind]) continue; if(used[to]){ ans[ind] = now; use[ind] = true; used[now] = true; break; } } for(auto [to, ind] : G[now]){ if(use[ind]) continue; if(used[to]) continue; if(!used[now]){ ans[ind] = now; used[now] = true; use[ind] = true; } dfs(dfs, to); } }; for(int i = 0; i < N; i++){ if(!used_root[U.root(i)]) { used_root[U.root(i)] = true; dfs(dfs, i); } } for(int i = 0; i < N; i++) cout << ans[i] + 1 << endl; } }