#include using namespace std; struct iofast_t { iofast_t() { ios::sync_with_stdio(false); cin.tie(nullptr); } } iofast; struct uns_t {} uns; template auto vec(Element init, Head arg, Args ...args) { if constexpr (sizeof...(Args) == 0) return std::vector(arg, init); else return std::vector(arg, vec(init, args...)); } template auto vec(uns_t, Head arg, Args ...args) { return vec(Element(), arg, args...); } template > T &chmin(T &l, T r, Compare &&f = less()) { return l = min(l, r, f); } template > T &chmax(T &l, T r, Compare &&f = less()) { return l = max(l, r, f); } #include int main() { int n; cin >> n; auto g = vec>(uns, n, 0); atcoder::dsu dsu1(n); for (int i = 0; i < n; ++i) { int a, b; cin >> a >> b; --a; --b; g[a].push_back({ b, i }); g[b].push_back({ a, i }); dsu1.merge(a, b); } auto groups = dsu1.groups(); for (auto &group : groups) { set edge; for (auto v : group) { for (auto [u, c] : g[v]) { edge.insert(c); } } if (size(group) < size(edge)) { cout << "No" << endl; return 0; } } auto ans = vec(uns, n); auto used = vec(false, n); auto vis = vec(false, n); auto fin = vec(false, n); for (auto &group : groups) { stack hist; int con = -1; auto dfs = [&](auto &&self, int v, int p = -1) -> bool { vis[v] = true; hist.push(v); for (auto [u, _] : g[v]) { if (p == _) { continue; } if (fin[u]) { continue; } if (vis[u] && !fin[u]) { con = u; return true; } if (self(self, u, _)) { return true; } } hist.pop(); fin[v] = true; return false; }; if (!dfs(dfs, group[0])) { cout << "No" << endl; return 0; } set cycle; int cur = con; while (!empty(hist)) { int u = hist.top(); hist.pop(); for (auto [_, c] : g[cur]) { if (u != _) { continue; } ans[c] = u; used[c] = true; break; } cur = u; cycle.insert(u); if (u == con) { break; } } for (auto v : cycle) { queue que; que.push(v); while (!empty(que)) { int v = que.front(); que.pop(); for (auto [u, c] : g[v]) { if (used[c]) { continue; } ans[c] = u; used[c] = true; que.push(u); } } } } cout << "Yes" << endl; for (auto v : ans) { cout << v + 1 << endl; } }