#include <bits/stdc++.h>
#define pb push_back
#define MOD 1000000007
#define lll long long
#define mp make_pair
#define fi first
#define se second
using namespace std;

const int NR = 363304 + 10 ;

void boost ()    {
    #ifndef ONLINE_JUDGE
    freopen("date.in", "r", stdin);
   // freopen("scmax.out", "w", stdout);
    #endif
     ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
}

string s ;
int n , cati_sell , cati_buy ;
vector < pair < bool , int > > st;
vector <int> all , not_know ;
vector <int> Tree_buy ( NR << 2, 0 ) ;
vector <int> Tree_sell ( NR << 2, 0 ) ;

void element_update_sell ( int nod , int st , int dr , int pos )    {
    if ( st == dr ) {
        Tree_buy[ nod ] = 0 ;
        Tree_sell [ nod ] = 1 ;
        return ;
    }
    int mij = ( st + dr ) >> 1 ;
    if ( pos <= mij )   element_update_sell( nod << 1 , st , mij , pos ) ;
    else                element_update_sell( nod << 1 | 1 , mij + 1 , dr , pos ) ;

    Tree_buy [ nod ] = Tree_buy [ nod << 1 ] + Tree_buy [ nod << 1 | 1 ] ;
    Tree_sell [ nod ] = Tree_sell [ nod << 1 ] + Tree_sell [ nod << 1 | 1 ] ;
}

void element_update_buy ( int nod , int st , int dr , int pos )    {
    if ( st == dr ) {
        Tree_buy[ nod ] = 1 ;
        Tree_sell [ nod ] = 0 ;
        return ;
    }
    int mij = ( st + dr ) >> 1 ;
    if ( pos <= mij )   element_update_buy( nod << 1 , st , mij , pos ) ;
    else                element_update_buy( nod << 1 | 1 , mij + 1 , dr , pos ) ;

    Tree_buy [ nod ] = Tree_buy [ nod << 1 ] + Tree_buy [ nod << 1 | 1 ] ;
    Tree_sell [ nod ] = Tree_sell [ nod << 1 ] + Tree_sell [ nod << 1 | 1 ] ;
}

void element_update_neutru ( int nod , int st , int dr , int pos )    {
    if ( st == dr ) {
        Tree_buy[ nod ] = 0 ;
        Tree_sell [ nod ] = 0 ;
        return ;
    }
    int mij = ( st + dr ) >> 1 ;
    if ( pos <= mij )   element_update_neutru( nod << 1 , st , mij , pos ) ;
    else                element_update_neutru( nod << 1 | 1 , mij + 1 , dr , pos ) ;

    Tree_buy [ nod ] = Tree_buy [ nod << 1 ] + Tree_buy [ nod << 1 | 1 ] ;
    Tree_sell [ nod ] = Tree_sell [ nod << 1 ] + Tree_sell [ nod << 1 | 1 ] ;
}

int range_query_sell( int nod , int st , int dr , int a , int b )  {
    if ( st == dr ) {
        return Tree_sell [ nod ] ;
    }
    int mij = ( st + dr ) >> 1 , sol_st = 0 , sol_dr = 0 ;
    if ( a <= mij )   sol_st = range_query_sell( nod << 1 , st , mij , a , b ) ;
    if ( mij <  b )   sol_dr = range_query_sell( nod << 1 | 1 , mij + 1 , dr , a , b ) ;

    return sol_st + sol_dr ;
}

int range_query_buy( int nod , int st , int dr , int a , int b )  {
    if ( st == dr ) {
         return Tree_buy [ nod ] ;
    }
    int mij = ( st + dr ) >> 1 , sol_st = 0 , sol_dr = 0 ;
    if ( a <= mij )   sol_st = range_query_buy( nod << 1 , st , mij , a , b ) ;
    if ( mij <  b )   sol_dr = range_query_buy( nod << 1 | 1 , mij + 1 , dr , a , b ) ;

    return sol_st + sol_dr ;
}

int element_query ( int nod , int st , int dr , int pos )    {
        if ( st == dr ) {
                if ( Tree_sell [ nod ] == 1 )
                    return 1 ;
                if ( Tree_buy [ nod ] == 1 )
                    return 2 ;
        return 0 ;
    }
    int mij = ( st + dr ) >> 1 ;
    if ( pos <= mij )   return element_query( nod << 1 , st , mij , pos ) ;
    else                return element_query( nod << 1 | 1 , mij + 1 , dr , pos ) ;

}

int main(){
    boost() ;
    int x , i , act , sol = 1 , base ;
    cin >> n ;
    for ( i = 1 ; i <= n ; ++ i )   {
        cin >> s >> x ;
        all.pb(x);
        if ( s == "ADD" )
            st.pb( mp ( 1 , x ) ) ;
        else
            st.pb( mp ( 0 , x ) ) ;
    }

    sort(all.begin(), all.end());
  	all.erase(unique(all.begin(), all.end()), all.end());
    auto norm = [&](int x) {
    	return lower_bound(all.begin(), all.end(), x) - all.begin() + 1;
  	};

    for ( i = 0 ; i < n ; ++ i )   {
            if (  st [ i ].fi == 1 )    {
                    cati_sell = range_query_sell( 1 , 1 , n + 5 , 1 , norm ( st[i].se ) ) ;
                    cati_buy  = range_query_buy ( 1 , 1 , n + 5 , norm ( st[i].se ) , n ) ;

                    if ( cati_sell )    {
                        element_update_sell ( 1 , 1 , n + 5 , norm ( st[i].se ) ) ;
                    }
                    if ( cati_buy )    {
                        element_update_buy ( 1 , 1 , n + 5 , norm ( st[i].se ) ) ;
                    }
                    if ( !cati_buy && !cati_sell )  {
                        not_know.pb( st [ i ].se ) ;
                    }
            }   else    {
                while ( !not_know.empty() ) {
                    if ( not_know.back() > st [ i ].se )    {
                        element_update_sell ( 1 , 1 , n + 5 , norm ( not_know.back() ) ) ;
                    }   else    {
                        element_update_buy ( 1 , 1 , n + 5 , norm ( not_know.back() ) ) ;
                    }
                    not_know.pop_back();
                }
                act       = element_query ( 1 , 1 , n + 5 , st [i].se ) ;
                cati_sell = range_query_sell( 1 , 1 , n + 5 , 1 , norm ( st[i].se ) ) ;
                cati_buy  = range_query_buy ( 1 , 1 , n + 5 , norm ( st[i].se ) , n ) ;

                if ( act == 1 ) cati_sell -- ;
                if ( act == 2 ) cati_buy  -- ;

                if ( !cati_sell && !cati_buy ) sol = ( 1LL * sol * 2 ) % MOD ;

                if ( cati_sell || cati_buy )
                    return cout << 0 , 0 ;

                element_update_neutru ( 1 , 1 , n + 5 , norm( st [ i ].se ) ) ;

            }
    }
    base = sol ;
    sol = 0 ;
    for ( i = 0 ; i < not_know.size() ; ++ i )  {

        cati_sell = range_query_sell( 1 , 1 , n + 5 , 1 , norm ( not_know[i] ) ) ;
        cati_buy  = range_query_buy ( 1 , 1 , n + 5 , norm ( not_know[i] ) , n ) ;

        if ( !cati_sell && !cati_buy )  {
            sol = 1LL * ( sol + base * 2 ) % MOD ;
        }
    }

    cout << max ( sol , base ) << '\n' ;

}


#include <bits/stdc++.h>
#define pb push_back
#define MOD 1000000007
#define lll long long
#define mp make_pair
#define fi first
#define se second
using namespace std;

const int NR = 363304 + 10 ;

void boost ()    {
    #ifndef ONLINE_JUDGE
    freopen("date.in", "r", stdin);
   // freopen("scmax.out", "w", stdout);
    #endif
     ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
}

string s ;
int n , cati_sell , cati_buy ;
vector < pair < bool , int > > st;
vector <int> all , not_know ;
vector <int> Tree_buy ( NR << 2, 0 ) ;
vector <int> Tree_sell ( NR << 2, 0 ) ;

void element_update_sell ( int nod , int st , int dr , int pos )    {
    if ( st == dr ) {
        Tree_buy[ nod ] = 0 ;
        Tree_sell [ nod ] = 1 ;
        return ;
    }
    int mij = ( st + dr ) >> 1 ;
    if ( pos <= mij )   element_update_sell( nod << 1 , st , mij , pos ) ;
    else                element_update_sell( nod << 1 | 1 , mij + 1 , dr , pos ) ;

    Tree_buy [ nod ] = Tree_buy [ nod << 1 ] + Tree_buy [ nod << 1 | 1 ] ;
    Tree_sell [ nod ] = Tree_sell [ nod << 1 ] + Tree_sell [ nod << 1 | 1 ] ;
}

void element_update_buy ( int nod , int st , int dr , int pos )    {
    if ( st == dr ) {
        Tree_buy[ nod ] = 1 ;
        Tree_sell [ nod ] = 0 ;
        return ;
    }
    int mij = ( st + dr ) >> 1 ;
    if ( pos <= mij )   element_update_buy( nod << 1 , st , mij , pos ) ;
    else                element_update_buy( nod << 1 | 1 , mij + 1 , dr , pos ) ;

    Tree_buy [ nod ] = Tree_buy [ nod << 1 ] + Tree_buy [ nod << 1 | 1 ] ;
    Tree_sell [ nod ] = Tree_sell [ nod << 1 ] + Tree_sell [ nod << 1 | 1 ] ;
}

void element_update_neutru ( int nod , int st , int dr , int pos )    {
    if ( st == dr ) {
        Tree_buy[ nod ] = 0 ;
        Tree_sell [ nod ] = 0 ;
        return ;
    }
    int mij = ( st + dr ) >> 1 ;
    if ( pos <= mij )   element_update_neutru( nod << 1 , st , mij , pos ) ;
    else                element_update_neutru( nod << 1 | 1 , mij + 1 , dr , pos ) ;

    Tree_buy [ nod ] = Tree_buy [ nod << 1 ] + Tree_buy [ nod << 1 | 1 ] ;
    Tree_sell [ nod ] = Tree_sell [ nod << 1 ] + Tree_sell [ nod << 1 | 1 ] ;
}

int range_query_sell( int nod , int st , int dr , int a , int b )  {
    if ( st == dr ) {
        return Tree_sell [ nod ] ;
    }
    int mij = ( st + dr ) >> 1 , sol_st = 0 , sol_dr = 0 ;
    if ( a <= mij )   sol_st = range_query_sell( nod << 1 , st , mij , a , b ) ;
    if ( mij <  b )   sol_dr = range_query_sell( nod << 1 | 1 , mij + 1 , dr , a , b ) ;

    return sol_st + sol_dr ;
}

int range_query_buy( int nod , int st , int dr , int a , int b )  {
    if ( st == dr ) {
         return Tree_buy [ nod ] ;
    }
    int mij = ( st + dr ) >> 1 , sol_st = 0 , sol_dr = 0 ;
    if ( a <= mij )   sol_st = range_query_buy( nod << 1 , st , mij , a , b ) ;
    if ( mij <  b )   sol_dr = range_query_buy( nod << 1 | 1 , mij + 1 , dr , a , b ) ;

    return sol_st + sol_dr ;
}

int element_query ( int nod , int st , int dr , int pos )    {
        if ( st == dr ) {
                if ( Tree_sell [ nod ] == 1 )
                    return 1 ;
                if ( Tree_buy [ nod ] == 1 )
                    return 2 ;
        return 0 ;
    }
    int mij = ( st + dr ) >> 1 ;
    if ( pos <= mij )   return element_query( nod << 1 , st , mij , pos ) ;
    else                return element_query( nod << 1 | 1 , mij + 1 , dr , pos ) ;

}

int main(){
    boost() ;
    int x , i , act , sol = 1 , base ;
    cin >> n ;
    for ( i = 1 ; i <= n ; ++ i )   {
        cin >> s >> x ;
        all.pb(x);
        if ( s == "ADD" )
            st.pb( mp ( 1 , x ) ) ;
        else
            st.pb( mp ( 0 , x ) ) ;
    }

    sort(all.begin(), all.end());
  	all.erase(unique(all.begin(), all.end()), all.end());
    auto norm = [&](int x) {
    	return lower_bound(all.begin(), all.end(), x) - all.begin() + 1;
  	};

    for ( i = 0 ; i < n ; ++ i )   {
            if (  st [ i ].fi == 1 )    {
                    cati_sell = range_query_sell( 1 , 1 , n + 5 , 1 , norm ( st[i].se ) ) ;
                    cati_buy  = range_query_buy ( 1 , 1 , n + 5 , norm ( st[i].se ) , n ) ;

                    if ( cati_sell )    {
                        element_update_sell ( 1 , 1 , n + 5 , norm ( st[i].se ) ) ;
                    }
                    if ( cati_buy )    {
                        element_update_buy ( 1 , 1 , n + 5 , norm ( st[i].se ) ) ;
                    }
                    if ( !cati_buy && !cati_sell )  {
                        not_know.pb( st [ i ].se ) ;
                    }
            }   else    {
                while ( !not_know.empty() ) {
                    if ( not_know.back() > st [ i ].se )    {
                        element_update_sell ( 1 , 1 , n + 5 , norm ( not_know.back() ) ) ;
                    }
                    if ( not_know.back() < st [ i ].se )    {
                        element_update_buy ( 1 , 1 , n + 5 , norm ( not_know.back() ) ) ;
                    }
                    not_know.pop_back();
                }
                act       = element_query ( 1 , 1 , n + 5 , st [i].se ) ;
                cati_sell = range_query_sell( 1 , 1 , n + 5 , 1 , norm ( st[i].se ) ) ;
                cati_buy  = range_query_buy ( 1 , 1 , n + 5 , norm ( st[i].se ) , n ) ;

                if ( act == 1 ) cati_sell -- ;
                if ( act == 2 ) cati_buy  -- ;

                if ( !cati_sell && !cati_buy ) sol = ( 1LL * sol * 2 ) % MOD ;

                if ( cati_sell || cati_buy )
                    return cout << 0 , 0 ;

                element_update_neutru ( 1 , 1 , n + 5 , norm( st [ i ].se ) ) ;

            }
    }
    base = sol ;
    sol = 0 ;
    for ( i = 0 ; i < not_know.size() ; ++ i )  {

        cati_sell = range_query_sell( 1 , 1 , n + 5 , 1 , norm ( not_know[i] ) ) ;
        cati_buy  = range_query_buy ( 1 , 1 , n + 5 , norm ( not_know[i] ) , n ) ;

        if ( !cati_sell && !cati_buy )  {
            sol = 1LL * ( sol + base * 2 ) % MOD ;
        }
    }

    cout << max ( sol , base ) << '\n' ;

}


#include <bits/stdc++.h>
#define pb push_back
#define MOD 1000000007
#define lll long long
#define mp make_pair
#define fi first
#define se second
using namespace std;

const int NR = 363304 + 10 ;

void boost ()    {
    #ifndef ONLINE_JUDGE
    freopen("date.in", "r", stdin);
   // freopen("scmax.out", "w", stdout);
    #endif
     ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
}

string s ;
int n , cati_sell , cati_buy ;
vector < pair < bool , int > > st;
vector <int> all , not_know ;
vector <int> Tree_buy ( NR << 2, 0 ) ;
vector <int> Tree_sell ( NR << 2, 0 ) ;

void element_update_sell ( int nod , int st , int dr , int pos )    {
    if ( st == dr ) {
        Tree_buy[ nod ] = 0 ;
        Tree_sell [ nod ] = 1 ;
        return ;
    }
    int mij = ( st + dr ) >> 1 ;
    if ( pos <= mij )   element_update_sell( nod << 1 , st , mij , pos ) ;
    else                element_update_sell( nod << 1 | 1 , mij + 1 , dr , pos ) ;

    Tree_buy [ nod ] = Tree_buy [ nod << 1 ] + Tree_buy [ nod << 1 | 1 ] ;
    Tree_sell [ nod ] = Tree_sell [ nod << 1 ] + Tree_sell [ nod << 1 | 1 ] ;
}

void element_update_buy ( int nod , int st , int dr , int pos )    {
    if ( st == dr ) {
        Tree_buy[ nod ] = 1 ;
        Tree_sell [ nod ] = 0 ;
        return ;
    }
    int mij = ( st + dr ) >> 1 ;
    if ( pos <= mij )   element_update_buy( nod << 1 , st , mij , pos ) ;
    else                element_update_buy( nod << 1 | 1 , mij + 1 , dr , pos ) ;

    Tree_buy [ nod ] = Tree_buy [ nod << 1 ] + Tree_buy [ nod << 1 | 1 ] ;
    Tree_sell [ nod ] = Tree_sell [ nod << 1 ] + Tree_sell [ nod << 1 | 1 ] ;
}

void element_update_neutru ( int nod , int st , int dr , int pos )    {
    if ( st == dr ) {
        Tree_buy[ nod ] = 0 ;
        Tree_sell [ nod ] = 0 ;
        return ;
    }
    int mij = ( st + dr ) >> 1 ;
    if ( pos <= mij )   element_update_neutru( nod << 1 , st , mij , pos ) ;
    else                element_update_neutru( nod << 1 | 1 , mij + 1 , dr , pos ) ;

    Tree_buy [ nod ] = Tree_buy [ nod << 1 ] + Tree_buy [ nod << 1 | 1 ] ;
    Tree_sell [ nod ] = Tree_sell [ nod << 1 ] + Tree_sell [ nod << 1 | 1 ] ;
}

int range_query_sell( int nod , int st , int dr , int a , int b )  {
    if ( st == dr ) {
        return Tree_sell [ nod ] ;
    }
    int mij = ( st + dr ) >> 1 , sol_st = 0 , sol_dr = 0 ;
    if ( a <= mij )   sol_st = range_query_sell( nod << 1 , st , mij , a , b ) ;
    if ( mij <  b )   sol_dr = range_query_sell( nod << 1 | 1 , mij + 1 , dr , a , b ) ;

    return sol_st + sol_dr ;
}

int range_query_buy( int nod , int st , int dr , int a , int b )  {
    if ( st == dr ) {
         return Tree_buy [ nod ] ;
    }
    int mij = ( st + dr ) >> 1 , sol_st = 0 , sol_dr = 0 ;
    if ( a <= mij )   sol_st = range_query_buy( nod << 1 , st , mij , a , b ) ;
    if ( mij <  b )   sol_dr = range_query_buy( nod << 1 | 1 , mij + 1 , dr , a , b ) ;

    return sol_st + sol_dr ;
}

int element_query ( int nod , int st , int dr , int pos )    {
        if ( st == dr ) {
                if ( Tree_sell [ nod ] == 1 )
                    return 1 ;
                if ( Tree_buy [ nod ] == 1 )
                    return 2 ;
        return 0 ;
    }
    int mij = ( st + dr ) >> 1 ;
    if ( pos <= mij )   return element_query( nod << 1 , st , mij , pos ) ;
    else                return element_query( nod << 1 | 1 , mij + 1 , dr , pos ) ;

}

int main(){
    boost() ;
    int x , i , act , sol = 1 , base ;
    cin >> n ;
    for ( i = 1 ; i <= n ; ++ i )   {
        cin >> s >> x ;
        all.pb(x);
        if ( s == "ADD" )
            st.pb( mp ( 1 , x ) ) ;
        else
            st.pb( mp ( 0 , x ) ) ;
    }

    sort(all.begin(), all.end());
  	all.erase(unique(all.begin(), all.end()), all.end());
    auto norm = [&](int x) {
    	return lower_bound(all.begin(), all.end(), x) - all.begin() + 1;
  	};

    for ( i = 0 ; i < n ; ++ i )   {
            if (  st [ i ].fi == 1 )    {
                    cati_sell = range_query_sell( 1 , 1 , n + 5 , 1 , norm ( st[i].se ) ) ;
                    cati_buy  = range_query_buy ( 1 , 1 , n + 5 , norm ( st[i].se ) , n ) ;
                    if ( cati_sell && cati_buy )    {
                        return cout << 0 , 0 ;
                    }
                    if ( cati_sell )    {
                        element_update_sell ( 1 , 1 , n + 5 , norm ( st[i].se ) ) ;
                    }
                    if ( cati_buy )    {
                        element_update_buy ( 1 , 1 , n + 5 , norm ( st[i].se ) ) ;
                    }
                    if ( !cati_buy && !cati_sell )  {
                        not_know.pb( st [ i ].se ) ;
                    }
            }   else    {
                while ( !not_know.empty() ) {
                    if ( not_know.back() > st [ i ].se )    {
                        element_update_sell ( 1 , 1 , n + 5 , norm ( not_know.back() ) ) ;
                    }   else    {
                        element_update_buy ( 1 , 1 , n + 5 , norm ( not_know.back() ) ) ;
                    }
                    not_know.pop_back();
                }
                act       = element_query ( 1 , 1 , n + 5 , st [i].se ) ;
                cati_sell = range_query_sell( 1 , 1 , n + 5 , 1 , norm ( st[i].se ) ) ;
                cati_buy  = range_query_buy ( 1 , 1 , n + 5 , norm ( st[i].se ) , n ) ;

                if ( act == 1 ) cati_sell -- ;
                if ( act == 2 ) cati_buy  -- ;

                if ( !cati_sell && !cati_buy ) sol = ( 1LL * sol * 2 ) % MOD ;

                if ( cati_sell || cati_buy )
                    return cout << 0 , 0 ;

                element_update_neutru ( 1 , 1 , n + 5 , norm( st [ i ].se ) ) ;

            }
    }
    base = sol ;
    sol = 0 ;
    for ( i = 0 ; i < not_know.size() ; ++ i )  {

        cati_sell = range_query_sell( 1 , 1 , n + 5 , 1 , norm ( not_know[i] ) ) ;
        cati_buy  = range_query_buy ( 1 , 1 , n + 5 , norm ( not_know[i] ) , n ) ;

        if ( !cati_sell && !cati_buy )  {
            sol = 1LL * ( sol + base * 2 ) % MOD ;
        }
    }

    cout << max ( sol , base ) << '\n' ;

}


#include<bits/stdc++.h>
using namespace std;
int n,ans=1,res=1,x,mn=0,mx=1e9,mod=1e9+7;
set<int>S;
char s[9];
int main(){
scanf("%d",&n);
S.insert(1e9),S.insert(0);
for(int i=1;i<=n;++i){
scanf("%s%d",s,&x);
if(s[1]=='D')S.insert(x),res+=(x>=mn&&x<=mx)?1:0;
else{
if(x<mn||x>mx)ans=0;
if(x!=mn&&x!=mx)ans=2*ans%mod;
S.erase(x);res=1;
auto it=S.lower_bound(x);
mx=*it;
mn=*(--it);
}
}
printf("%d\n",1ll*ans*res%mod);
}


#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 1e5 + 1;
int ans = 1;
int n;

set <int> unknown;
set <int> sell;
set <int> buy;

void input() {
    cin >> n;
}

bool exist(set <int> &s, int key) {
    auto it = s.find(key);
    return it != s.end();
}

void clear_unknown(int id) {
    for(auto it = unknown.begin(); it != unknown.end(); ++it) {
        if(*it < id) {
            buy.insert(*it);
        }
        if(*it > id) {
            sell.insert(*it);
        }
    }
    unknown.clear();
}

void solve() {
    for(int i = 0; i < n; ++i) {
        string cmd; cin >> cmd;
        int id; cin >> id;
        if(cmd == "ADD") {
            unknown.insert(id);
        }
        if(cmd == "ACCEPT") {
            if(exist(sell, id)) {
                if(id != *sell.begin()) {
                    cout << "0\n";
                    return;
                }
                clear_unknown(id);
                sell.erase(sell.begin());
                continue;
            }
            if(exist(buy, id)) {
                if(id != *prev(buy.end())) {
                    cout << "0\n";
                    return;
                }
                clear_unknown(id);
                buy.erase(prev(buy.end()));
                continue;
            }
            int tmp = ans; ans = 0;
            if(buy.empty() || id == *prev(buy.end())) {
                ans += tmp;
            }
            if(sell.empty() || id == *sell.begin()) {
                ans += tmp;
            }
            ans %= mod;
            if(!ans) {
                cout << "0\n";
                return;
            }
            clear_unknown(id);
        }
    }
    cout << ans << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    input();
    solve();
}


#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int ans = 1;
int n;

set <int> unknown;
set <int> sell;
set <int> buy;

void input() {
    cin >> n;
}

bool exist(set <int> &s, int key) {
    auto it = s.find(key);
    return it != s.end();
}

void clear_unknown(int id) {
    for(auto it = unknown.begin(); it != unknown.end(); ++it) {
        if(*it < id) {
            buy.insert(*it);
        }
        if(*it > id) {
            sell.insert(*it);
        }
    }
    unknown.clear();
}

void solve() {
    for(int i = 0; i < n; ++i) {
        string cmd; cin >> cmd;
        int id; cin >> id;
        if(cmd == "ADD") {
            unknown.insert(id);
        }
        if(cmd == "ACCEPT") {
            if(exist(sell, id)) {
                if(id != *sell.begin()) {
                    cout << "0\n";
                    return;
                }
                clear_unknown(id);
                sell.erase(sell.begin());
                continue;
            }
            if(exist(buy, id)) {
                if(id != *prev(buy.end())) {
                    cout << "0sd\n";
                    return;
                }
                clear_unknown(id);
                buy.erase(prev(buy.end()));
                continue;
            }
            int tmp = ans; ans = 0;
            if(buy.empty() || id == *prev(buy.end())) {
                ans += tmp;
            }
            if(sell.empty() || id == *sell.begin()) {
                ans += tmp;
            }
            ans %= mod;
            if(!ans) {
                cout << "0ds\n";
                return;
            }
            clear_unknown(id);
        }
    }
    cout << ans << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    input();
    solve();
}


#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int ans = 1;
int n;

set <int> unknown;
set <int> sell;
set <int> buy;

void input() {
    cin >> n;
}

bool exist(set <int> &s, int key) {
    auto it = s.find(key);
    return it != s.end();
}

void clear_unknown(int id) {
    for(auto it = unknown.begin(); it != unknown.end(); ++it) {
        if(*it < id) {
            buy.insert(*it);
        }
        if(*it > id) {
            sell.insert(*it);
        }
    }
    unknown.clear();
}

void solve() {
    for(int i = 0; i < n; ++i) {
        string cmd; cin >> cmd;
        int id; cin >> id;
        if(cmd == "ADD") {
            if(!sell.empty() && id > *sell.begin()) {
                sell.insert(id);
            }
            else if(!buy.empty() && id < *prev(buy.end())) {
                buy.insert(id);
            }
            else {
                unknown.insert(id);
            }
        }
        if(cmd == "ACCEPT") {
            if(exist(sell, id)) {
                if(id != *sell.begin()) {
                    cout << "0\n";
                    return;
                }
                clear_unknown(id);
                sell.erase(sell.begin());
                continue;
            }
            if(exist(buy, id)) {
                if(id != *prev(buy.end())) {
                    cout << "0\n";
                    return;
                }
                clear_unknown(id);
                buy.erase(prev(buy.end()));
                continue;
            }
            int tmp = ans; ans = 0;
            if(buy.empty() || id > *prev(buy.end())) {
                ans += tmp;
            }
            if(sell.empty() || id < *sell.begin()) {
                ans += tmp;
            }
            ans %= mod;
            if(!ans) {
                cout << "0\n";
                return;
            }
            clear_unknown(id);
        }
    }
    cout << 1ll * ans * (1 + unknown.size()) % mod << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    input();
    solve();
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>

#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <deque>
using namespace std;

#define dout(x) cerr << #x << " = " << x << endl;

typedef vector< vector<int> > Graph;

const int MAX_N = 250000;

int n;
int x,y;
Graph spanningTree(MAX_N);

//map < pair<int,int>, int > _dfs;
//vector < vector<int> > _dfs;
int _dfs[MAX_N][3];
int called = 0;
deque < tuple<int,int,int> > s;
int dfs(int p, int v, int availableEdges) {
	s.push_back( make_tuple(p,v,availableEdges) );
	called++;
	/*
	if (_dfs.count(make_pair(v, availableEdges))) {
		return _dfs[make_pair(v,availableEdges)];
	}
	*/
	if (_dfs[v][availableEdges] > 0) {
		//dout(v); dout(availableEdges);
		//s.pop_back();
		s.push_back(make_tuple(-1,-1,-1));
		return _dfs[v][availableEdges]-1;
	}
	if (_dfs[v][availableEdges] == -1) {
		for (auto si: s) {
			printf("-> %d %d %d\n",get<0>(si), get<1>(si), get<2>(si));
		}
		exit(1);
	}
	_dfs[v][availableEdges] = -1;
	int result = 0;
	int leftEdges = availableEdges;
	for (auto u: spanningTree[v]) {
		if (u != p) {
			int uv_taken = 1 + dfs(v, u, 1);
			int uv_untaken = dfs(v, u, 2);
			if (leftEdges &&  uv_taken > uv_untaken) {
				//take edge [v,u]
				result += uv_taken;
				leftEdges -= 1;
			} else {
				// don't take [v, u]
				result += uv_untaken;
			}
		}
	}
	//return _dfs[make_pair(v,availableEdges)] = result;

	_dfs[v][availableEdges] = result + 1;
	//printf("_dfs[%d][%d] = %d\n", v, availableEdges, result+1);
	//s.pop_back();
	//s.push_back(make_tuple(-1,-1,-1));
	return result;
}

int max_length_nonintersected_simple_paths() {
	//_dfs = vector< vector<int> > (n+1, vector<int>(3));
	memset(_dfs, 0, sizeof _dfs);
	return dfs(0, 1, 2);
}

void readData() {
	scanf("%d", &n);
	//spanningTree = Graph(n+1);
	scanf("%d%d", &x, &y);
	for (int i = 0; i < n-1; i++) {
		int u,v;
		scanf("%d%d", &u,&v);
		spanningTree[u].push_back(v);
		spanningTree[v].push_back(u);
	}
}

void solve() {
	int m = 0; // roads from spanningTree
	if (x >= y) {
		// use normal roads
		for (int i = 1; i <= n; i++)
			if (spanningTree[i].size() == n-1) m = 1;
	} else {
		m = max_length_nonintersected_simple_paths();
	}
	cout << (long long)m*x + (long long)(n-1-m)*y << "\n";

}

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	readData();
	solve();
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>

#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <deque>
using namespace std;

#define dout(x) cerr << #x << " = " << x << endl;

typedef vector< vector<int> > Graph;

const int MAX_N = 250000;

int n;
int x,y;
Graph spanningTree(MAX_N);

//map < pair<int,int>, int > _dfs;
//vector < vector<int> > _dfs;
int _dfs[MAX_N][3];
int called = 0;
deque < tuple<int,int,int> > s;
int dfs(int p, int v, int availableEdges) {
	s.push_back( make_tuple(p,v,availableEdges) );
	called++;
	/*
	if (_dfs.count(make_pair(v, availableEdges))) {
		return _dfs[make_pair(v,availableEdges)];
	}
	*/
	if (_dfs[v][availableEdges] > 0) {
		//dout(v); dout(availableEdges);
		//s.pop_back();
		s.push_back(make_tuple(-1,-1,-1));
		return _dfs[v][availableEdges]-1;
	}
	if (_dfs[v][availableEdges] == -1) {
		for (auto si: s) {
			printf("-> %d %d %d\n",get<0>(si), get<1>(si), get<2>(si));
		}
		exit(1);
	}
	_dfs[v][availableEdges] = -1;
	int result = 0;
	int leftEdges = availableEdges;
	for (auto u: spanningTree[v]) {
		if (u != p) {
			int uv_taken = 1 + dfs(v, u, 1);
			int uv_untaken = dfs(v, u, 2);
			if (leftEdges &&  uv_taken > uv_untaken) {
				//take edge [v,u]
				result += uv_taken;
				leftEdges -= 1;
			} else {
				// don't take [v, u]
				result += uv_untaken;
			}
		}
	}
	//return _dfs[make_pair(v,availableEdges)] = result;

	_dfs[v][availableEdges] = result + 1;
	//printf("_dfs[%d][%d] = %d\n", v, availableEdges, result+1);
	//s.pop_back();
	//s.push_back(make_tuple(-1,-1,-1));
	return result;
}

int max_length_nonintersected_simple_paths() {
	//_dfs = vector< vector<int> > (n+1, vector<int>(3));
	memset(_dfs, 0, sizeof _dfs);
	return dfs(0, 1, 2);
}

void readData() {
	scanf("%d", &n);
	//spanningTree = Graph(n+1);
	scanf("%d%d", &x, &y);
	for (int i = 0; i < n-1; i++) {
		int u,v;
		scanf("%d%d", &u,&v);
		spanningTree[u].push_back(v);
		spanningTree[v].push_back(u);
	}
}

void solve() {
	int m = 0; // roads from spanningTree
	if (x >= y) {
		// use normal roads
		for (int i = 1; i <= n; i++)
			if (spanningTree[i].size() == n-1) m += 1;
	} else {
		m = max_length_nonintersected_simple_paths();
	}
	cout << (long long)m*x + (long long)(n-1-m)*y << "\n";

}

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	readData();
	solve();
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>

#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
using namespace std;

#define dout(x) cerr << #x << " = " << x << endl;

const int MAX_N = 250000;

int f(vector <pair<int,int>>& e, int n) {
	vector <int> degree(n+1);
	for (auto& edge: e) {
		degree[edge.first] += 1;
		degree[edge.second] += 1;
	}
	vector <pair<int, pair<int,int> > > d_e;
	for (int i = 0; i < e.size(); i++) {
		d_e.push_back( make_pair( min(degree[e[i].first], degree[e[i].second]), e[i] ) );
	}
	sort(d_e.begin(), d_e.end());

	vector <int> visited(n+1);
	int m = 0;
	for (int i = 0; i < e.size(); i++) {
			e[i] = d_e[i].second;
			if (visited[e[i].first] < 2 && visited[e[i].second] < 2) {
				m += 1;
				visited[e[i].first] += 1;
				visited[e[i].second] += 1;
			}
		}
	return m;
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);

	int n;
	int xx,yy;
	long long x,y;
	scanf("%d%d%d", &n, &xx, &yy);
	x = xx;
	y = yy;
	vector <pair<int,int>> e;

	for (int i = 0; i < n; i++) {
		int u, v;
		scanf("%d%d", &u, &v);
		e.push_back(make_pair(u,v));
	}

	if (x >= y) {
		cout << y*(n-1);
	} else {
		int m = f(e, n);
		cout << m*x + (n-1-m)*y;
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>

#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
using namespace std;

#define dout(x) cerr << #x << " = " << x << endl;

typedef vector< vector<int> > Graph;

const int MAX_N = 250000;

int n;
int x,y;
Graph spanningTree;

//map < pair<int,int>, int > _dfs;
//vector < vector<int> > _dfs;
int _dfs[MAX_N][2];
int dfs(int p, int v, int availableEdges) {
	/*
	if (_dfs.count(make_pair(v, availableEdges))) {
		return _dfs[make_pair(v,availableEdges)];
	}
	*/
	if (_dfs[v][availableEdges] > 0)
		return _dfs[v][availableEdges]-1;
	int result = 0;
	for (auto u: spanningTree[v]) {
		if (u != p) {
			if (availableEdges && 1 + dfs(v, u, 1) > dfs(v, u, 2)) {
				//take edge [v,u]
				result += 1 + dfs(v, u, 1);
				availableEdges -= 1;
			} else {
				// don't take [v, u]
				result += dfs(v, u, 2);
			}
		}
	}
	//return _dfs[make_pair(v,availableEdges)] = result;
	_dfs[v][availableEdges] = result + 1;
	return result;
}

int max_length_nonintersected_simple_paths() {
	//_dfs = vector< vector<int> > (n+1, vector<int>(3));
	memset(_dfs, 0, sizeof _dfs);
	return dfs(0, 1, 2);
}

void readData() {
	scanf("%d", &n);
	spanningTree = Graph(n+1);
	scanf("%d%d", &x, &y);
	for (int i = 0; i < n-1; i++) {
		int u,v;
		scanf("%d%d", &u,&v);
		spanningTree[u].push_back(v);
		spanningTree[v].push_back(u);
	}
}

void solve() {
	int m = 0; // roads from spanningTree
	if (x >= y) {
		// use normal roads
		for (int i = 1; i <= n; i++)
			if (spanningTree[i].size() == n-1) m += 1;
	} else {
		m = max_length_nonintersected_simple_paths();
	}
	cout << (long long)m*x + (long long)(n-1-m)*y << "\n";
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	readData();
	solve();
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>

#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
using namespace std;

#define dout(x) cerr << #x << " = " << x << endl;

typedef vector< vector<int> > Graph;

int n;
int x,y;
Graph spanningTree;

//map < pair<int,int>, int > _dfs;
vector < vector<int> > _dfs(n+1, vector<int>(3));
int dfs(int p, int v, int availableEdges) {
	/*
	if (_dfs.count(make_pair(v, availableEdges))) {
		return _dfs[make_pair(v,availableEdges)];
	}
	*/
	if (_dfs[v][availableEdges] > 0)
		return _dfs[v][availableEdges]-1;
	int result = 0;
	for (auto u: spanningTree[v]) {
		if (u != p) {
			if (availableEdges && 1 + dfs(v, u, 1) > dfs(v, u, 2)) {
				//take edge [v,u]
				result += 1 + dfs(v, u, 1);
				availableEdges -= 1;
			} else {
				// don't take [v, u]
				result += dfs(v, u, 2);
			}
		}
	}
	//return _dfs[make_pair(v,availableEdges)] = result;
	_dfs[v][availableEdges] = result + 1;
	return result;
}

int max_length_nonintersected_simple_paths() {
	return dfs(0, 1, 2);
}

void readData() {
	scanf("%d", &n);
	spanningTree = Graph(n+1);
	scanf("%d%d", &x, &y);
	for (int i = 0; i < n-1; i++) {
		int u,v;
		scanf("%d%d", &u,&v);
		spanningTree[u].push_back(v);
		spanningTree[v].push_back(u);
	}
}

void solve() {
	int m = 0; // roads from spanningTree
	if (x >= y) {
		// use normal roads
		for (int i = 1; i <= n; i++)
			if (spanningTree[i].size() == n-1) m += 1;
	} else {
		m = max_length_nonintersected_simple_paths();
	}
	cout << (long long)m*x + (long long)(n-1-m)*y << "\n";
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	readData();
	solve();
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>

#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
using namespace std;

#define dout(x) cerr << #x << " = " << x << endl;

typedef vector< vector<int> > Graph;

const int MAX_N = 250000;

int n;
int x,y;
Graph spanningTree(MAX_N);

//map < pair<int,int>, int > _dfs;
//vector < vector<int> > _dfs;
int _dfs[MAX_N][3];
int dfs(int p, int v, int availableEdges) {
	/*
	if (_dfs.count(make_pair(v, availableEdges))) {
		return _dfs[make_pair(v,availableEdges)];
	}
	*/
	if (_dfs[v][availableEdges] > 0) {
		//dout(v); dout(availableEdges);
		return _dfs[v][availableEdges]-1;
	}
	int result = 0;
	for (auto u: spanningTree[v]) {
		if (u != p) {
			if (availableEdges && 1 + dfs(v, u, 1) > dfs(v, u, 2)) {
				//take edge [v,u]
				result += 1 + dfs(v, u, 1);
				availableEdges -= 1;
			} else {
				// don't take [v, u]
				result += dfs(v, u, 2);
			}
		}
	}
	//return _dfs[make_pair(v,availableEdges)] = result;
	_dfs[v][availableEdges] = result + 1;
	return result;
}

int max_length_nonintersected_simple_paths() {
	//_dfs = vector< vector<int> > (n+1, vector<int>(3));
	memset(_dfs, 0, sizeof _dfs);
	return dfs(0, 1, 2);
}

void readData() {
	scanf("%d", &n);
	//spanningTree = Graph(n+1);
	scanf("%d%d", &x, &y);
	for (int i = 0; i < n-1; i++) {
		int u,v;
		scanf("%d%d", &u,&v);
		spanningTree[u].push_back(v);
		spanningTree[v].push_back(u);
	}
}

void solve() {
	int m = 0; // roads from spanningTree
	if (x >= y) {
		// use normal roads
		for (int i = 1; i <= n; i++)
			if (spanningTree[i].size() == n-1) m += 1;
	} else {
		m = max_length_nonintersected_simple_paths();
	}
	cout << (long long)m*x + (long long)(n-1-m)*y << "\n";
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	readData();
	solve();
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>

#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
using namespace std;

#define dout(x) cerr << #x << " = " << x << endl;

typedef vector< vector<int> > Graph;

int n;
int x,y;
Graph spanningTree;

//map < pair<int,int>, int > _dfs;
vector < vector<int> > _dfs;
int dfs(int p, int v, int availableEdges) {
	/*
	if (_dfs.count(make_pair(v, availableEdges))) {
		return _dfs[make_pair(v,availableEdges)];
	}
	*/
	if (_dfs[v][availableEdges] > 0)
		return _dfs[v][availableEdges]-1;
	int result = 0;
	for (auto u: spanningTree[v]) {
		if (u != p) {
			if (availableEdges && 1 + dfs(v, u, 1) > dfs(v, u, 2)) {
				//take edge [v,u]
				result += 1 + dfs(v, u, 1);
				availableEdges -= 1;
			} else {
				// don't take [v, u]
				result += dfs(v, u, 2);
			}
		}
	}
	//return _dfs[make_pair(v,availableEdges)] = result;
	_dfs[v][availableEdges] = result + 1;
	return result;
}

int max_length_nonintersected_simple_paths() {
	_dfs = vector< vector<int> > (n+1, vector<int>(3));
	return dfs(0, 1, 2);
}

void readData() {
	scanf("%d", &n);
	spanningTree = Graph(n+1);
	scanf("%d%d", &x, &y);
	for (int i = 0; i < n-1; i++) {
		int u,v;
		scanf("%d%d", &u,&v);
		spanningTree[u].push_back(v);
		spanningTree[v].push_back(u);
	}
}

void solve() {
	int m = 0; // roads from spanningTree
	if (x >= y) {
		// use normal roads
		for (int i = 1; i <= n; i++)
			if (spanningTree[i].size() == n-1) m += 1;
	} else {
		m = max_length_nonintersected_simple_paths();
	}
	cout << (long long)m*x + (long long)(n-1-m)*y << "\n";
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	readData();
	solve();
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>

#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
using namespace std;

#define dout(x) cerr << #x << " = " << x << endl;

const int MAX_N = 250000;

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);

	int n;
	int xx,yy;
	long long x,y;
	scanf("%d%d%d", &n, &xx, &yy);
	x = xx;
	y = yy;
	vector <pair<int,int>> e;
	vector <int> visited(n+1);

	for (int i = 0; i < n; i++) {
		int u, v;
		scanf("%d%d", &u, &v);
		e.push_back(make_pair(u,v));
	}

	if (x >= y) {
		cout << y*(n-1);
	} else {
		int m = 0;
		for (int i = 0; i < e.size(); i++) {
			if (visited[e[i].first] < 2 && visited[e[i].second] < 2) {
				m += 1;
				visited[e[i].first] += 1;
				visited[e[i].second] += 1;
			}
		}
		cout << m*x + (n-m-1)*y;
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>

#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
using namespace std;

#define dout(x) cerr << #x << " = " << x << endl;

typedef vector< vector<int> > Graph;

const int MAX_N = 250000;

int n;
int x,y;
Graph spanningTree(MAX_N);

int dfs2(int parent, int vertex, long long &answer) {

}

//map < pair<int,int>, int > _dfs;
//vector < vector<int> > _dfs;
int _dfs[MAX_N][3];
int called = 0;
int dfs(int p, int v, int availableEdges) {
	called++;
	/*
	if (_dfs.count(make_pair(v, availableEdges))) {
		return _dfs[make_pair(v,availableEdges)];
	}
	*/
	if (_dfs[v][availableEdges] > 0) {
		//dout(v); dout(availableEdges);
		return _dfs[v][availableEdges]-1;
	}
	if (_dfs[v][availableEdges] == -1) {
		exit(1);
	}
	_dfs[v][availableEdges] = -1;
	int result = 0;
	for (auto u: spanningTree[v]) {
		if (u != p) {
			if (availableEdges && 1 + dfs(v, u, 1) > dfs(v, u, 2)) {
				//take edge [v,u]
				result += 1 + dfs(v, u, 1);
				availableEdges -= 1;
			} else {
				// don't take [v, u]
				result += dfs(v, u, 2);
			}
		}
	}
	//return _dfs[make_pair(v,availableEdges)] = result;
	_dfs[v][availableEdges] = result + 1;
	return result;
}

int max_length_nonintersected_simple_paths() {
	//_dfs = vector< vector<int> > (n+1, vector<int>(3));
	memset(_dfs, 0, sizeof _dfs);
	return dfs(0, 1, 2);
}

void readData() {
	scanf("%d", &n);
	//spanningTree = Graph(n+1);
	scanf("%d%d", &x, &y);
	for (int i = 0; i < n-1; i++) {
		int u,v;
		scanf("%d%d", &u,&v);
		spanningTree[u].push_back(v);
		spanningTree[v].push_back(u);
	}
}

void solve() {
	int m = 0; // roads from spanningTree
	if (x >= y) {
		// use normal roads
		for (int i = 1; i <= n; i++)
			if (spanningTree[i].size() == n-1) m += 1;
	} else {
		m = max_length_nonintersected_simple_paths();
	}
	cout << (long long)m*x + (long long)(n-1-m)*y << "\n";

}

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	readData();
	solve();
	return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
ll n,x,y;
const int MX=2e5+3;
int deg[MX];
vector<int>adj[MX];
int vis[MX];
int vert[MX];
void bfs()
{
    memset(vis,-1,sizeof vis);
    queue<int>q;
    q.push(1);
    vis[1]=0;
    while(!q.empty())
    {
        int moth=q.front();
        q.pop();
        for(int i=0;i<adj[moth].size();i++)
        {
            int yy=adj[moth][i];
            if(vis[yy]!=-1)continue;
            vis[yy]=vis[moth]+1;
            vert[vis[yy]]++;
            q.push(yy);
        }
    }
}
int num=0;
int dfs(int node,int pa)
{
    int adjec=0;
    for(auto u : adj[node])
    {
        if(u==pa)continue;
        adjec+=dfs(u,node);
    }
    num+=max(adjec-2,0);
    return 1;

}
int main()
{
    cin>>n>>x>>y;
    for(int i=1;i<n;i++)
    {
        int s,w;
        cin>>s>>w;
        adj[s].push_back(w);
        adj[w].push_back(s);
     }
    bfs();
    dfs(1,0);
      ll ans;
      num+=!num;
    if(x<=y)
    ans=num*y+(n-1-num)*x;
    else
    {
        ans=0;
      if(vert[2])
      {
          ans=(n-1)*y;
      }
      else ans=(n-2)*y+x;
        //cout<<"&&";
    }

     cout<<ans;

    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
ll n,x,y;
const int MX=2e5+3;
 vector<int>adj[MX];

bool ss()
{
   for(int i=1;i<=n;i++)
   {
       if(adj[i].size()==n-1)return 0;
   }
   return 1;
}
int num=0;
int dfs(int node,int pa)
{
    int adjec=0;
    for(auto u : adj[node])
    {
        if(u==pa)continue;
        adjec+=dfs(u,node);
    }
    if(adjec>=2)
    {
        num+=2;
        return 0;
    }
    num+=adjec;
    return 1;

}
int main()
{
    cin>>n>>x>>y;
    for(int i=1;i<n;i++)
    {
        int s,w;
        cin>>s>>w;
        adj[s].push_back(w);
        adj[w].push_back(s);
     }
    dfs(1,0);
      ll ans;
     if(x<=y)
    ans=num*x+(n-1-num)*y;
    else
    {
        ans=0;
      if(ss())
      {
          ans=(n-1)*y;
      }
      else ans=(n-2)*y+x;
        //cout<<"&&";
    }

     cout<<ans;

    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
ll n,x,y;
const int MX=2e5+3;
int deg[MX];
vector<int>adj[MX];
int vis[MX];
int vert[MX];
void bfs()
{
    memset(vis,-1,sizeof vis);
    queue<int>q;
    q.push(1);
    vis[1]=0;
    while(!q.empty())
    {
        int moth=q.front();
        q.pop();
        for(int i=0;i<adj[moth].size();i++)
        {
            int yy=adj[moth][i];
            if(vis[yy]!=-1)continue;
            vis[yy]=vis[moth]+1;
            vert[vis[yy]]++;
            q.push(yy);
        }
    }
}
int num=0;
int dfs(int node,int pa)
{
    int adjec=0;
    for(auto u : adj[node])
    {
        if(u==pa)continue;
        adjec+=dfs(u,node);
    }
    if(adjec>=2)
    {
        num+=adjec-2;
        return 0;
    }
    num+=adjec;
    return 1;

}
int main()
{
    cin>>n>>x>>y;
    for(int i=1;i<n;i++)
    {
        int s,w;
        cin>>s>>w;
        adj[s].push_back(w);
        adj[w].push_back(s);
     }
    bfs();
    dfs(1,0);
      ll ans;
     if(x<=y)
    ans=num*y+(n-1-num)*x;
    else
    {
        ans=0;
      if(vert[2])
      {
          ans=(n-1)*y;
      }
      else ans=(n-2)*y+x;
        //cout<<"&&";
    }

     cout<<ans;

    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
ll n,x,y;
const int MX=2e5+3;
int deg[MX];
vector<int>adj[MX];
int vis[MX];
int vert[MX];
void bfs()
{
    memset(vis,-1,sizeof vis);
    queue<int>q;
    q.push(1);
    vis[1]=0;
    while(!q.empty())
    {
        int moth=q.front();
        q.pop();
        for(int i=0;i<adj[moth].size();i++)
        {
            int yy=adj[moth][i];
            if(vis[yy]!=-1)continue;
            vis[yy]=vis[moth]+1;
            vert[vis[yy]]++;
            q.push(yy);
        }
    }
}
int main()
{
    cin>>n>>x>>y;
    for(int i=1;i<n;i++)
    {
        int s,w;
        cin>>s>>w;
        adj[s].push_back(w);
        adj[w].push_back(s);
        deg[s]++;
        deg[w]++;
    }
    bfs();
    ll num=0;
    for(int i=1;i<=n;i++)
        num+=max((ll)deg[i]-2,(ll)0);
    ll ans;
    if(x<=y)
    ans=num*y+(n-1-num)*x;
    else
    {
        ans=0;
      if(vert[2])
      {
          ans=(n-1)*y;
      }
      else ans=(n-2)*y+x;
        //cout<<"&&";
    }
        if(ans>1e3)
        {
            cout<<num<<' ';
        }
     cout<<ans;

    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
ll n,x,y;
const int MX=2e5+3;
int deg[MX];
vector<int>adj[MX];
int vis[MX];
int vert[MX];
void bfs()
{
    memset(vis,-1,sizeof vis);
    queue<int>q;
    q.push(1);
    vis[1]=0;
    while(!q.empty())
    {
        int moth=q.front();
        q.pop();
        for(int i=0;i<adj[moth].size();i++)
        {
            int yy=adj[moth][i];
            if(vis[yy]!=-1)continue;
            vis[yy]=vis[moth]+1;
            vert[vis[yy]]++;
            q.push(yy);
        }
    }
}
int num=0;
int dfs(int node,int pa)
{
    int adjec=0;
    for(auto u : adj[node])
    {
        if(u==pa)continue;
        adjec+=dfs(u,node);
    }
    if(adjec>=2)
    {
        num+=adjec-2;
        return 0;
    }

    return 1;

}
int main()
{
    cin>>n>>x>>y;
    for(int i=1;i<n;i++)
    {
        int s,w;
        cin>>s>>w;
        adj[s].push_back(w);
        adj[w].push_back(s);
     }
    bfs();
    dfs(1,0);
      ll ans;
     if(x<=y)
    ans=num*y+(n-1-num)*x;
    else
    {
        ans=0;
      if(vert[2])
      {
          ans=(n-1)*y;
      }
      else ans=(n-2)*y+x;
        //cout<<"&&";
    }

     cout<<ans;

    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
int n,x,y;
const int MX=2e5+3;
int deg[MX];
vector<int>adj[MX];
int vis[MX];
int vert[MX];
void bfs()
{
    memset(vis,-1,sizeof vis);
    queue<int>q;
    q.push(1);
    vis[1]=0;
    while(!q.empty())
    {
        int moth=q.front();
        q.pop();
        for(int i=0;i<adj[moth].size();i++)
        {
            int yy=adj[moth][i];
            if(vis[yy]!=-1)continue;
            vis[yy]=vis[moth]+1;
            vert[vis[yy]]++;
            q.push(yy);
        }
    }
}
int main()
{
    cin>>n>>x>>y;
    for(int i=1;i<n;i++)
    {
        int s,w;
        cin>>s>>w;
        adj[s].push_back(w);
        adj[w].push_back(s);
        deg[s]++;
        deg[w]++;
    }
    bfs();
    ll num=0;
    for(int i=1;i<=n;i++)
        num+=max(deg[i]-2,0);
    ll ans;
    if(x<=y)
    ans=num*y+(n-1-num)*x;
    else
    {
        ans=0;
      if(vert[2])
      {
          ans=(n-1)*y;
      }
      else ans=(n-2)*y+x;
        //cout<<"&&";
    }

     cout<<ans;

    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
ll n,x,y;
const int MX=2e5+3;
int deg[MX];
vector<int>adj[MX];
int vis[MX];
int vert[MX];
void bfs()
{
    memset(vis,-1,sizeof vis);
    queue<int>q;
    q.push(1);
    vis[1]=0;
    while(!q.empty())
    {
        int moth=q.front();
        q.pop();
        for(int i=0;i<adj[moth].size();i++)
        {
            int yy=adj[moth][i];
            if(vis[yy]!=-1)continue;
            vis[yy]=vis[moth]+1;
            vert[vis[yy]]++;
            q.push(yy);
        }
    }
}
int num=1;
int dfs(int node,int pa)
{
    int adjec=0;
    for(auto u : adj[node])
    {
        if(u==pa)continue;
        adjec+=dfs(u,node);
    }
    num+=max(adjec-2,0);
    return 1;

}
int main()
{
    cin>>n>>x>>y;
    for(int i=1;i<n;i++)
    {
        int s,w;
        cin>>s>>w;
        adj[s].push_back(w);
        adj[w].push_back(s);
     }
    bfs();
    dfs(1,0);
      ll ans;
    if(x<=y)
    ans=num*y+(n-1-num)*x;
    else
    {
        ans=0;
      if(vert[2])
      {
          ans=(n-1)*y;
      }
      else ans=(n-2)*y+x;
        //cout<<"&&";
    }
        if(ans>1e3)
        {
            cout<<num<<' ';
        }
     cout<<ans;

    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
ll n,x,y;
const int MX=2e5+3;
int deg[MX];
vector<int>adj[MX];
int vis[MX];
int vert[MX];
void bfs()
{
    memset(vis,-1,sizeof vis);
    queue<int>q;
    q.push(1);
    vis[1]=0;
    while(!q.empty())
    {
        int moth=q.front();
        q.pop();
        for(int i=0;i<adj[moth].size();i++)
        {
            int yy=adj[moth][i];
            if(vis[yy]!=-1)continue;
            vis[yy]=vis[moth]+1;
            vert[vis[yy]]++;
            q.push(yy);
        }
    }
}
int num=0;
int dfs(int node,int pa)
{
    int adjec=0;
    for(auto u : adj[node])
    {
        if(u==pa)continue;
        adjec+=dfs(u,node);
    }
    if(adjec>=2)
    {
        num+=adjec-2;
    }
    num+=adjec;
    return 1;

}
int main()
{
    cin>>n>>x>>y;
    for(int i=1;i<n;i++)
    {
        int s,w;
        cin>>s>>w;
        adj[s].push_back(w);
        adj[w].push_back(s);
     }
    bfs();
    dfs(1,0);
      ll ans;
     if(x<=y)
    ans=num*x+(n-1-num)*y;
    else
    {
        ans=0;
      if(vert[2])
      {
          ans=(n-1)*y;
      }
      else ans=(n-2)*y+x;
        //cout<<"&&";
    }

     cout<<ans;

    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
ll n,x,y;
const int MX=2e5+3;
int deg[MX];
vector<int>adj[MX];
int vis[MX];
int vert[MX];
void bfs()
{
    memset(vis,-1,sizeof vis);
    queue<int>q;
    q.push(1);
    vis[1]=0;
    while(!q.empty())
    {
        int moth=q.front();
        q.pop();
        for(int i=0;i<adj[moth].size();i++)
        {
            int yy=adj[moth][i];
            if(vis[yy]!=-1)continue;
            vis[yy]=vis[moth]+1;
            vert[vis[yy]]++;
            q.push(yy);
        }
    }
}
int num=0;
int dfs(int node,int pa)
{
    int adjec=0;
    for(auto u : adj[node])
    {
        if(u==pa)continue;
        adjec+=dfs(u,node);
    }
    if(adjec>=2)
    {
        num+=2;
        return 0;
    }
    num+=adjec;
    return 1;

}
int main()
{
    cin>>n>>x>>y;
    for(int i=1;i<n;i++)
    {
        int s,w;
        cin>>s>>w;
        adj[s].push_back(w);
        adj[w].push_back(s);
     }
    bfs();
    dfs(1,0);
      ll ans;
     if(x<=y)
    ans=num*x+(n-1-num)*y;
    else
    {
        ans=0;
      if(vert[2])
      {
          ans=(n-1)*y;
      }
      else ans=(n-2)*y+x;
        //cout<<"&&";
    }

     cout<<ans;

    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
const int MAX = 2*1e5+10;
int root;
using namespace std;
vector<int> a[MAX];
ll dfs(int v,int p){
    ll t=0;
    for(auto u:a[v]){
        if(u==p)continue;
        t+=dfs(u ,v);
    }
    if(a[v].size()==1 && v!=root)return 0;
    t++;
    return t;
}
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll n,x,y; cin>>n>>x>>y;
    int mx=0,id=-1;
    for(int i=0;i<n-1;i++){
        int u,v; cin>>u>>v;
        a[u].push_back(v); a[v].push_back(u);
        if(a[u].size()>mx){mx=a[u].size(); id=u;}
        if(a[v].size()>mx){mx=a[v].size(); id=v;}
    }
    if(x>=y){
        ll ans=(n-1)*y;
        cout<<ans; return 0;
    }
    root=id;
    ll ans=dfs(id,0);
    if(a[root].size()!=1)ans++;
    ans=ans*x + (n-1-ans)*y;
    cout<<ans;
}


//In God We Trust
//Go To Be Your Best !
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
typedef long long ll;
using namespace std;
const int N = 2 * 1e5 + 10;
vector<int> a[N];
int dp[N];
bool us[N];

void dfs(int v,int p = 0){
    int tmp = 0;
    for(auto u:a[v]){
        if(u == p)continue;
        dfs(u , v);
        dp[v]+=dp[u];
        if(!us[u])tmp++;
    }
    if(tmp == 1)dp[v]++;
    else if(tmp>=2){us[v] = true; dp[v]+=2;}
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll n , x , y;
    cin>>n>>x>>y;
    for(int i=0;i<n-1;i++){
        int u,v; cin>>u>>v;
        a[u].pb(v);
        a[v].pb(u);
    }
    ll mxd = -1;
    for(int i=1;i<=n;i++)
        mxd = max(mxd , (ll)a[i].size());
    //Tricky Case :
    if(x>=y){
        if(mxd == n-1)
            cout<<(n-2)*y + x<<'\n';
        else
            cout<<(n-1)*y<<'\n';
        return 0;
    }
    dfs(1);
    cout<<x * dp[1] + (n - dp[1] - 1)*y<<'\n';
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
const int MAX = 2*1e5+10;
int root;
using namespace std;
vector<int> a[MAX]; ll dp[MAX] ,sz[MAX];
void dfs(int v,int p){
    ll t=0; int c=0 , d=0;
    for(auto u:a[v]){
        if(u==p)continue;
        dfs(u,v);
        dp[v]+=dp[u];
        sz[v]++;
        if(sz[u]<=1)d++;
    }
    if(d==1)dp[v]++;
    else if(d>=2)dp[v]+=2;
    if(a[v].size()==1 && v!=root)dp[v]=0;
}
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll n,x,y; cin>>n>>x>>y;
    int mx=0,id=-1;
    for(int i=0;i<n-1;i++){
        int u,v; cin>>u>>v;
        a[u].push_back(v); a[v].push_back(u);
        if(a[u].size()>mx){mx=a[u].size(); id=u;}
        if(a[v].size()>mx){mx=a[v].size(); id=v;}
    }
    bool f;
    if(mx==n-1)f=false; else f=true;
    if(x>=y){
        if(f){
        ll ans=(n-1)*y;
        cout<<ans; return 0;
        }
        else{
            cout<<(n-2)*y+x; return 0;
        }
    }
    root=1;
    dfs(1,0);
    ll ans=dp[1]*x + (n-1-dp[1])*y;
    cout<<ans;
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
const int MAX = 2*1e5+10;
int root;
using namespace std;
vector<int> a[MAX]; ll dp[MAX] ,sz[MAX];
void dfs(int v,int p){
    ll t=0; int c=0 , d=0;
    for(auto u:a[v]){
        if(u==p)continue;
        dfs(u,v);
        dp[v]+=dp[u];
        sz[v]++;
        if(sz[u]<=1)d++;
    }
    if(d==1)dp[v]++;
    else if(d>=2)dp[v]+=2;
    if(a[v].size()==1 && v!=root)dp[v]=0;
}
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll n,x,y; cin>>n>>x>>y;
    int mx=0,id=-1;
    for(int i=0;i<n-1;i++){
        int u,v; cin>>u>>v;
        a[u].push_back(v); a[v].push_back(u);
        if(a[u].size()>mx){mx=a[u].size(); id=u;}
        if(a[v].size()>mx){mx=a[v].size(); id=v;}
    }
    if(x>=y){
        ll ans=(n-1)*y;
        cout<<ans; return 0;
    }
    root=1;
    dfs(1,0);
    ll ans=dp[1]*x + (n-1-dp[1])*y;
    cout<<ans;
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
const int MAX = 2*1e5+10;
int root;
using namespace std;
vector<int> a[MAX]; ll dp[MAX] ,sz[MAX];
void dfs(int v,int p){
    ll t=0; int c=0 , d=0;
    for(auto u:a[v]){
        if(u==p)continue;
        dfs(u,v);
        dp[v]+=dp[u];
        sz[v]++;
        if(sz[u]<=1)d++;
    }
    if(d==1)dp[v]++;
    else if(d>=2)dp[v]+=2;
    if(a[v].size()==1 && v!=root)dp[v]=0;
}
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll n,x,y; cin>>n>>x>>y;
    int mx=0,id=-1;
    for(int i=0;i<n-1;i++){
        int u,v; cin>>u>>v;
        a[u].push_back(v); a[v].push_back(u);
        if(a[u].size()>mx){mx=a[u].size(); id=u;}
        if(a[v].size()>mx){mx=a[v].size(); id=v;}
    }
    bool f;
    if(mx==n-1)f=false; else f=true;
    if(x>=y){
        if(f){
        ll ans=(n-1)*y;
        cout<<ans; return 0;
        }
        else{
            cout<<(n-2)*y+x; return 0;
        }
    }
    root=id;
    dfs(id,0);
    ll ans=dp[root]*x + (n-1-dp[root])*y;
    cout<<ans;
}


//In God We Trust
//Go To Be Your Best !
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
typedef long long ll;
using namespace std;
const int N = 2 * 1e5 + 10;
vector<int> a[N];
ll dp[N] , us[N];

void dfs(int v,int p = 0){
    int tmp = 0;
    for(auto u:a[v]){
        if(u == p)continue;
        dfs(u , v);
        dp[v]+=dp[u];
        if(!us[u])tmp++;
    }
    if(tmp == 1)dp[v]++;
    else if(tmp>=2){us[v] = true; dp[v]+=2;}
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll n , x , y;
    cin>>n>>x>>y;
    for(int i=0;i<n-1;i++){
        int u,v; cin>>u>>v;
        a[u].pb(v);
        a[v].pb(u);
    }
    ll mxd = -1;
    for(int i=1;i<=n;i++)
        mxd = max(mxd , (ll)a[i].size());
    //Tricky Case :
    if(x>=y){
        if(mxd == n-1)
            cout<<(n-2)*y + x<<'\n';
        else
            cout<<(n-1)*y<<'\n';
        return 0;
    }
    dfs(1);
    cout<<x * dp[1] + (n - dp[1] - 1)*y<<'\n';
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
const int MAX = 2*1e5+10 , root=1;
using namespace std;
vector<int> a[MAX];
ll dfs(int v,int p){
    ll t=0;
    for(auto u:a[v]){
        if(u==p)continue;
        t+=dfs(u ,v);
    }
    if(a[v].size()==1 && v!=root)return 0;
    t++;
    return t;
}
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll n,x,y; cin>>n>>x>>y;
    for(int i=0;i<n-1;i++){
        int u,v; cin>>u>>v;
        a[u].push_back(v); a[v].push_back(u);
    }
    if(x>=y){
        ll ans=(n-1)*y;
        cout<<ans; return 0;
    }
    ll ans=dfs(1,0);
    if(a[root].size()!=1)ans++;
    ans=ans*x + (n-1-ans)*y;
    cout<<ans;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N = 2e5+1;

int c[N];
int main() {
    ll n, x, y, u, v, ans=0, cy=0;
    scanf("%lld%lld%lld", &n, &x, &y);
    for(int i=0; i<n-1; ++i) {
        scanf("%lld%lld", &u, &v);
        c[u]++, c[v]++;
    }
    for(int i=0; i<n; ++i) {
         if (c[i] > 2) cy += c[i] - 2;
    }
    ans = cy*y + (n-cy-1)*min(x, y);
    printf("%lld\n", ans);

    return 0;
}


#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long ll;
const int N = 2e5+1;
vector<int> g[N];
ll n, x, y, u, v, ans=0, c, ok = 1;

int dfs(int u, int p) {
    int as=0;
    if (g[u].size() == n-1) ok = 0;
    for(int i=0; i<g[u].size(); ++i) {
        if (g[u][i] != p) as += dfs(g[u][i], u);
    }
    if (as > 1) {
        c += as - 1;
        return 0;
    }
    return 1;
}

int main() {
    scanf("%lld%lld%lld", &n, &x, &y);
    for(int i=0; i<n-1; ++i) {
        scanf("%lld%lld", &u, &v);
        g[u].push_back(v);
        g[v].push_back(u);
    }
    c += dfs(1, 1);
    c--;
    if (x >= y) {
       if (ok) ans = (n-1)*y;
       else ans = x + (n-2)*y;
    } else {
       ans = c*y + (n-c-1)*x;
    }
    printf("%lld\n", ans);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N = 2e5+1;

int c[N];
int main() {
    ll n, x, y, u, v, ans=0, cy=0;
    scanf("%lld%lld%lld", &n, &x, &y);
    for(int i=0; i<n-1; ++i) {
        scanf("%lld%lld", &u, &v);
        c[u]++, c[v]++;
    }
    bool ok = true;
    for(int i=0; i<n; ++i) {
        if (c[i] > 2) cy += c[i] - 2;
        if (c[i] == n-1) ok = false;
    }
    if (n == 2) printf("%d\n", x);
    else if (n == 3) printf("%d\n", 2*x+y);
    else if (ok) ans = cy*y + (n-cy-1)*min(x, y);
    else ans = x + min(x, y) + (n-3)*y
    printf("%lld\n", ans);

    return 0;
}


#include <cstdio>
#include <algorithm>

using namespace std;

typedef long long ll;
const int N = 2e5+1;

int c[N];
int main() {
    ll n, x, y, u, v, ans=0, cy=0;
    scanf("%lld%lld%lld", &n, &x, &y);
    for(int i=0; i<n-1; ++i) {
        scanf("%lld%lld", &u, &v);
        c[u]++, c[v]++;
    }
    bool ok = true;
    for(int i=0; i<n; ++i) {
        if (c[i] > 2) cy += c[i] - 2;
        if (c[i] == n-1) ok = false;
    }
    if (n == 2) ans = x;
    else if (n == 3) ans = 2*x+y;
    else if (ok) ans = cy*y + (n-cy-1)*min(x, y);
    else ans = x + min(x, y) + (n-3)*y;
    printf("%lld\n", ans);

    return 0;
}


#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long ll;
const int N = 2e5+1;
vector<int> g[N];
ll n, x, y, u, v, ans=0, c, ok = 1;

int dfs(int u, int p) {
    int as=0;
    if (g[u].size() == n-1) ok = 0;
    for(int i=0; i<g[u].size(); ++i) {
        if (g[u][i] != p) as += dfs(g[u][i], u);
    }
    if (as > 1) {
        c += as - 2;
        return 0;
    }
    return 1;
}

int main() {
    scanf("%lld%lld%lld", &n, &x, &y);
    for(int i=0; i<n-1; ++i) {
        scanf("%lld%lld", &u, &v);
        g[u].push_back(v);
        g[v].push_back(u);
    }
    c += dfs(1, 1);
    if (x >= y) {
       if (ok) ans = (n-1)*y;
       else ans = x + (n-2)*y;
    } else {
       ans = c*y + (n-c-1)*x;
    }
    printf("%lld\n", ans);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N = 2e5+1;

int c[N];
int main() {
    ll n, x, y, u, v, ans=0, cy=0;
    scanf("%lld%lld%lld", &n, &x, &y);
    for(int i=0; i<n-1; ++i) {
        scanf("%lld%lld", &u, &v);
        c[u]++, c[v]++;
    }
    bool ok = true
    for(int i=0; i<n; ++i) {
        if (c[i] > 2) cy += c[i] - 2;
        if (c[i] == n-1) ok = false;
    }
    if (n == 2) printf("%d\n", x);
    else if (n == 3) printf("%d\n", 2*x+y);
    else if (ok) ans = cy*y + (n-cy-1)*min(x, y);
    else ans = x + min(x, y) + (n-3)*y
    printf("%lld\n", ans);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N = 2e5+1;

int c[N];
int main() {
    ll n, x, y, u, v, ans=0, cx=0;
    scanf("%lld%lld%lld", &n, &x, &y);
    for(int i=0; i<n-1; ++i) {
        scanf("%lld%lld", &u, &v);
        c[u]++, c[v]++;
    }
    for(int i=1; i<n; ++i) {
         if (c[i] > 2) cx += c[i] - 2;
    }
    ans = cx*y + (n-cx-1)*min(x, y);
    printf("%lld\n", ans);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N = 2e5+1;

int c[N];
int main() {
    ll n, x, y, u, v, ans=0, cy=0;
    scanf("%lld%lld%lld", &n, &x, &y);
    for(int i=0; i<n-1; ++i) {
        scanf("%lld%lld", &u, &v);
        c[u]++, c[v]++;
    }
    bool ok = true;
    for(int i=0; i<n; ++i) {
         if (c[i] > 2) cy += c[i] - 2;
         if (c[i] == n-1) ok = false;
    }
    if (!ok) ans = x + min(x, y) + y*(n-3);
    else ans = cy*y + (n-cy-1)*min(x, y);
    printf("%lld\n", ans);

    return 0;
}


#include <cstdio>
#include <algorithm>

using namespace std;

typedef long long ll;
const int N = 2e5+1;

int c[N];
int main() {
    ll n, x, y, u, v, ans=0, cy=0;
    scanf("%lld%lld%lld", &n, &x, &y);
    for(int i=0; i<n-1; ++i) {
        scanf("%lld%lld", &u, &v);
        c[u]++, c[v]++;
    }
    bool ok = true;
    for(int i=0; i<n; ++i) {
        if (c[i] > 2) cy += c[i] - 2;
        if (c[i] == n-1) ok = false;
    }
    if (x >= y) {
       if (ok) ans = (n-1)*y;
       else ans = x + (n-2)*y;
    } else {
       ans = cy*y + (n-cy-1)*x;
    }
    printf("%lld\n", ans);

    return 0;
}


#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long ll;
const int N = 2e5+1;
vector<int> g[N];
ll n, x, y, u, v, ans=0, c, ok = 1;

int dfs(int u, int p) {
    int as=0;
    if (g[u].size() == n-1) ok = 0;
    for(int i=0; i<g[u].size(); ++i) {
        if (g[u][i] != p) as += dfs(g[u][i], u);
    }
    if (as > 1) {
        c += as - 2;
        return 0;
    }
    return 1;
}

int main() {
    scanf("%lld%lld%lld", &n, &x, &y);
    for(int i=0; i<n-1; ++i) {
        scanf("%lld%lld", &u, &v);
        g[u].push_back(v);
        g[v].push_back(u);
    }
    if (x >= y) {
       if (ok) ans = (n-1)*y;
       else ans = x + (n-2)*y;
    } else {
       ans = c*y + (n-c-1)*x;
    }
    printf("%lld\n", ans);

    return 0;
}


/********************************
*MAHBUBCSEJU                    *
*CSE 22                         *
*JAHANGIRNAGAR UNIVERSITY       *
*TIMUS:164273FU                 *
*UVA>>LIGHTOJ>>HUST:mahbubcseju *
********************************/
#include<cfloat>
#include<climits>
#include<fstream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<map>
#include<cstring>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<string.h>
#define ll long long int
#define ull unsigned long long int
#define I(a) scanf("%d",&a)
#define I2(a,b) scanf("%d%d",&a,&b)
#define I3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define L(a) scanf("%lld",&a)
#define L2(a,b) scanf("%lld%lld",&a,&b)
#define L3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define PI(a) printf("%d\n",a)
#define PL(a) printf("%lld\n",a)
#define PT(t) printf("Case %d: ",t)
#define PB push_back
#define x first
#define y second
#define xx first.first
#define xy first.second
#define yx second.first
#define yy second.second
#define SC scanf
#define PC printf
#define NL printf("\n")
#define SET(a) memset(a,0,sizeof a)
#define SETR(a) memset(a,-1,sizeof a)
#define SZ(a) ((int)a.size())
//#define pi 2.0*acos(0.0)
#define R(a) freopen(a, "r", stdin);
#define W(a) freopen(a, "w", stdout);
#define CB(x) __builtin_popcount(x)
#define STN(a) stringtonumber<ll>(a)
#define lol printf("BUG\n")
#define mk make_pair
using namespace std;
template <class T> inline T BM(T p, T e, T M) {
    ll ret = 1;
    for(; e > 0; e >>= 1) {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a, T b) {
    if(b == 0)return a;
    return gcd(b, a % b);
}
template <class T> inline T mdINV(T a, T M) {
    return BM(a, M - 2, M);
}
template <class T> inline T PW(T p, T e) {
    ll ret = 1;
    for(; e > 0; e >>= 1) {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}
template <class T>string NTS ( T Number ) {
    stringstream ss;
    ss << Number;
    return ss.str();
}
template <class T>T stringtonumber ( const string &Text ) {
    istringstream ss(Text);
    T result;
    return ss >> result ? result : 0;
}
template <class T>bool ISLEFT ( T a,T b,T c) {
    if(((a.x-b.x)*(b.y-c.y)-(b.x-c.x)*(a.y-b.y))!=0)return 1;//Uporer dike //A,b,c, x okkher ordera sorted
    else return 0;
}
#define mx 200000
#define md 1000000007
#define maxp 2050180000

typedef pair<ll,ll> P;

////////define value/////
int n,m,k;
vector<int>v[mx+2];
int vis[mx+2];
ll ans=0;
void dfs(int i,int p) {

    for(int j=0; j<v[i].size(); j++) {
        int x=v[i][j];
        if(x==p)continue;
        dfs(x,i);
        vis[i]+=vis[x];
    }
    //cout<<i<<" "<<vis[i]<<endl;
    if(vis[i]>1)
    ans+=(vis[i]-1);
    if(i==1&&vis[i]==1)ans++;
    if(vis[i]>1){
        vis[i]=0;
    }
    else vis[i]=1;
   // cout<<i<<" "<<vis[i]<<endl;

}

int main() {

    I3(n,m,k);
    for(int i=1; i<n; i++) {
        int x,y;
        I2(x,y);
        v[x].PB(y);

        v[y].PB(x);
    }

    if(m>=k) {
        if(n<=4)ans=(ll)(n-2)*(ll)k+(ll)m;
        else ans=(ll)(n-1)*(ll)k;
    } else {
        dfs(1,0);
     //  cout<<ans<<endl;
     ans--;
        ans=(ans)*(ll)k+(ll)(n-1-ans)*(ll)m;

    }
    PL(ans);

    return 0;
}


/********************************
*MAHBUBCSEJU                    *
*CSE 22                         *
*JAHANGIRNAGAR UNIVERSITY       *
*TIMUS:164273FU                 *
*UVA>>LIGHTOJ>>HUST:mahbubcseju *
********************************/
#include<cfloat>
#include<climits>
#include<fstream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<map>
#include<cstring>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<string.h>
#define ll long long int
#define ull unsigned long long int
#define I(a) scanf("%d",&a)
#define I2(a,b) scanf("%d%d",&a,&b)
#define I3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define L(a) scanf("%lld",&a)
#define L2(a,b) scanf("%lld%lld",&a,&b)
#define L3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define PI(a) printf("%d\n",a)
#define PL(a) printf("%lld\n",a)
#define PT(t) printf("Case %d: ",t)
#define PB push_back
#define x first
#define y second
#define xx first.first
#define xy first.second
#define yx second.first
#define yy second.second
#define SC scanf
#define PC printf
#define NL printf("\n")
#define SET(a) memset(a,0,sizeof a)
#define SETR(a) memset(a,-1,sizeof a)
#define SZ(a) ((int)a.size())
//#define pi 2.0*acos(0.0)
#define R(a) freopen(a, "r", stdin);
#define W(a) freopen(a, "w", stdout);
#define CB(x) __builtin_popcount(x)
#define STN(a) stringtonumber<ll>(a)
#define lol printf("BUG\n")
#define mk make_pair
using namespace std;
template <class T> inline T BM(T p, T e, T M) {
    ll ret = 1;
    for(; e > 0; e >>= 1) {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a, T b) {
    if(b == 0)return a;
    return gcd(b, a % b);
}
template <class T> inline T mdINV(T a, T M) {
    return BM(a, M - 2, M);
}
template <class T> inline T PW(T p, T e) {
    ll ret = 1;
    for(; e > 0; e >>= 1) {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}
template <class T>string NTS ( T Number ) {
    stringstream ss;
    ss << Number;
    return ss.str();
}
template <class T>T stringtonumber ( const string &Text ) {
    istringstream ss(Text);
    T result;
    return ss >> result ? result : 0;
}
template <class T>bool ISLEFT ( T a,T b,T c) {
    if(((a.x-b.x)*(b.y-c.y)-(b.x-c.x)*(a.y-b.y))!=0)return 1;//Uporer dike //A,b,c, x okkher ordera sorted
    else return 0;
}
#define mx 200000
#define md 1000000007
#define maxp 2050180000

typedef pair<ll,ll> P;

////////define value/////
int n,m,k;
vector<int>v[mx+2];
int vis[mx+2];
ll ans=0;
void dfs(int i,int p) {

    for(int j=0; j<v[i].size(); j++) {
        int x=v[i][j];
        if(x==p)continue;
        dfs(x,i);
        vis[i]+=vis[x];
    }
    //cout<<i<<" "<<vis[i]<<endl;
    if(vis[i]>1)
    ans+=(vis[i]-1);
    if(i==1&&vis[i]==1)ans++;
    if(vis[i]>1){
        vis[i]=0;
    }
    else vis[i]=1;
   // cout<<i<<" "<<vis[i]<<endl;

}

int main() {

    I3(n,m,k);
    for(int i=1; i<n; i++) {
        int x,y;
        I2(x,y);
        v[x].PB(y);

        v[y].PB(x);
    }

    if(m>=k) {
        if(n<=4)ans=(n-2)*k+m;
        else ans=(n-1)*k;
    } else {
        dfs(1,0);
     //  cout<<ans<<endl;
     ans--;
        ans=(ans)*(ll)k+(ll)(n-1-ans)*(ll)m;

    }
    PL(ans);

    return 0;
}


/********************************
*MAHBUBCSEJU                    *
*CSE 22                         *
*JAHANGIRNAGAR UNIVERSITY       *
*TIMUS:164273FU                 *
*UVA>>LIGHTOJ>>HUST:mahbubcseju *
********************************/
#include<cfloat>
#include<climits>
#include<fstream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<map>
#include<cstring>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<string.h>
#define ll long long int
#define ull unsigned long long int
#define I(a) scanf("%d",&a)
#define I2(a,b) scanf("%d%d",&a,&b)
#define I3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define L(a) scanf("%lld",&a)
#define L2(a,b) scanf("%lld%lld",&a,&b)
#define L3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define PI(a) printf("%d\n",a)
#define PL(a) printf("%lld\n",a)
#define PT(t) printf("Case %d: ",t)
#define PB push_back
#define x first
#define y second
#define xx first.first
#define xy first.second
#define yx second.first
#define yy second.second
#define SC scanf
#define PC printf
#define NL printf("\n")
#define SET(a) memset(a,0,sizeof a)
#define SETR(a) memset(a,-1,sizeof a)
#define SZ(a) ((int)a.size())
//#define pi 2.0*acos(0.0)
#define R(a) freopen(a, "r", stdin);
#define W(a) freopen(a, "w", stdout);
#define CB(x) __builtin_popcount(x)
#define STN(a) stringtonumber<ll>(a)
#define lol printf("BUG\n")
#define mk make_pair
using namespace std;
template <class T> inline T BM(T p, T e, T M) {
    ll ret = 1;
    for(; e > 0; e >>= 1) {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a, T b) {
    if(b == 0)return a;
    return gcd(b, a % b);
}
template <class T> inline T mdINV(T a, T M) {
    return BM(a, M - 2, M);
}
template <class T> inline T PW(T p, T e) {
    ll ret = 1;
    for(; e > 0; e >>= 1) {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}
template <class T>string NTS ( T Number ) {
    stringstream ss;
    ss << Number;
    return ss.str();
}
template <class T>T stringtonumber ( const string &Text ) {
    istringstream ss(Text);
    T result;
    return ss >> result ? result : 0;
}
template <class T>bool ISLEFT ( T a,T b,T c) {
    if(((a.x-b.x)*(b.y-c.y)-(b.x-c.x)*(a.y-b.y))!=0)return 1;//Uporer dike //A,b,c, x okkher ordera sorted
    else return 0;
}
#define mx 200000
#define md 1000000007
#define maxp 2050180000

typedef pair<ll,ll> P;

////////define value/////
int n,m,k;
vector<int>v[mx+2];
int vis[mx+2];
ll ans=0;
void dfs(int i,int p) {

    for(int j=0; j<v[i].size(); j++) {
        int x=v[i][j];
        if(x==p)continue;
        dfs(x,i);
        vis[i]+=vis[x];
    }
    //cout<<i<<" "<<vis[i]<<endl;
    if(vis[i]>1&&i>1)
    ans+=(vis[i]-1);
    if(vis[i]>1){
        vis[i]=0;
    }
    else vis[i]=1;
   // cout<<i<<" "<<vis[i]<<endl;

}

int main() {

    I3(n,m,k);
    for(int i=1; i<n; i++) {
        int x,y;
        I2(x,y);
        v[x].PB(y);
        v[y].PB(x);
    }

    if(m>=k) {
        if(n<=4)ans=(n-2)*k+m;
        else ans=(n-1)*k;
    } else {
        dfs(1,0);
       // cout<<ans<<endl;
        ans=(ans)*k+(n-1-ans)*m;

    }
    PL(ans);

    return 0;
}


/********************************
*MAHBUBCSEJU                    *
*CSE 22                         *
*JAHANGIRNAGAR UNIVERSITY       *
*TIMUS:164273FU                 *
*UVA>>LIGHTOJ>>HUST:mahbubcseju *
********************************/
#include<cfloat>
#include<climits>
#include<fstream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<map>
#include<cstring>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<string.h>
#define ll long long int
#define ull unsigned long long int
#define I(a) scanf("%d",&a)
#define I2(a,b) scanf("%d%d",&a,&b)
#define I3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define L(a) scanf("%lld",&a)
#define L2(a,b) scanf("%lld%lld",&a,&b)
#define L3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define PI(a) printf("%d\n",a)
#define PL(a) printf("%lld\n",a)
#define PT(t) printf("Case %d: ",t)
#define PB push_back
#define x first
#define y second
#define xx first.first
#define xy first.second
#define yx second.first
#define yy second.second
#define SC scanf
#define PC printf
#define NL printf("\n")
#define SET(a) memset(a,0,sizeof a)
#define SETR(a) memset(a,-1,sizeof a)
#define SZ(a) ((int)a.size())
//#define pi 2.0*acos(0.0)
#define R(a) freopen(a, "r", stdin);
#define W(a) freopen(a, "w", stdout);
#define CB(x) __builtin_popcount(x)
#define STN(a) stringtonumber<ll>(a)
#define lol printf("BUG\n")
#define mk make_pair
using namespace std;
template <class T> inline T BM(T p, T e, T M) {
    ll ret = 1;
    for(; e > 0; e >>= 1) {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a, T b) {
    if(b == 0)return a;
    return gcd(b, a % b);
}
template <class T> inline T mdINV(T a, T M) {
    return BM(a, M - 2, M);
}
template <class T> inline T PW(T p, T e) {
    ll ret = 1;
    for(; e > 0; e >>= 1) {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}
template <class T>string NTS ( T Number ) {
    stringstream ss;
    ss << Number;
    return ss.str();
}
template <class T>T stringtonumber ( const string &Text ) {
    istringstream ss(Text);
    T result;
    return ss >> result ? result : 0;
}
template <class T>bool ISLEFT ( T a,T b,T c) {
    if(((a.x-b.x)*(b.y-c.y)-(b.x-c.x)*(a.y-b.y))!=0)return 1;//Uporer dike //A,b,c, x okkher ordera sorted
    else return 0;
}
#define mx 200000
#define md 1000000007
#define maxp 2050180000

typedef pair<ll,ll> P;

////////define value/////
int n,m,k;
vector<int>v[mx+2];
int vis[mx+2];
void dfs(int i,int p) {
    for(int j=0; j<v[i].size(); j++) {
        int x=v[i][j];
        if(x==p)continue;
        dfs(x,i);
        vis[i]=max(vis[i],vis[x]);
    }
    vis[i]++;
}
ll ans=0;

void dfs2(int i,int p,int op) {
    int ar[3];
    SET(ar);

    for(int j=0; j<v[i].size(); j++) {
        int x=v[i][j];
        if(x==p)continue;
        ar[0]=vis[x];
        sort(ar,ar+3);
    }

    if(op==0) {
        if(i!=1)ans+=k;
        int ho=ar[1]+ar[2]+1;
        ans+=(ll)(ho-1)*m;
       // cout<<ans<<i<<endl;
        bool fl=0,fl1=0;
        for(int j=0; j<v[i].size(); j++) {
            int x=v[i][j];
            if(x==p)continue;
            if(vis[x]==ar[1]&&fl==0) {
                fl=1;
                dfs2(x,i,1);

            } else if(vis[x]==ar[2]&&fl1==0) {
                fl1=1;
                dfs2(x,i,1);
            } else {
                dfs2(x,i,0);
            }
        }

    } else if(op==1) {
        bool fl=0;
        for(int j=0; j<v[i].size(); j++) {
            int x=v[i][j];
            if(x==p)continue;
            if(vis[x]==ar[2]&&fl==0) {
                fl=1;
                dfs2(x,i,op);
            } else {
                dfs2(x,i,0);

            }
        }
    }
}
int main() {

    I3(n,m,k);
    for(int i=1; i<n; i++) {
        int x,y;
        I2(x,y);
        v[x].PB(y);
        v[y].PB(x);
    }

    if(m>=k) {
        if(n<=4)ans=(n-2)*k+m;
        else ans=(n-1)*k;
    } else {
        dfs(1,0);
        dfs2(1,0,0);

    }
    PL(ans);

    return 0;
}


/********************************
*MAHBUBCSEJU                    *
*CSE 22                         *
*JAHANGIRNAGAR UNIVERSITY       *
*TIMUS:164273FU                 *
*UVA>>LIGHTOJ>>HUST:mahbubcseju *
********************************/
#include<cfloat>
#include<climits>
#include<fstream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<map>
#include<cstring>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<string.h>
#define ll long long int
#define ull unsigned long long int
#define I(a) scanf("%d",&a)
#define I2(a,b) scanf("%d%d",&a,&b)
#define I3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define L(a) scanf("%lld",&a)
#define L2(a,b) scanf("%lld%lld",&a,&b)
#define L3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define PI(a) printf("%d\n",a)
#define PL(a) printf("%lld\n",a)
#define PT(t) printf("Case %d: ",t)
#define PB push_back
#define x first
#define y second
#define xx first.first
#define xy first.second
#define yx second.first
#define yy second.second
#define SC scanf
#define PC printf
#define NL printf("\n")
#define SET(a) memset(a,0,sizeof a)
#define SETR(a) memset(a,-1,sizeof a)
#define SZ(a) ((int)a.size())
//#define pi 2.0*acos(0.0)
#define R(a) freopen(a, "r", stdin);
#define W(a) freopen(a, "w", stdout);
#define CB(x) __builtin_popcount(x)
#define STN(a) stringtonumber<ll>(a)
#define lol printf("BUG\n")
#define mk make_pair
using namespace std;
template <class T> inline T BM(T p, T e, T M) {
    ll ret = 1;
    for(; e > 0; e >>= 1) {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a, T b) {
    if(b == 0)return a;
    return gcd(b, a % b);
}
template <class T> inline T mdINV(T a, T M) {
    return BM(a, M - 2, M);
}
template <class T> inline T PW(T p, T e) {
    ll ret = 1;
    for(; e > 0; e >>= 1) {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}
template <class T>string NTS ( T Number ) {
    stringstream ss;
    ss << Number;
    return ss.str();
}
template <class T>T stringtonumber ( const string &Text ) {
    istringstream ss(Text);
    T result;
    return ss >> result ? result : 0;
}
template <class T>bool ISLEFT ( T a,T b,T c) {
    if(((a.x-b.x)*(b.y-c.y)-(b.x-c.x)*(a.y-b.y))!=0)return 1;//Uporer dike //A,b,c, x okkher ordera sorted
    else return 0;
}
#define mx 100000
#define md 1000000007
#define maxp 2050180000

typedef pair<ll,ll> P;

////////define value/////
int n,m,k;
vector<int>v[mx+2];
int vis[mx+2];
void dfs(int i,int p) {
    for(int j=0; j<v[i].size(); j++) {
        int x=v[i][j];
        if(x==p)continue;
        dfs(x,i);
        vis[i]=max(vis[i],vis[x]);
    }
    vis[i]++;
}
ll ans=0;

void dfs2(int i,int p,int op) {
    int ar[3];
    SET(ar);

    for(int j=0; j<v[i].size(); j++) {
        int x=v[i][j];
        if(x==p)continue;
        ar[0]=vis[x];
        sort(ar,ar+3);
    }

    if(op==0) {
        if(i!=1)ans+=k;
        int ho=ar[1]+ar[2]+1;
        ans+=(ll)(ho-1)*m;
       // cout<<ans<<i<<endl;
        bool fl=0,fl1=0;
        for(int j=0; j<v[i].size(); j++) {
            int x=v[i][j];
            if(x==p)continue;
            if(vis[x]==ar[1]&&fl==0) {
                fl=1;
                dfs2(x,i,1);

            } else if(vis[x]==ar[2]&&fl1==0) {
                fl1=1;
                dfs2(x,i,1);
            } else {
                ans+=k;
                dfs2(x,i,0);
            }
        }

    } else if(op==1) {
        bool fl=0;
        for(int j=0; j<v[i].size(); j++) {
            int x=v[i][j];
            if(x==p)continue;
            if(vis[x]==ar[2]&&fl==0) {
                fl=1;
                dfs2(x,i,op);
            } else {
                dfs2(x,i,0);

            }
        }
    }
}
int main() {

    I3(n,m,k);
    for(int i=1; i<n; i++) {
        int x,y;
        I2(x,y);
        v[x].PB(y);
        v[y].PB(x);
    }

    if(m>=k) {
        if(n<=4)ans=(n-2)*k+m;
        else ans=(n-1)*k;
    } else {
        dfs(1,0);
        dfs2(1,0,0);

    }
    PL(ans);

    return 0;
}


/********************************
*MAHBUBCSEJU                    *
*CSE 22                         *
*JAHANGIRNAGAR UNIVERSITY       *
*TIMUS:164273FU                 *
*UVA>>LIGHTOJ>>HUST:mahbubcseju *
********************************/
#include<cfloat>
#include<climits>
#include<fstream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<map>
#include<cstring>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<string.h>
#define ll long long int
#define ull unsigned long long int
#define I(a) scanf("%d",&a)
#define I2(a,b) scanf("%d%d",&a,&b)
#define I3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define L(a) scanf("%lld",&a)
#define L2(a,b) scanf("%lld%lld",&a,&b)
#define L3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define PI(a) printf("%d\n",a)
#define PL(a) printf("%lld\n",a)
#define PT(t) printf("Case %d: ",t)
#define PB push_back
#define x first
#define y second
#define xx first.first
#define xy first.second
#define yx second.first
#define yy second.second
#define SC scanf
#define PC printf
#define NL printf("\n")
#define SET(a) memset(a,0,sizeof a)
#define SETR(a) memset(a,-1,sizeof a)
#define SZ(a) ((int)a.size())
//#define pi 2.0*acos(0.0)
#define R(a) freopen(a, "r", stdin);
#define W(a) freopen(a, "w", stdout);
#define CB(x) __builtin_popcount(x)
#define STN(a) stringtonumber<ll>(a)
#define lol printf("BUG\n")
#define mk make_pair
using namespace std;
template <class T> inline T BM(T p, T e, T M) {
    ll ret = 1;
    for(; e > 0; e >>= 1) {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a, T b) {
    if(b == 0)return a;
    return gcd(b, a % b);
}
template <class T> inline T mdINV(T a, T M) {
    return BM(a, M - 2, M);
}
template <class T> inline T PW(T p, T e) {
    ll ret = 1;
    for(; e > 0; e >>= 1) {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}
template <class T>string NTS ( T Number ) {
    stringstream ss;
    ss << Number;
    return ss.str();
}
template <class T>T stringtonumber ( const string &Text ) {
    istringstream ss(Text);
    T result;
    return ss >> result ? result : 0;
}
template <class T>bool ISLEFT ( T a,T b,T c) {
    if(((a.x-b.x)*(b.y-c.y)-(b.x-c.x)*(a.y-b.y))!=0)return 1;//Uporer dike //A,b,c, x okkher ordera sorted
    else return 0;
}
#define mx 200000
#define md 1000000007
#define maxp 2050180000

typedef pair<ll,ll> P;

////////define value/////
int n,m,k;
vector<int>v[mx+2];
int vis[mx+2];
ll ans=0;
void dfs(int i,int p) {

    for(int j=0; j<v[i].size(); j++) {
        int x=v[i][j];
        if(x==p)continue;
        dfs(x,i);
        vis[i]+=vis[x];
    }
    //cout<<i<<" "<<vis[i]<<endl;
    if(vis[i]>1)
    ans+=(vis[i]-1);
    //if(i==1)cout<<vis[i]<<endl;
    if(i==1&&vis[i]<=1)ans++;
    if(vis[i]>1){
        vis[i]=0;
    }
    else vis[i]=1;
   // cout<<i<<" "<<vis[i]<<endl;

}

int main() {

    I3(n,m,k);
    int con[n+2];
    SET(con);
    bool fl=0;
    for(int i=1; i<n; i++) {
        int x,y;
        I2(x,y);
        v[x].PB(y);

        v[y].PB(x);
        con[x]++;
        con[y]++;
        if(con[x]==n-1||con[y]==n-1)fl=1;

    }

    if(m>=k) {
        if(fl)ans=(ll)(n-2)*(ll)k+(ll)m;
        else ans=(ll)(n-1)*(ll)k;
    } else {
        dfs(1,0);
      // cout<<ans<<endl;
     ans--;
        ans=(ans)*(ll)k+(ll)(n-1-ans)*(ll)m;

    }
    PL(ans);

    return 0;
}


/********************************
*MAHBUBCSEJU                    *
*CSE 22                         *
*JAHANGIRNAGAR UNIVERSITY       *
*TIMUS:164273FU                 *
*UVA>>LIGHTOJ>>HUST:mahbubcseju *
********************************/
#include<cfloat>
#include<climits>
#include<fstream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<map>
#include<cstring>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<string.h>
#define ll long long int
#define ull unsigned long long int
#define I(a) scanf("%d",&a)
#define I2(a,b) scanf("%d%d",&a,&b)
#define I3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define L(a) scanf("%lld",&a)
#define L2(a,b) scanf("%lld%lld",&a,&b)
#define L3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define PI(a) printf("%d\n",a)
#define PL(a) printf("%lld\n",a)
#define PT(t) printf("Case %d: ",t)
#define PB push_back
#define x first
#define y second
#define xx first.first
#define xy first.second
#define yx second.first
#define yy second.second
#define SC scanf
#define PC printf
#define NL printf("\n")
#define SET(a) memset(a,0,sizeof a)
#define SETR(a) memset(a,-1,sizeof a)
#define SZ(a) ((int)a.size())
//#define pi 2.0*acos(0.0)
#define R(a) freopen(a, "r", stdin);
#define W(a) freopen(a, "w", stdout);
#define CB(x) __builtin_popcount(x)
#define STN(a) stringtonumber<ll>(a)
#define lol printf("BUG\n")
#define mk make_pair
using namespace std;
template <class T> inline T BM(T p, T e, T M) {
    ll ret = 1;
    for(; e > 0; e >>= 1) {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a, T b) {
    if(b == 0)return a;
    return gcd(b, a % b);
}
template <class T> inline T mdINV(T a, T M) {
    return BM(a, M - 2, M);
}
template <class T> inline T PW(T p, T e) {
    ll ret = 1;
    for(; e > 0; e >>= 1) {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}
template <class T>string NTS ( T Number ) {
    stringstream ss;
    ss << Number;
    return ss.str();
}
template <class T>T stringtonumber ( const string &Text ) {
    istringstream ss(Text);
    T result;
    return ss >> result ? result : 0;
}
template <class T>bool ISLEFT ( T a,T b,T c) {
    if(((a.x-b.x)*(b.y-c.y)-(b.x-c.x)*(a.y-b.y))!=0)return 1;//Uporer dike //A,b,c, x okkher ordera sorted
    else return 0;
}
#define mx 200000
#define md 1000000007
#define maxp 2050180000

typedef pair<ll,ll> P;

////////define value/////
int n,m,k;
vector<int>v[mx+2];
int vis[mx+2];
void dfs(int i,int p) {
    for(int j=0; j<v[i].size(); j++) {
        int x=v[i][j];
        if(x==p)continue;
        dfs(x,i);
        vis[i]=max(vis[i],vis[x]);
    }
    vis[i]++;
}
ll ans=0;

void dfs2(int i,int p,int op) {
    int ar[3];
    SET(ar);

    for(int j=0; j<v[i].size(); j++) {
        int x=v[i][j];
        if(x==p)continue;
        ar[0]=vis[x];
        sort(ar,ar+3);
    }

    if(op==0) {
        if(i!=1)ans+=k;
        int ho=ar[1]+ar[2]+1;
        ans+=(ll)(ho-1)*m;
       // cout<<ans<<i<<endl;
        bool fl=0,fl1=0;
        for(int j=0; j<v[i].size(); j++) {
            int x=v[i][j];
            if(x==p)continue;
            if(vis[x]==ar[1]&&fl==0) {
                fl=1;
                dfs2(x,i,1);

            } else if(vis[x]==ar[2]&&fl1==0) {
                fl1=1;
                dfs2(x,i,1);
            } else {
                ans+=k;
                dfs2(x,i,0);
            }
        }

    } else if(op==1) {
        bool fl=0;
        for(int j=0; j<v[i].size(); j++) {
            int x=v[i][j];
            if(x==p)continue;
            if(vis[x]==ar[2]&&fl==0) {
                fl=1;
                dfs2(x,i,op);
            } else {
                dfs2(x,i,0);

            }
        }
    }
}
int main() {

    I3(n,m,k);
    for(int i=1; i<n; i++) {
        int x,y;
        I2(x,y);
        v[x].PB(y);
        v[y].PB(x);
    }

    if(m>=k) {
        if(n<=4)ans=(n-2)*k+m;
        else ans=(n-1)*k;
    } else {
        dfs(1,0);
        dfs2(1,0,0);

    }
    PL(ans);

    return 0;
}


/********************************
*MAHBUBCSEJU                    *
*CSE 22                         *
*JAHANGIRNAGAR UNIVERSITY       *
*TIMUS:164273FU                 *
*UVA>>LIGHTOJ>>HUST:mahbubcseju *
********************************/
#include<cfloat>
#include<climits>
#include<fstream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<map>
#include<cstring>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<string.h>
#define ll long long int
#define ull unsigned long long int
#define I(a) scanf("%d",&a)
#define I2(a,b) scanf("%d%d",&a,&b)
#define I3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define L(a) scanf("%lld",&a)
#define L2(a,b) scanf("%lld%lld",&a,&b)
#define L3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define PI(a) printf("%d\n",a)
#define PL(a) printf("%lld\n",a)
#define PT(t) printf("Case %d: ",t)
#define PB push_back
#define x first
#define y second
#define xx first.first
#define xy first.second
#define yx second.first
#define yy second.second
#define SC scanf
#define PC printf
#define NL printf("\n")
#define SET(a) memset(a,0,sizeof a)
#define SETR(a) memset(a,-1,sizeof a)
#define SZ(a) ((int)a.size())
//#define pi 2.0*acos(0.0)
#define R(a) freopen(a, "r", stdin);
#define W(a) freopen(a, "w", stdout);
#define CB(x) __builtin_popcount(x)
#define STN(a) stringtonumber<ll>(a)
#define lol printf("BUG\n")
#define mk make_pair
using namespace std;
template <class T> inline T BM(T p, T e, T M) {
    ll ret = 1;
    for(; e > 0; e >>= 1) {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a, T b) {
    if(b == 0)return a;
    return gcd(b, a % b);
}
template <class T> inline T mdINV(T a, T M) {
    return BM(a, M - 2, M);
}
template <class T> inline T PW(T p, T e) {
    ll ret = 1;
    for(; e > 0; e >>= 1) {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}
template <class T>string NTS ( T Number ) {
    stringstream ss;
    ss << Number;
    return ss.str();
}
template <class T>T stringtonumber ( const string &Text ) {
    istringstream ss(Text);
    T result;
    return ss >> result ? result : 0;
}
template <class T>bool ISLEFT ( T a,T b,T c) {
    if(((a.x-b.x)*(b.y-c.y)-(b.x-c.x)*(a.y-b.y))!=0)return 1;//Uporer dike //A,b,c, x okkher ordera sorted
    else return 0;
}
#define mx 200000
#define md 1000000007
#define maxp 2050180000

typedef pair<ll,ll> P;

////////define value/////
int n,m,k;
vector<int>v[mx+2];
int vis[mx+2];
ll ans=0;
void dfs(int i,int p) {

    for(int j=0; j<v[i].size(); j++) {
        int x=v[i][j];
        if(x==p)continue;
        dfs(x,i);
        vis[i]+=vis[x];
    }
    //cout<<i<<" "<<vis[i]<<endl;
    if(vis[i]>1)
    ans+=(vis[i]-1);
    //if(i==1)cout<<vis[i]<<endl;
    if(i==1&&vis[i]<=1)ans++;
    if(vis[i]>1){
        vis[i]=0;
    }
    else vis[i]=1;
   // cout<<i<<" "<<vis[i]<<endl;

}

int main() {

    I3(n,m,k);
    for(int i=1; i<n; i++) {
        int x,y;
        I2(x,y);
        v[x].PB(y);

        v[y].PB(x);
    }

    if(m>=k) {
        if(n<=4)ans=(ll)(n-2)*(ll)k+(ll)m;
        else ans=(ll)(n-1)*(ll)k;
    } else {
        dfs(1,0);
      // cout<<ans<<endl;
     ans--;
        ans=(ans)*(ll)k+(ll)(n-1-ans)*(ll)m;

    }
    PL(ans);

    return 0;
}


/********************************
*MAHBUBCSEJU                    *
*CSE 22                         *
*JAHANGIRNAGAR UNIVERSITY       *
*TIMUS:164273FU                 *
*UVA>>LIGHTOJ>>HUST:mahbubcseju *
********************************/
#include<cfloat>
#include<climits>
#include<fstream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<map>
#include<cstring>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<string.h>
#define ll long long int
#define ull unsigned long long int
#define I(a) scanf("%d",&a)
#define I2(a,b) scanf("%d%d",&a,&b)
#define I3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define L(a) scanf("%lld",&a)
#define L2(a,b) scanf("%lld%lld",&a,&b)
#define L3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define PI(a) printf("%d\n",a)
#define PL(a) printf("%lld\n",a)
#define PT(t) printf("Case %d: ",t)
#define PB push_back
#define x first
#define y second
#define xx first.first
#define xy first.second
#define yx second.first
#define yy second.second
#define SC scanf
#define PC printf
#define NL printf("\n")
#define SET(a) memset(a,0,sizeof a)
#define SETR(a) memset(a,-1,sizeof a)
#define SZ(a) ((int)a.size())
//#define pi 2.0*acos(0.0)
#define R(a) freopen(a, "r", stdin);
#define W(a) freopen(a, "w", stdout);
#define CB(x) __builtin_popcount(x)
#define STN(a) stringtonumber<ll>(a)
#define lol printf("BUG\n")
#define mk make_pair
using namespace std;
template <class T> inline T BM(T p, T e, T M) {
    ll ret = 1;
    for(; e > 0; e >>= 1) {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a, T b) {
    if(b == 0)return a;
    return gcd(b, a % b);
}
template <class T> inline T mdINV(T a, T M) {
    return BM(a, M - 2, M);
}
template <class T> inline T PW(T p, T e) {
    ll ret = 1;
    for(; e > 0; e >>= 1) {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}
template <class T>string NTS ( T Number ) {
    stringstream ss;
    ss << Number;
    return ss.str();
}
template <class T>T stringtonumber ( const string &Text ) {
    istringstream ss(Text);
    T result;
    return ss >> result ? result : 0;
}
template <class T>bool ISLEFT ( T a,T b,T c) {
    if(((a.x-b.x)*(b.y-c.y)-(b.x-c.x)*(a.y-b.y))!=0)return 1;//Uporer dike //A,b,c, x okkher ordera sorted
    else return 0;
}
#define mx 200000
#define md 1000000007
#define maxp 2050180000

typedef pair<ll,ll> P;

////////define value/////
int n,m,k;
vector<int>v[mx+2];
int vis[mx+2];
void dfs(int i,int p) {
    for(int j=0; j<v[i].size(); j++) {
        int x=v[i][j];
        if(x==p)continue;
        dfs(x,i);
        vis[i]=max(vis[i],vis[x]);
    }
    vis[i]++;
}
ll ans=0;

void dfs2(int i,int p,int op) {
    int ar[3];
    SET(ar);

    for(int j=0; j<v[i].size(); j++) {
        int x=v[i][j];
        if(x==p)continue;
        ar[0]=vis[x];
        sort(ar,ar+3);
    }

    if(op==0) {
        if(i!=1)ans+=(ll)k;
        int ho=ar[1]+ar[2]+1;
        ans+=(ll)(ho-1)*m;
       // cout<<ans<<i<<endl;
        bool fl=0,fl1=0;
        for(int j=0; j<v[i].size(); j++) {
            int x=v[i][j];
            if(x==p)continue;
            if(vis[x]==ar[1]&&fl==0) {
                fl=1;
                dfs2(x,i,1);

            } else if(vis[x]==ar[2]&&fl1==0) {
                fl1=1;
                dfs2(x,i,1);
            } else {
                dfs2(x,i,0);
            }
        }

    } else if(op==1) {
        bool fl=0;
        for(int j=0; j<v[i].size(); j++) {
            int x=v[i][j];
            if(x==p)continue;
            if(vis[x]==ar[2]&&fl==0) {
                fl=1;
                dfs2(x,i,op);
            } else {
                dfs2(x,i,0);

            }
        }
    }
}
int main() {

    I3(n,m,k);
    for(int i=1; i<n; i++) {
        int x,y;
        I2(x,y);
        v[x].PB(y);
        v[y].PB(x);
    }

    if(m>=k) {
        if(n<=4)ans=(n-2)*k+m;
        else ans=(n-1)*k;
    } else {
        dfs(1,0);
        dfs2(1,0,0);

    }
    PL(ans);

    return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
using namespace std;
long long int n,x,y;
vector<int>adj[200007];
int dp[200007][3];

void dfs(int i,int parent)
{
for(int j=0;j<adj[i].size();j++)
if(adj[i][j]!=parent)
{
dfs(adj[i][j],i);
dp[i][0]+=max(dp[adj[i][j]][0],max(dp[adj[i][j]][2],dp[adj[i][j]][1]));
}
int temp[adj[i].size()+2];
int c=0;
for(int j=0;j<adj[i].size();j++)
if(adj[i][j]!=parent)
{
dp[i][1]=max(dp[i][1],1+dp[i][0]-max(dp[adj[i][j]][0],max(dp[adj[i][j]][2],dp[adj[i][j]][1]))+max(dp[adj[i][j]][0],dp[adj[i][j]][1]));
temp[c++]=max(dp[adj[i][j]][0],max(dp[adj[i][j]][2],dp[adj[i][j]][1]))-max(dp[adj[i][j]][0],dp[adj[i][j]][1]);
}
sort(temp,temp+c);
if(c>=2)
dp[i][2]=2+dp[i][0]-temp[0]-temp[1];
}

long long int func()
{
if(y<=x)
{
for(int i=1;i<=n;i++)
if(adj[i].size()==n-1)
return x+(n-2)*y;
return (n-1)*y;
}
dfs(1,-1);
long long int f=max(dp[1][0],max(dp[1][1],dp[1][2]));
//cout<<dp[1][0]<<" "<<dp[1][1]<<" "<<dp[1][2]<<endl;
return x*f+(n-1-f)*y;
}

int main()
{
ios_base::sync_with_stdio(false);
cin>>n>>x>>y;
for(int i=1;i<n;i++)
{
int u,v;
cin>>u>>v;
adj[u].push_back(v);
adj[v].push_back(u);
}
cout<<func()<<endl;
return 0;
}