//============================================================================
// Name : Brahmi Zied
// Author : brahZied
// Version : 2022
// Description : Road to specialist
//============================================================================
/*
STAY ORGANIZED
CHANGE YOUR APPROACH
BE CONFIDENT
*/
// when you train write the algos from 0
//Think different approaches (trace TestCase,think with symbols,think with PICS,numberTheory,bs,dp,greedy,graphs,shortest paths,mst,dsu,LCA(binary lifting?))
//Stay Calm
// IN TRAINING DO NOT SEE WRONG TEST CASES AFTER SUBMITTING!
//Look for special cases
//Beware of overflow and array bounds
//Think the problem backwards
#include <bits/stdc++.h>
using namespace std;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; } ;
sim > rge< c> range( c i, c j) { return rge< c> { i, j} ; }
sim > auto dud( c* x) - > decltype( cerr << * x, 0 ) ;
sim > char dud( ...) ;
struct debug {
#ifdef LOCAL
~debug( ) { cerr << endl; }
eni( ! = ) cerr << boolalpha << i; ris; }
eni( == ) ris << range( begin( i) , end( i) ) ; }
sim, class b dor( pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")" ;
}
sim dor( rge< c> d) {
* this << "[" ;
for ( auto it = d.b ; it ! = d.e ; ++ it)
* this << ", " + 2 * ( it == d.b ) << * it;
ris << "]" ;
}
#else
sim dor( const c& ) { ris; }
#endif
} ;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long long ll;
typedef long double ld;
ll n,m,k,g,a,b,d,c;
const ll prime= 1e9 + 7 ;
const int nax= 2e5 + 5 ;
vector< int > adj[ nax] ;
int nodeFurthest= - 1 ;
int furthest= - 1 ;
void dfs( int node,int parent,int level) {
if ( level>= furthest) {
nodeFurthest= node;
furthest= level;
}
for ( int i= 0 ; i< ( int ) adj[ node] .size ( ) ; i++ ) {
if ( adj[ node] [ i] ! = parent) {
dfs( adj[ node] [ i] ,node,level+ 1 ) ;
}
}
}
void dfs1( int node,int parent) {
cout << node+ 1 << " " ;
for ( int i= 0 ; i< ( int ) adj[ node] .size ( ) ; i++ ) {
if ( adj[ node] [ i] ! = parent) {
dfs1( adj[ node] [ i] ,node) ;
}
}
}
void solve( ) {
cin >> n ;
int from,to;
for ( int i= 0 ; i< n- 1 ; i++ ) {
cin >> from >> to;
from-- ;
to-- ;
adj[ from] .push_back ( to) ;
adj[ to] .push_back ( from) ;
}
dfs( from,- 1 ,0 ) ;
dfs( nodeFurthest,- 1 ,0 ) ;
if ( furthest<= 3 ) {
cout << "NO" << "\n " ;
return ;
}
int curr ,next;
for ( int i= 0 ; i< n; i++ ) {
if ( ( int ) adj[ i] .size ( ) <= 1 ) continue ;
for ( int j= 0 ; j< ( int ) adj[ i] .size ( ) ; j++ ) {
if ( adj[ adj[ i] [ j] ] .size ( ) >= 2 ) {
next= adj[ i] [ j] ;
curr= i;
break ;
}
}
}
debug( ) << imie( curr) << imie( next) ;
cout << "YES" << "\n " ;
dfs1( curr,next) ;
dfs1( next,curr) ;
cout << "\n " ;
}
int main( ) {
fastInp;
//freopen("mootube.in","r",stdin);
//freopen("t.out","w",stdout);
int tc= 1 ;
//cout << res[9] << "\n";
//reverse(res.begin(),res.end());
//cin >> tc;
//cout << setprecision(10)<<fixed;
//int i=1;
//tempTC=tc;
while ( tc-- ) {
//cout <<"HELLO"<<endl;
//cout << "Case #"<<i<<": " ;
//cout << setprecision(10) << "\n";
solve( ) ;
//i++;
}
/*Slong long number;
while(cin >> number){
if(number==0) break;
long long i=(long long)sqrt(number);
if(i*i==number){
cout <<"yes"<<"\n";
}else{
cout <<"no"<<"\n";
}
}*/
/*while(true){
cin >> n >> m >>coin;
if(n==0 && m==0&&coin==0){
break;
}
solveUVA();
}
*/
return 0 ;
}
Ly89PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09Ci8vIE5hbWUgICAgIC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