#include //#include //#include using namespace std; //using namespace atcoder; //using namespace boost::multiprecision; #define fs first #define sc second #define pb push_back #define mp make_pair #define eb emplace_back #define ALL(A) A.begin(),A.end() #define RALL(A) A.rbegin(),A.rend() typedef long long ll; typedef pair P; 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; } template T gcd(T a,T b){return b?gcd(b,a%b):a;} const ll mod=1e9 + 7; const ll LINF=1ll<<60; const int INF=1<<30; //int dx[]={0,1,0,-1,0,1,-1,1,-1}; //int dy[]={0,0,1,0,-1,1,-1,-1,1}; int dx[]={0,0,1,-1}; int dy[]={-1,1,0,0}; const int M_N=500001; struct UnionFind{ int par[M_N]; int rank[M_N]; int sz[M_N]; int p[M_N]; void init(int n){ for(int i=0;i G[1<<17]; map, int> id; vector Ans(1 << 17, 0); vector used(1 << 17, false); set s; void dfs(int u, int v){ for(auto g:G[u]){ if(g == v) continue; if(used[id[{u, g}]]) continue; used[id[{u, g}]] = true; Ans[id[{u, g}]] = g + 1; s.insert(g + 1); dfs(g, u); } return; } int main(){ int n;cin >> n; vector a(n),b(n); UnionFind uf; uf.init(n); vector f(n , false); for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; a[i]--,b[i]--; G[a[i]].pb(b[i]); G[b[i]].pb(a[i]); id[{a[i], b[i]}] = i; id[{b[i], a[i]}] = i; uf.unite(a[i],b[i]); if(uf.getp(a[i]) == uf.size(a[i])) f[a[i]] = true; } int ans = 0; for (int i = 0; i < n; i++) { if(uf.find(i)==i){ if(uf.getp(i) >= uf.size(i)) ans += uf.size(i); else ans += uf.size(i) - 1; } } if(ans == n){ puts("Yes"); for (int i = 0; i < n; i++) { if(f[i]) dfs(i, i); } for (int i = 0; i < n; i++) { if(Ans[i] == 0){ if(s.find(a[i] + 1) == s.end()) cout << a[i] + 1 << endl; else cout << b[i] + 1 << endl; } else{ cout << Ans[i] << endl; } } } else puts("No"); return 0; }