#include #include #define rep(i, n) for (int i = 0; i < (n); i++) #define rrep(i, n) for (int i = (n - 1); i >= 0; i--) #define ALL(v) v.begin(), v.end() #define pb push_back using namespace std; using namespace atcoder; using P = pair; using Graph = vector>; typedef long long ll; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; Graph G; bool non_tree[400000]; vector bfs(vector start, int n){ vector dist(n, 1e9); vector pre(n, -1); queue que; for(auto d : start){ dist[d] = 0; que.push(d); } while (!que.empty()){ int v = que.front(); que.pop(); for(int u: G[v]){ if(dist[u] != 1e9) continue; dist[u] = dist[v] + 1; pre[u] = v; que.push(u); } } return dist; } int main() { int n; cin >> n; dsu d(n); vector

res; vector cn(n); G.resize(n); rep(i, n){ int a, b; cin >> a >> b; a--, b--; cn[a]++; cn[b]++; G[a].pb(b); G[b].pb(a); res.push_back({a, b}); if(d.same(a, b)){ non_tree[d.leader(a)] = true; } if(non_tree[d.leader(a)] | non_tree[d.leader(b)]){ d.merge(a, b); non_tree[d.leader(a)] = true; } d.merge(a, b); } int ans = 0; rep(i, n){ if(d.leader(i) != i)continue; if(!non_tree[i]){ cout << "No" << endl; return 0; } } int s = -1; int e = n; rep(i, n){ chmin(e, cn[i]); } vector start; rep(i, n){ if(cn[i] == e)start.pb(i); } vector dist = bfs(start, n); cout << "Yes" << endl; set st; vector used(n, 0); rep(i, n){ int a = res[i].first; int b = res[i].second; if(used[a] == 0 && used[b] == 0){ if(dist[a] < dist[b]){ cout << a + 1 << endl; used[a]++; }else{ cout << b + 1 << endl; used[b]++; } }else if(used[b] == 0){ cout << b + 1 << endl; used[b]++; }else{ cout << a + 1 << endl; used[a]++; } } }