#include #include #include template struct Edge { int from, to; T cost; int idx; Edge() = default; Edge(int from, int to, T cost = 1, int idx = 0) : from(from), to(to), cost(cost), idx(idx) {} }; template struct Graph { std::vector>> es; int edge_num; Graph(int n) : edge_num(0) { es.resize(n); } int size() { return es.size(); } void add_edge(int from, int to, T cost = 1, int idx = 0) { es[from].emplace_back(from, to, cost, idx); ++edge_num; } std::vector> edges() { std::vector> tmp; for (int v = 0; v < (int)es.size(); ++v) { for (auto& e : es[v]) { tmp.push_back(e); } } if (tmp.size() >= 2 && tmp[0].idx == tmp[1].idx) { return tmp; } std::vector> res(edge_num); for (auto& e : tmp) res[e.idx] = e; return res; } std::vector>& operator[](int i) { return es[i]; } }; #include #include #include template bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } template T div_floor(T a, T b) { if (b < 0) a *= -1, b *= -1; return a >= 0 ? a / b : (a + 1) / b - 1; } template T div_ceil(T a, T b) { if (b < 0) a *= -1, b *= -1; return a > 0 ? (a - 1) / b + 1 : a / b; } template struct CoordComp { std::vector v; bool sorted; CoordComp() : sorted(false) {} int size() { return v.size(); } void add(T x) { v.push_back(x); } void build() { std::sort(v.begin(), v.end()); v.erase(std::unique(v.begin(), v.end()), v.end()); sorted = true; } int get_idx(T x) { assert(sorted); return lower_bound(v.begin(), v.end(), x) - v.begin(); } T &operator[](int i) { return v[i]; } }; #define For(i, a, b) for (int i = (int)(a); (i) < (int)(b); ++(i)) #define rFor(i, a, b) for (int i = (int)(a)-1; (i) >= (int)(b); --(i)) #define rep(i, n) For(i, 0, n) #define rrep(i, n) rFor(i, n, 0) #define fi first #define se second using namespace std; using lint = long long; using pii = pair; using pll = pair; using namespace atcoder; int get_back(int v, int pv, Graph<> &gr, vector &used) { used[v] = true; for (auto &e : gr[v]) { if (e.to == pv) continue; if (used[e.to]) return e.idx; int tmp = get_back(e.to, v, gr, used); if (tmp >= 0) return tmp; } return -1; } void dfs(int v, int pv, Graph<> &gr, vector &col, vector &ans) { for (auto &e : gr[v]) { if (e.to == pv || col[e.to]) continue; col[e.to] = 1; ans[e.idx] = e.to; dfs(e.to, v, gr, col, ans); } } int main() { int n; scanf("%d", &n); Graph gr(n); rep(i, n) { int a, b; scanf("%d%d", &a, &b); --a; --b; gr.add_edge(a, b, 1, i); gr.add_edge(b, a, 1, i); } auto es = gr.edges(); dsu uf(n); for (auto &e : es) uf.merge(e.from, e.to); vector cnt(n, 0); for (auto &e : es) ++cnt[uf.leader(e.from)]; rep(i, n) if (i == uf.leader(i)) { if (uf.size(i) > cnt[i]) { puts("No"); return 0; } } vector col(n, 0), ans(es.size(), -1); vector used(n, false); rep(i, n) if (col[i] == 0) { int b = get_back(i, -1, gr, used); ans[b] = es[b].from; col[es[b].from] = 1; dfs(es[b].from, -1, gr, col, ans); } puts("Yes"); rep(i, n) printf("%d\n", ans[i] + 1); }