import sys input = sys.stdin.readline from collections import * class UnionFind(object): def __init__(self, n=1): self.par = [i for i in range(n)] self.rank = [0 for _ in range(n)] self.size = [1 for _ in range(n)] def find(self, x): if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x != y: if self.rank[x] < self.rank[y]: x, y = y, x if self.rank[x] == self.rank[y]: self.rank[x] += 1 self.par[y] = x self.size[x] += self.size[y] def is_same(self, x, y): return self.find(x) == self.find(y) def get_size(self, x): x = self.find(x) return self.size[x] N = int(input()) A, B = [0] * N, [0] * N G = [[] for i in range(N)] U = UnionFind(N) Q = [] cnt = [0] * N ans, seen = [-1] * N, [0] * N for i in range(N): A[i], B[i] = map(int, input().split()) A[i], B[i] = A[i] - 1, B[i] - 1 if not U.is_same(A[i], B[i]): G[A[i]].append((B[i], i)) G[B[i]].append((A[i], i)) else: Q.append(deque([A[i]])) seen[A[i]] = 1 ans[i] = A[i] + 1 U.union(A[i], B[i]) for i in range(N): ui = U.find(A[i]) cnt[ui] += 1 if cnt[ui] > U.get_size(ui): print("No") exit() for qs in Q: while qs: u = qs.popleft() for v, ind in G[u]: if seen[v]: continue ans[ind] = v + 1 qs.append(v) seen[v] = 1 print("Yes") for a in ans: print(a)