#include #include using std::vector; int a[500005], b[500005]; struct Edge { int u, v; int id; }; vector g[500005]; int color[500005]; int cnt[500005]; int vis[500005]; Edge c[500005]; int stack[500005]; int top = 0; int set[500005]; void dfs(int u){ stack[++top] = u; vis[u] = 1; for(Edge e: g[u]){ int v = e.v; if(!vis[v]){ //color[id] = v; dfs(v); } } } void dfs1(int u){ //printf("u = %d\n",u); vis[u] = 1; set[u] = 1; for(Edge e: g[u]){ int v = e.v, id = e.id; //printf("v = %d\n",v); if(!color[id] && !vis[v]){ color[id] = v; dfs1(v); } } } int main(){ //printf("haha\n"); int n; scanf("%d",&n); for(int i = 1; i <= n; i++){ scanf("%d%d",&a[i],&b[i]); cnt[a[i]]++; cnt[b[i]]++; } for(int i = 1; i <= n; i++){ if(cnt[a[i]]==1){ color[i] = a[i]; vis[a[i]] = 1; //dfs1(a[i]); } else if(cnt[b[i]]==1){ color[i] = b[i]; vis[b[i]] = 1; //dfs1(a[i]); } else if(a[i]==b[i]){ color[i] = b[i]; vis[b[i]] = 1; //dfs1(a[i]); } else{ g[a[i]].push_back(Edge{a[i], b[i],i}); g[b[i]].push_back(Edge{b[i], a[i],i}); } } //printf("ok\n"); //for(int i = 1; i <= n; i++) if(vis[i] && !set[i]) dfs1(i); //printf("break\n"); for(int i = 1; i <= n; i++){ if(!vis[i]){ //printf("i = %d\n",i); int find = -1; int u = i; for(Edge e: g[u]){ if(!color[e.id]){ find = e.id; break; } } if(find==-1){ break; } else{ top = 0; //printf("find = %d: %d %d\n",find,a[find],b[find]); color[find] = a[find]; dfs(a[find]); int bad = !vis[b[find]]; for(int j = 1; j <= top; j++) vis[stack[j]] = 0; if(bad){ top = 0; //printf("haha\n"); color[find] = b[find]; dfs(b[find]); int bb = !vis[a[find]]; for(int j = 1; j <= top; j++) vis[stack[j]] = 0; if(bb) break; else{ dfs1(b[find]); } } else dfs1(a[find]); } } } int find = 0; for(int i = 1; i <= n; i++){ if(!vis[i]) find = 1; } if(find) printf("No\n"); else{ printf("Yes\n"); for(int i = 1; i <= n; i++) printf("%d\n",color[i]); } return 0; }