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

#include<vector>
#include <algorithm>
#include<string>
using namespace std;
#define inf 99999999
#define repf(i,a,b) for(int i=(a);i<=(b);i++)
typedef long long ll;
#define N 210000
int n;
//ll vis[N];
int dp[N][3];
int a[N];
vector<int>v[N];
void dfs(int x,int pre)
{
    int i,j,k;
    if(v[x].size()==1) return ;
    for(i = 0;i < v[x].size();i++)
    {
        if(v[x][i]==pre) continue;
        else dfs(v[x][i],x);

    }
    int u=0,z=0,tmp=0;
    for(i = 0;i < v[x].size();i++)
    {
       int u=v[x][i];
       if(u==pre) continue;
       int t1 = max(dp[u][0], dp[u][1]);
        int t2 = max(t1, dp[u][2]);
        int t3 = max(t1, t2);
        int cur=x;
        dp[cur][2] = max(dp[cur][2]+t3, dp[cur][1]+t1+1);
        dp[cur][1] = max(dp[cur][1]+t3, dp[cur][0]+t1+1);
        dp[cur][0] += t3;
	}
}
int find1()
{
    int flag=0;
    int i;
    for(i = 1;i <= n;i++)
    {
        if(v[i].size()==n-1) return 0;
    }
    return 1;
}
int main()
{
    int x,y;
    while(cin>>n>>x>>y)
    {
    //    memset(vis,0,sizeof(vis));
         int i,j;
        for(i=0;i<=n;i++)
        {
            for(j=0;j<=2;j++)
            {
                dp[i][j]=0;
            }
        }
       for(i = 0;i <= n;i++) v[i].clear();
       int p,q;
       for(i = 1;i < n;i++)
       {
           scanf("%d %d",&p,&q);
           v[p].push_back(q);
           v[q].push_back(p);
       }
       if(x>=y)
       {
           if(find1())
                printf("%I64d\n",(ll)y*(n-1));
           else
                printf("%I64d\n",(ll)y*(n-2)+x);
            continue;
       }
        dfs(1,0);
        int ans=0;
        for(i=0;i<=2;i++)
        {
            ans=max(ans,dp[1][i]);
        }

        printf("%I64d\n",(ll)x*(ll)ans+(ll)(n-1-ans)*(ll)y);
    }
}


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

#include<vector>
#include <algorithm>
#include<string>
using namespace std;
#define inf 99999999
#define repf(i,a,b) for(int i=(a);i<=(b);i++)
typedef long long ll;
#define N 210000
int n;
int vis[N];
int dp[N][2];
int a[N];
vector<int>v[N];
void dfs(int x,int pre)
{
    int i,j,k;
    if(v[x].size()==1)
    {
        dp[x][0]=dp[x][1]=1;
        return ;
    }
    for(i = 0;i < v[x].size();i++)
    {
        if(v[x][i]==pre) continue;
        else dfs(v[x][i],x);

    }
    for(i = 0;i < v[x].size();i++)
    {
       int y=v[x][i];
       if(y==pre) continue;
       if(dp[y][0]+1>dp[x][0])
       {
           dp[x][1]=dp[x][0];
           dp[x][0]=dp[y][0]+1;
       }
       else if(dp[y][0]+1>dp[x][1])
       {
           dp[x][1]=dp[y][0]+1;
       }
    }
}
int main()
{
    int x,y;
    while(cin>>n>>x>>y)
    {
    //    memset(vis,0,sizeof(vis));
         int i,j;
        for(i=0;i<=n;i++)
        {
            for(j=0;j<=1;j++)
            {
                dp[i][j]=j;
            }
        }
       for(i = 0;i <= n;i++) v[i].clear();
       int p,q;
       for(i = 1;i < n;i++)
       {
           scanf("%d %d",&p,&q);
           v[p].push_back(q);
           v[q].push_back(p);
       }
       if(x>=y)
       {
           printf("%d\n",y*(n-1));
            continue;
       }
        dfs(1,0);
        int ans=dp[1][0]+dp[1][1]-2;
        printf("%I64d\n",(ll)x*(ll)ans+(ll)(n-1-ans)*(ll)y);
    }
}


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

#include<vector>
#include <algorithm>
#include<string>
using namespace std;
#define inf 99999999
#define repf(i,a,b) for(int i=(a);i<=(b);i++)
typedef long long ll;
#define N 210000
int n;
//ll vis[N];
int dp[N][3];
int a[N];
vector<int>v[N];
void dfs(int x,int pre)
{
    int i,j,k;
    for(i = 0;i < v[x].size();i++)
    {
        if(v[x][i]==pre) continue;
        else dfs(v[x][i],x);

    }
    int u=0,z=0,tmp=0;
    for(i = 0;i < v[x].size();i++)
    {
       int u=v[x][i];
       if(u==pre) continue;
       int t1 = max(dp[u][0], dp[u][1]);
        int t2 = max(t1, dp[u][2]);
        int t3 = max(t1, t2);
        int cur=x;
        dp[cur][2] = max(dp[cur][2]+t3, dp[cur][1]+t1+1);
        dp[cur][1] = max(dp[cur][1]+t3, dp[cur][0]+t1+1);
        dp[cur][0] += t3;
	}
}
int find1()
{
    int flag=0;
    int i;
    for(i = 1;i <= n;i++)
    {
        if(v[i].size()==n-1) return 0;
    }
    return 1;
}
int main()
{
    int x,y;
    while(cin>>n>>x>>y)
    {
    //    memset(vis,0,sizeof(vis));
         int i,j;
        for(i=0;i<=n;i++)
        {
            for(j=0;j<=2;j++)
            {
                dp[i][j]=0;
            }
        }
       for(i = 0;i <= n;i++) v[i].clear();
       int p,q;
       for(i = 1;i < n;i++)
       {
           scanf("%d %d",&p,&q);
           v[p].push_back(q);
           v[q].push_back(p);
       }
       if(x>=y)
       {
           if(find1())
                printf("%I64d\n",(ll)y*(n-1));
           else
                printf("%I64d\n",(ll)y*(n-2)+x);
            continue;
       }
        dfs(1,0);
        int ans=0;
        for(i=0;i<=2;i++)
        {
            ans=max(ans,dp[1][i]);
        }

        printf("%I64d\n",(ll)x*(ll)ans+(ll)(n-1-ans)*(ll)y);
    }
}


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

#include<vector>
#include <algorithm>
#include<string>
using namespace std;
#define inf 99999999
#define repf(i,a,b) for(int i=(a);i<=(b);i++)
typedef long long ll;
#define N 210000
int n;
int vis[N];
int dp[N][2];
int a[N];
vector<int>v[N];
void dfs(int x,int pre)
{
    int i,j,k;
    if(v[x].size()==1)
    {
        dp[x][0]=dp[x][1]=1;
        return ;
    }
    for(i = 0;i < v[x].size();i++)
    {
        if(v[x][i]==pre) continue;
        else dfs(v[x][i],x);

    }
    for(i = 0;i < v[x].size();i++)
    {
       int y=v[x][i];
       if(y==pre) continue;
       if(dp[y][0]+1>dp[x][0])
       {
           dp[x][1]=dp[x][0];
           dp[x][0]=dp[y][0]+1;
       }
       else if(dp[y][0]+1>dp[x][1])
       {
           dp[x][1]=dp[y][0]+1;
       }
    }
}
int main()
{
    int x,y;
    while(cin>>n>>x>>y)
    {
    //    memset(vis,0,sizeof(vis));
         int i,j;
        for(i=0;i<=n;i++)
        {
            for(j=0;j<=1;j++)
            {
                dp[i][j]=j;
            }
        }
       for(i = 0;i <= n;i++) v[i].clear();
       int p,q;
       for(i = 1;i < n;i++)
       {
           scanf("%d %d",&p,&q);
           v[p].push_back(q);
           v[q].push_back(p);
       }
       if(x>=y)
       {
           printf("%d\n",y*(n-1));
            continue;
       }
        dfs(1,0);
        int ans=0;
        for(i=1;i<=n;i++)
        {
            ans=max(ans,dp[1][0]+dp[1][1]-2);
        }

        printf("%I64d\n",(ll)x*(ll)ans+(ll)(n-1-ans)*(ll)y);
    }
}


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

#include<vector>
#include <algorithm>
#include<string>
using namespace std;
#define inf 99999999
#define repf(i,a,b) for(int i=(a);i<=(b);i++)
typedef long long ll;
#define N 210000
int n;
int vis[N];
int dp[N][2];
int a[N];
vector<int>v[N];
void dfs(int x,int pre)
{
    int i,j,k;
    if(v[x].size()==1)
    {
        dp[x][0]=dp[x][1]=1;
        return ;
    }
    for(i = 0;i < v[x].size();i++)
    {
        if(v[x][i]==pre) continue;
        else dfs(v[x][i],x);

    }
    for(i = 0;i < v[x].size();i++)
    {
       int y=v[x][i];
       if(y==pre) continue;
       if(dp[y][0]+1>dp[x][0])
       {
           dp[x][1]=dp[x][0];
           dp[x][0]=dp[y][0]+1;
       }
       else if(dp[y][0]+1>dp[x][1])
       {
           dp[x][1]=dp[y][0]+1;
       }
    }
}
int main()
{
    int x,y;
    while(cin>>n>>x>>y)
    {
    //    memset(vis,0,sizeof(vis));
         int i,j;
        for(i=0;i<=n;i++)
        {
            for(j=0;j<=1;j++)
            {
                dp[i][j]=j;
            }
        }
       for(i = 0;i <= n;i++) v[i].clear();
       int p,q;
       for(i = 1;i < n;i++)
       {
           scanf("%d %d",&p,&q);
           v[p].push_back(q);
           v[q].push_back(p);
       }
       if(x>=y)
       {
           printf("%d\n",y*(n-1));
            continue;
       }
        dfs(1,0);
        int ans=dp[1][0]+dp[1][1]-2;
        printf("%d\n",x*ans+(n-1-ans)*y);
    }
}


#include <bits/stdc++.h>
#define filein(t) freopen(t, "r", stdin)
#define fileout(t) freopen(t, "w", stdout)
#define mp make_pair
#define f first
#define s second
#define N 200005
#define NN 10000000
#define BIT(i, j) ((j >> i) & 1)
#define ll long long
#define oo 1000000007
#define ln 1e9+1
#define Pi 3.14159265359
#define Line pair < pair <ll, ll>, ll >
#define pi pair < int, pair <int, int> >
#define Pa pair < int ,int >

using namespace std;

vector < int > a[N];
int DP[2][N], n, X, Y;

void DFS(int u, int pre)
{
    if(a[u].size() == 1)
    {
        DP[0][u] = 1;
        DP[1][u] = ln;
        return;
    }
    Pa Min = mp(ln, ln);
    int Sum = 0;
    for(int i=0; i<a[u].size(); i++)
    {
        int v = a[u][i];
        if(v == pre)    continue;
        DFS(v, u);
        Sum += min(DP[1][v], DP[0][v]);
        if(Min.f > DP[0][v] - min(DP[1][v], DP[0][v]))
        {
            Min.s = Min.f;
            Min.f = DP[0][v] - min(DP[1][v], DP[0][v]);
        }
        else
            Min.s = min(Min.s, DP[0][v] - min(DP[1][v], DP[0][v]));
    }
    DP[1][u] = Sum + Min.f + Min.s - 1;
    DP[0][u] = Sum + Min.f;
}

int Min_Edge()
{
    if(n == 2)  return 1;
    int root = 1;
    while(a[root].size() == 1 && root < n)  root++;
    DFS(root, 0);
    return min(DP[0][root], DP[1][root]);
}

int Max_Edge()
{
    for(int i=1; i<=n; i++)
        if(a[i].size() == n-1)   return n-1;
    return n;
}

void Solve()
{
    if(X <= Y)
    {
        int t = Min_Edge();
        cout << (ll)(t-1) * Y + (ll)(n - t) * X;
        return;
    }
    int t = Max_Edge();
    cout << (ll)(t-1) * Y + (ll)(n - t) * X;
}

int main()
{
    ios_base::sync_with_stdio(0);
    //filein("inp.txt");  fileout("out.txt");
    int u, v;
    cin >> n >> X >> Y;
    for(int i=1; i<n; i++)
    {
        cin >> u >> v;
        a[u].push_back(v);
        a[v].push_back(u);
    }
    Solve();
}


#include <bits/stdc++.h>
#define filein(t) freopen(t, "r", stdin)
#define fileout(t) freopen(t, "w", stdout)
#define mp make_pair
#define f first
#define s second
#define N 200005
#define NN 10000000
#define BIT(i, j) ((j >> i) & 1)
#define ll long long
#define oo 1000000007
#define ln 1e9+1
#define Pi 3.14159265359
#define Line pair < pair <ll, ll>, ll >
#define pi pair < int, pair <int, int> >
#define Pa pair < int ,int >

using namespace std;

vector < int > a[N];
int DP[2][N], n, X, Y;

void DFS(int u, int pre)
{
    if(a[u].size() == 1)
    {
        DP[0][u] = 1;
        DP[1][u] = ln;
        return;
    }
    Pa Min = mp(ln, ln);
    int Sum = 0;
    for(int i=0; i<a[u].size(); i++)
    {
        int v = a[u][i];
        if(v == pre)    continue;
        DFS(v, u);
        Sum += min(DP[1][v], DP[0][v]);
        if(Min.f > DP[0][v] - min(DP[1][v], DP[0][v]))
        {
            Min.s = Min.f;
            Min.f = DP[0][v] - min(DP[1][v], DP[0][v]);
        }
        else
            Min.s = min(Min.s, DP[0][v] - min(DP[1][v], DP[0][v]));
    }
    DP[1][u] = Sum + Min.f + Min.s - 1;
    DP[0][u] = Sum + Min.f;
}

int Min_Edge()
{
    if(n == 2)  return 1;
    int root = 1;
    while(a[root].size() == 1 && root < n)  root++;
    DFS(root, 0);
    return min(DP[0][root], DP[1][root]);
}

int Max_Edge()
{
    for(int i=1; i<=n; i++)
        if(a[i].size() == n-1)   return n-1;
    return n;
}

void Solve()
{
    if(X <= Y)
    {
        int t = Min_Edge();
        cout << (t-1) * Y + (n - t) * X;
        return;
    }
    int t = Max_Edge();
    cout << (t-1) * Y + (n - t) * X;
}

int main()
{
    ios_base::sync_with_stdio(0);
   // filein("inp.txt");  fileout("out.txt");
    int u, v;
    cin >> n >> X >> Y;
    for(int i=1; i<n; i++)
    {
        cin >> u >> v;
        a[u].push_back(v);
        a[v].push_back(u);
    }
    Solve();
}


#include <bits/stdc++.h>
#define filein(t) freopen(t, "r", stdin)
#define fileout(t) freopen(t, "w", stdout)
#define mp make_pair
#define f first
#define s second
#define N 200005
#define NN 10000000
#define BIT(i, j) ((j >> i) & 1)
#define ll long long
#define oo 1000000007
#define ln 1e9+1
#define Pi 3.14159265359
#define Line pair < pair <ll, ll>, ll >
#define pi pair < int, pair <int, int> >
#define Pa pair < int ,int >

using namespace std;

int n, x, y, Use[N];
set < int > S;
map < int , int > ok[N];
vector < int > a[N];
ll ans1 = 0, ans2 = 0;

Pa Get(int u)
{
    for(set < int > :: iterator it = S.begin(); it != S.end(); it++)
        if(ok[u][*it] == 0)
            return mp(x, *it);
    for(int i=0; i<a[u].size(); i++)
        if(Use[a[u][i]] == 0)
            return mp(y, a[u][i]);
}

void DFS(int u)
{
    Use[u] = 1;
    for(int i=0; i<a[u].size(); i++)
    {
        int v = a[u][i];
        if(Use[v])  continue;
        ans2 += y;
        DFS(v);
        return;
    }
}

int main()
{
  //  filein("inp.txt");  fileout("out.txt");
    int u, v;
    cin >> n >> y >> x;
    for(int i=1; i<n; i++)
    {
        cin >> u >> v;
        a[u].push_back(v);
        a[v].push_back(u);
        ok[u][v] = 1;
        ok[v][u] = 1;
    }
    for(int i=2; i<=n; i++)
        S.insert(i);
    Use[1] = 1;
    int top = 1;
    int bot = 1;
    for(int i=2; i<=n; i++)
    {
        Pa P = Get(top);
        Pa Q = Get(bot);
        if(P.f > Q.f)
        {
            bot = Q.s, ans1 += Q.f;
            S.erase(bot);
            Use[bot] = 1;
        }
        else
        {
            top = P.s, ans1 += P.f;
            S.erase(top);
            Use[top] = 1;
        }
    }
    memset(Use, 0, sizeof(Use));
    for(int i=1; i<=n; i++)
        if(a[i].size() == 1 && Use[i] == 0)
        {
            DFS(i);
            ans2 += x;
        }
    ans2 -= x;
    cout << min(ans1, ans2);
}


#include <bits/stdc++.h>
#define filein(t) freopen(t, "r", stdin)
#define fileout(t) freopen(t, "w", stdout)
#define mp make_pair
#define f first
#define s second
#define N 200005
#define NN 10000000
#define BIT(i, j) ((j >> i) & 1)
#define ll long long
#define oo 1000000007
#define ln 1e9+1
#define Pi 3.14159265359
#define Line pair < pair <ll, ll>, ll >
#define pi pair < int, pair <int, int> >
#define Pa pair < int ,int >

using namespace std;

int n, x, y, Use[N];
set < int > S;
map < int , int > ok[N];
vector < int > a[N];
ll ans = 0;

Pa Get(int u)
{
    if(x <= y)
    {
        for(set < int > :: iterator it = S.begin(); it != S.end(); it++)
            if(ok[u][*it] == 0)
                return mp(x, *it);
        for(int i=0; i<a[u].size(); i++)
            if(Use[a[u][i]] == 0)
                return mp(y, a[u][i]);
    }
    for(int i=0; i<a[u].size(); i++)
        if(Use[a[u][i]] == 0)
            return mp(y, a[u][i]);
    for(set < int > :: iterator it = S.begin(); it != S.end(); it++)
        if(ok[u][*it] == 0)
            return mp(x, *it);
}

int main()
{
    ios_base::sync_with_stdio(0);
  //  filein("inp.txt");  fileout("out.txt");
    int u, v;
    cin >> n >> y >> x;
    for(int i=1; i<n; i++)
    {
        cin >> u >> v;
        a[u].push_back(v);
        a[v].push_back(u);
        ok[u][v] = 1;
        ok[v][u] = 1;
    }
    for(int i=2; i<=n; i++)
        S.insert(i);
    Use[1] = 1;
    int top = 1;
    int bot = 1;
    for(int i=2; i<=n; i++)
    {
        Pa P = Get(top);
        Pa Q = Get(bot);
        if(P.f > Q.f)
        {
            bot = Q.s, ans += Q.f;
            S.erase(bot);
            Use[bot] = 1;
        }
        else
        {
            top = P.s, ans += P.f;
            S.erase(top);
            Use[top] = 1;
        }
    }
    cout << ans;
}


#include <iostream>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#define INF 0xfffffff
#define MXN 200010
using namespace std;
typedef long long ll;
int n,x,y;
ll ans;
struct node
{
	int v,last;
}elist[MXN+MXN];
int tote,zh[MXN];
void adde(int u,int v)
{
	elist[++tote].v=v;
	elist[tote].last=zh[u];
	zh[u]=tote;
}
int d[MXN];
int xl[MXN],dfn[MXN],tot;
void dfs(int u)
{
	dfn[u]=++tot;
	xl[tot]=u;
	for (int i=zh[u];i;i=elist[i].last)
	{
		int v=elist[i].v;
		if (!dfn[v])
			dfs(v);
	}
}
/*/*f[i][1]= sigma (f[ch][0])+1
           sigma(f[ch][0])|ch!=i  + f[i][1];
f[i][0] = min(f[i][1], f[i][1]+f[j][1]+sigma(f[other ch][0]);
dfs��dp

f[leaf][0][1]=1;
O(n)
��¼��sum
�м���f[][1]��f[][0]���
*/
int f[MXN][2];
void solve()//1�Ǹ�
{
	for (int i=n;i>=1;i--)
	{
		int u=xl[i],cnt=0,sum=0;
		bool flag=0;
		for (int j=zh[u];j;j=elist[j].last)
		{
			int v=elist[j].v;
			if (dfn[v]>dfn[u])
			{
				flag=1;
				sum+=f[v][0];
				if (f[v][1]==f[v][0])
					cnt++;
			}
			/*f[i][1]= sigma (f[ch][0])+1
           sigma(f[ch][0])|ch!=i  + f[i][1];
f[i][0] = min(f[i][1], f[i][1]+f[j][1]+sigma(f[other ch][0]-1);*/
		}
		if (cnt>=1)	f[u][1]=sum;
		else	f[u][1]=sum+1;
		if (cnt>=2)	f[u][0]=sum-1;
		else if (cnt==1)
			f[u][0]=sum;
		else
			f[u][0]=sum+1;
	}
	ans=1ll*(f[1][0]-1)*y+1ll*(n-f[1][0])*x;
}
int main ()
{
//	freopen("D.in","r",stdin);
//	freopen("D.out","w",stdout);
	int m;
	scanf("%d%d%d",&n,&x,&y);
	memset(d,0,sizeof(d));m=0;
	memset(zh,0,sizeof(zh));tote=0;
	for (int i=1;i<n;i++)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		d[a]++;d[b]++;
		adde(a,b);adde(b,a);
	}
	for (int i=1;i<=n;i++)
		if (d[i]==1)
			m++;
	if (x<y||x==y)
	{
		memset(dfn,0,sizeof(dfn));tot=0;
		dfs(1);
		solve();
	}
	else
	{
		if (m>=n-1)
			ans=1ll*x+1ll*(n-2)*y;
		else
			ans=1ll*(n-1)*y;
	}
	printf("%I64d",ans);
//	fclose(stdin);fclose(stdout);
	return 0;
}


#include <iostream>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#define INF 0xfffffff
#define MXN 200010
using namespace std;
typedef long long ll;
int d[MXN];
int main ()
{
//	freopen("D.in","r",stdin);
//	freopen("D.out","w",stdout);
	int n,m,x,y;
	ll ans;
	scanf("%d%d%d",&n,&x,&y);
	memset(d,0,sizeof(d));m=0;
	for (int i=1;i<=n;i++)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		d[a]++;
		d[b]++;
	}
	for (int i=1;i<=n;i++)
	{
		d[i]/=2;
		if (d[i]==1)
			m++;
	}
	if (x<y||x==y)
		ans=1ll*(m-1)*y+1ll*(n-m)*x;
	else
	{
		if (m==n-1)
			ans=1ll*x+1ll*(n-2)*y;
		else
			ans=1ll*(n-1)*y;
	}
	printf("%I64d",ans);
//	fclose(stdin);fclose(stdout);
	return 0;
}


#include <iostream>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#define INF 0xfffffff
#define MXN 200010
using namespace std;
int d[MXN];
int main ()
{
//	freopen("D.in","r",stdin);
//	freopen("D.out","w",stdout);
	int n,m,x,y,ans;
	scanf("%d%d%d",&n,&x,&y);
	memset(d,0,sizeof(d));m=0;
	for (int i=1;i<=n;i++)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		d[a]++;
		d[b]++;
	}
	for (int i=1;i<=n;i++)
	{
		d[i]/=2;
		if (d[i]==1)
			m++;
	}
	if (x<y||x==y)
		ans=(m-1)*y+(n-m)*x;
	else
	{
		if (m==n-1)
			ans=x+(n-2)*y;
		else
			ans=(n-1)*y;
	}
	printf("%d",ans);
//	fclose(stdin);fclose(stdout);
	return 0;
}


#include <iostream>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#define INF 0xfffffff
#define MXN 200010
using namespace std;
typedef long long ll;
struct node
{
	int v,last;
}elist[MXN+MXN];
int tote,zh[MXN];
void adde(int u,int v)
{
	elist[++tote].v=v;
	elist[tote].last=zh[u];
	zh[u]=tote;
}
int tot;
bool vis[MXN],tag[MXN];
void dfs(int u)
{
	vis[u]=1;
	int cnt=0;
	for (int i=zh[u];i;i=elist[i].last)
	{
		int v=elist[i].v;
		if (!vis[v])
		{
			dfs(v);
			if (tag[v]==1)
				cnt++;
		}
	}
	if (cnt==0)
		tag[u]=1;
	else if (cnt==1)
	{
		tag[u]=1;
		tot++;
	}
	else
	{
		tag[u]=0;
		tot+=2;
	}
}
int d[MXN];
int main ()
{
//	freopen("D.in","r",stdin);
//	freopen("D.out","w",stdout);
	int n,m,x,y;
	ll ans;
	scanf("%d%d%d",&n,&x,&y);
	memset(d,0,sizeof(d));m=0;
	memset(zh,0,sizeof(zh));tote=0;
	for (int i=1;i<n;i++)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		d[a]++;d[b]++;
		adde(a,b);adde(b,a);
	}
	for (int i=1;i<=n;i++)
		if (d[i]==1)
			m++;
	if (x<y||x==y)
	{
		tot=0;
		memset(vis,0,sizeof(vis));
		memset(tag,0,sizeof(tag));
		dfs(1);
		ans=1ll*tot*x+1ll*(n-1-tot)*y;
	}
	else
	{
		if (m>=n-1)
			ans=1ll*x+1ll*(n-2)*y;
		else
			ans=1ll*(n-1)*y;
	}
	printf("%I64d",ans);
//	fclose(stdin);fclose(stdout);
	return 0;
}


#include <iostream>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#define INF 0xfffffff
#define MXN 200010
using namespace std;
typedef long long ll;
int d[MXN];
int main ()
{
//	freopen("D.in","r",stdin);
	//freopen("D.out","w",stdout);
	int n,m,x,y;
	ll ans;
	scanf("%d%d%d",&n,&x,&y);
	memset(d,0,sizeof(d));m=0;
	for (int i=1;i<n;i++)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		d[a]++;
		d[b]++;
		//cout<<a<<" "<<b<<" "<<d[a]<<" "<<d[b]<<endl;
	}
	for (int i=1;i<=n;i++)
	{
		//cout<<d[i]<<" ";
		if (d[i]==1)
			m++;
	}
	//cout<<m<<endl;
	if (x<y||x==y)
		ans=1ll*(m-2)*y+1ll*(n-m+1)*x;
	else
	{
		if (m==n-1)
			ans=1ll*x+1ll*(n-2)*y;
		else
			ans=1ll*(n-1)*y;
	}
	printf("%I64d",ans);
//	fclose(stdin);fclose(stdout);
	return 0;
}


#include <iostream>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#define INF 0xfffffff
#define MXN 200010
using namespace std;
typedef long long ll;
struct node
{
	int v,last;
}elist[MXN+MXN];
int tote,zh[MXN];
void adde(int u,int v)
{
	elist[++tote].v=v;
	elist[tote].last=zh[u];
	zh[u]=tote;
}
int tot;
bool vis[MXN],tag[MXN];
void dfs(int u)
{
	vis[u]=1;
	int cnt=0;
	for (int i=zh[u];i;i=elist[i].last)
	{
		int v=elist[i].v;
		if (!vis[v])
		{
			dfs(v);
			if (tag[v]==1)
				cnt++;
		}
	}
	if (cnt==0)
		tag[u]=1;
	else if (cnt==1)
	{
		tag[u]=1;
		tot++;
	}
	else
	{
		tag[u]=0;
		tot+=2;
	}
}
int d[MXN];
int main ()
{
	freopen("D.in","r",stdin);
	freopen("D.out","w",stdout);
	int n,m,x,y;
	ll ans;
	scanf("%d%d%d",&n,&x,&y);
	memset(d,0,sizeof(d));m=0;
	memset(zh,0,sizeof(zh));tote=0;
	for (int i=1;i<n;i++)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		d[a]++;d[b]++;
		adde(a,b);adde(b,a);
	}
	for (int i=1;i<=n;i++)
		if (d[i]==1)
			m++;
	if (x<y||x==y)
	{
		tot=0;
		memset(vis,0,sizeof(vis));
		memset(tag,0,sizeof(tag));
		dfs(1);
		ans=1ll*tot*x+1ll*(n-1-tot)*y;
	}
	else
	{
		if (m>=n-1)
			ans=1ll*x+1ll*(n-2)*y;
		else
			ans=1ll*(n-1)*y;
	}
	printf("%I64d",ans);
//	fclose(stdin);fclose(stdout);
	return 0;
}


#include <iostream>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#define INF 0xfffffff
#define MXN 200010
using namespace std;
typedef long long ll;
int d[MXN];
int main ()
{
	freopen("D.in","r",stdin);
	freopen("D.out","w",stdout);
	int n,m,x,y;
	ll ans;
	scanf("%d%d%d",&n,&x,&y);
	memset(d,0,sizeof(d));m=0;
	for (int i=1;i<n;i++)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		d[a]++;
		d[b]++;
		//cout<<a<<" "<<b<<" "<<d[a]<<" "<<d[b]<<endl;
	}
	for (int i=1;i<=n;i++)
	{
		//cout<<d[i]<<" ";
		if (d[i]==1)
			m++;
	}
	//cout<<m<<endl;
	if (x<y||x==y)
		ans=1ll*(m-2)*y+1ll*(n-m+1)*x;
	else
	{
		if (m==n-1)
			ans=1ll*x+1ll*(n-2)*y;
		else
			ans=1ll*(n-1)*y;
	}
	printf("%I64d",ans);
//	fclose(stdin);fclose(stdout);
	return 0;
}


#include <iostream>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#define INF 0xfffffff
#define MXN 200010
using namespace std;
typedef long long ll;
struct node
{
	int v,last;
}elist[MXN+MXN];
int tote,zh[MXN];
void adde(int u,int v)
{
	elist[++tote].v=v;
	elist[tote].last=zh[u];
	zh[u]=tote;
}
int tot;
bool vis[MXN],tag[MXN];
void dfs(int u)
{
	vis[u]=1;
	int cnt=0;
	for (int i=zh[u];i;i=elist[i].last)
	{
		int v=elist[i].v;
		if (!vis[v])
		{
			dfs(v);
			if (tag[v]==1)
				cnt++;
		}
	}
	if (cnt==0)
		tag[u]=1;
	else if (cnt==1)
	{
		tag[u]=1;
		tot++;
	}
	else
	{
		tag[u]=0;
		tot+=2;
	}
}
int d[MXN];
int main ()
{
//	freopen("D.in","r",stdin);
//	freopen("D.out","w",stdout);
	int n,m,x,y;
	ll ans;
	scanf("%d%d%d",&n,&x,&y);
	memset(d,0,sizeof(d));m=0;
	memset(zh,0,sizeof(zh));tote=0;
	for (int i=1;i<n;i++)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		d[a]++;d[b]++;
		adde(a,b);adde(b,a);
	}
	for (int i=1;i<=n;i++)
		if (d[i]==1)
			m++;
	if (x<y||x==y)
	{
		tot=0;
		memset(vis,0,sizeof(vis));
		memset(tag,0,sizeof(tag));
		dfs(1);
		ans=1ll*tot*x+1ll*(n-1-tot)*y;
	}
	else
	{
		if (m==n-1)
			ans=1ll*x+1ll*(n-2)*y;
		else
			ans=1ll*(n-1)*y;
	}
	printf("%I64d",ans);
//	fclose(stdin);fclose(stdout);
	return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<string.h>
#include<vector>
using namespace std;
#define LL __int64
#define N 200010
vector<int >g[N];
int vis[N];
int num[N];
struct node
{
    int u,len;
};
int bfs(int u)
{
    int i;
    queue<int>q;
    q.push(u);
    memset(vis,0,sizeof(vis));
    vis[u]=1;
    while(!q.empty()){
        u=q.front();
        q.pop();
        for(i=0;i<(int)g[u].size();++i){
            if(!vis[g[u][i]]){
                vis[g[u][i]]=1;
                q.push(g[u][i]);
            }
        }
    }
    return u;
}
int bfs_len(int u)
{
    int i;
    queue<node>q;
    node cur,next;
    cur.u=u;
    cur.len=1;
    q.push(cur);
    memset(vis,0,sizeof(vis));
    vis[u]=1;
    while(!q.empty()){
        cur=q.front();
        q.pop();
        for(i=0;i<(int)g[cur.u].size();++i){
            u=g[cur.u][i];
            if(!vis[u]){
                vis[u]=1;
                next.u=u;
                next.len=cur.len+1;
                q.push(next);
            }
        }
    }
    return cur.len;
}
int main()
{
    int i,t,n,a,b;
    LL x,y,ans;
    while(~scanf("%d",&n)){
        cin>>x>>y;
        for(i=0;i<=n;++i){
            g[i].clear();
            num[i]=0;
        }
        for(i=1;i<n;++i){
            scanf("%d%d",&a,&b);
            g[a].push_back(b);
            g[b].push_back(a);
            ++num[a];
            ++num[b];
        }
        if(x>=y){
            int cnt=0;
            for(i=1;i<=n;++i){
                if(num[i]==n-1){
                    ++cnt;
                }
            }
            if(cnt>=1)
                ans=(n-2)*y+x;
            else
                ans=(n-1)*y;
        }
        else{
            a=bfs(1);
            t=bfs_len(a);
           // cout<<a<<t<<endl;
            ans=(t-1)*x+(n-t)*y;
        }
        printf("%I64d\n",ans);
        puts("");
    }
    return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<string.h>
#include<vector>
using namespace std;
#define LL __int64
#define N 200010
vector<int >g[N];
int vis[N];
struct node
{
    int u,len;
};
int bfs(int u)
{
    int i;
    queue<int>q;
    q.push(u);
    memset(vis,0,sizeof(vis));
    vis[u]=1;
    while(!q.empty()){
        u=q.front();
        q.pop();
        for(i=0;i<g[u].size();++i){
            if(!vis[g[u][i]]){
                vis[g[u][i]]=1;
                q.push(g[u][i]);
            }
        }
    }
    return u;
}
int bfs_len(int u)
{
    int i;
    queue<node>q;
    node cur,next;
    cur.u=u;
    cur.len=1;
    q.push(cur);
    memset(vis,0,sizeof(vis));
    vis[u]=1;
    while(!q.empty()){
        cur=q.front();
        q.pop();
        for(i=0;i<g[cur.u].size();++i){
            u=g[cur.u][i];
            if(!vis[u]){
                vis[u]=1;
                next.u=u;
                next.len=cur.len+1;
                q.push(next);
            }
        }
    }
    return cur.len;
}
int main()
{
    int i,t,n;
    int x,y,a,b;
    LL ans;
    while(~scanf("%d%d%d",&n,&x,&y)){
        for(i=0;i<=n;++i){
            g[i].clear();
        }
        for(i=1;i<n;++i){
            scanf("%d%d",&a,&b);
            g[a].push_back(b);
            g[b].push_back(a);
        }
        if(x>=y){
            ans=(n-1)*y;
        }
        else{
            a=bfs(1);
            t=bfs_len(a);
           // cout<<a<<t<<endl;
            ans=(t-1)*x+(n-t)*y;
        }
        printf("%lld\n",ans);
        puts("");
    }
    return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<string.h>
#include<vector>
using namespace std;
#define LL __int64
#define N 200010
vector<int >g[N];
int vis[N];
int num[N];
struct node
{
    int u,len;
};
int bfs(int u)
{
    int i;
    queue<int>q;
    q.push(u);
    memset(vis,0,sizeof(vis));
    vis[u]=1;
    while(!q.empty()){
        u=q.front();
        q.pop();
        for(i=0;i<(int)g[u].size();++i){
            if(!vis[g[u][i]]){
                vis[g[u][i]]=1;
                q.push(g[u][i]);
            }
        }
    }
    return u;
}
int bfs_len(int u)
{
    int i,ans=1;
    queue<node>q;
    node cur,next;
    cur.u=u;
    cur.len=1;
    q.push(cur);
    memset(vis,0,sizeof(vis));
    vis[u]=1;
    while(!q.empty()){
        cur=q.front();
        q.pop();
        ans=max(ans,cur.len);
        for(i=0;i<(int)g[cur.u].size();++i){
            u=g[cur.u][i];
            if(!vis[u]){
                vis[u]=1;
                next.u=u;
                next.len=cur.len+1;
                q.push(next);
            }
        }
    }
    return ans;
}
int main()
{
    int i,t,n,a,b;
    LL x,y,ans,right,wrong;
    /*n=200000 ;
    x=999999999;
    y=1000000000;
    right=199998999997956;
    wrong=199998999999994;
    for(i=1;i<N;++i){
        ans=x*i+y*(n-i-1);
        if(ans==right)
        {
            printf("right i=%d \n",i);
        }
        if(ans==wrong)
        {
            printf("wrong i=%d\n ",i);
        }
    }*/
    while(~scanf("%d",&n)){
        cin>>x>>y;
        for(i=1;i<=n;++i){
            g[i].clear();
            num[i]=0;
        }
        for(i=1;i<n;++i){
            scanf("%d%d",&a,&b);
            g[a].push_back(b);
            g[b].push_back(a);
            ++num[a];
            ++num[b];
        }
        if(x>=y){
            int cnt=0;
            for(i=1;i<=n;++i){
                if(num[i]==n-1){
                    ++cnt;
                }
            }
            if(cnt>=1)
                ans=(n-2)*y+x;
            else
                ans=(n-1)*y;
        }
        else{
            a=bfs(1);
            t=bfs_len(a);
           // cout<<a<<t<<endl;
            ans=(t-1)*x+(n-t)*y;
        }
        if(n==200000)
            cout<<t<<endl;
        printf("%I64d\n",ans);
    }
    return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<string.h>
#include<vector>
using namespace std;
#define LL __int64
#define N 200010
vector<int >g[N];
int vis[N];
int num[N];
struct node
{
    int u,len;
};
int bfs(int u)
{
    int i;
    queue<int>q;
    q.push(u);
    memset(vis,0,sizeof(vis));
    vis[u]=1;
    while(!q.empty()){
        u=q.front();
        q.pop();
        for(i=0;i<(int)g[u].size();++i){
            if(!vis[g[u][i]]){
                vis[g[u][i]]=1;
                q.push(g[u][i]);
            }
        }
    }
    return u;
}
int bfs_len(int u)
{
    int i;
    queue<node>q;
    node cur,next;
    cur.u=u;
    cur.len=1;
    q.push(cur);
    memset(vis,0,sizeof(vis));
    vis[u]=1;
    while(!q.empty()){
        cur=q.front();
        q.pop();
        for(i=0;i<(int)g[cur.u].size();++i){
            u=g[cur.u][i];
            if(!vis[u]){
                vis[u]=1;
                next.u=u;
                next.len=cur.len+1;
                q.push(next);
            }
        }
    }
    return cur.len;
}
int main()
{
    int i,t,n,a,b;
    LL x,y,ans,right,wrong;
    /*n=200000 ;
    x=999999999;
    y=1000000000;
    right=199998999997956;
    wrong=199998999999994;
    for(i=1;i<N;++i){
        ans=x*i+y*(n-i-1);
        if(ans==right)
        {
            printf("right i=%d \n",i);
        }
        if(ans==wrong)
        {
            printf("wrong i=%d\n ",i);
        }
    }*/
    while(~scanf("%d",&n)){
        cin>>x>>y;
        for(i=1;i<=n;++i){
            g[i].clear();
            num[i]=0;
        }
        for(i=1;i<n;++i){
            scanf("%d%d",&a,&b);
            g[a].push_back(b);
            g[b].push_back(a);
            ++num[a];
            ++num[b];
        }
        if(x>=y){
            int cnt=0;
            for(i=1;i<=n;++i){
                if(num[i]==n-1){
                    ++cnt;
                }
            }
            if(cnt>=1)
                ans=(n-2)*y+x;
            else
                ans=(n-1)*y;
        }
        else{
            a=bfs(1);
            t=bfs_len(a);
           // cout<<a<<t<<endl;
            ans=(t-1)*x+(n-t)*y;
        }
        if(n==200000)
            cout<<t<<endl;
        printf("%I64d\n",ans);
    }
    return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<string.h>
#include<vector>
using namespace std;
#define LL __int64
#define N 200010
vector<int >g[N];
int num[N];
int vis[N];
int cnt;
int dfs(int u)
{
    int i,t=0;
    vis[u]=1;
    for(i=0;i<(int)g[u].size();++i){
        if(!vis[g[u][i]]){
            t+=dfs(g[u][i]);
        }
    }
    if(t<=1){
        cnt+=t;
        return 1;
    }
    if(t>=2){
        cnt+=2;
        return 0;
    }
}
int main()
{
    int i,a,b,n;
    LL x,y,ans;
    while(~scanf("%d",&n)){
        cin>>x>>y;
        for(i=1;i<=n;++i){
            g[i].clear();
        }
        memset(num,0,sizeof(num));
        for(i=1;i<n;++i){
            scanf("%d%d",&a,&b);
            g[a].push_back(b);
            g[b].push_back(a);
            ++num[a];
            ++num[b];
        }
        if(x>=y){
            int t=0;
            for(i=1;i<=n;++i){
                if(num[i]==n-1){
                    t=1;
                    break;
                }
            }
            if(t==1)
                ans=x+(n-2)*y;
            else
                ans=(n-1)*y;
        }
        else{
            cnt=0;
            memset(vis,0,sizeof(vis));
            dfs(1);
            ans=cnt*x+(n-cnt-1)*y;
        }
        cout<<ans<<endl;
    }
    return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<string.h>
#include<vector>
using namespace std;
#define LL __int64
#define N 200010
vector<int >g[N];
int vis[N];
int num[N];
struct node
{
    int u,len;
};
int bfs(int u)
{
    int i;
    queue<int>q;
    q.push(u);
    memset(vis,0,sizeof(vis));
    vis[u]=1;
    while(!q.empty()){
        u=q.front();
        q.pop();
        for(i=0;i<(int)g[u].size();++i){
            if(!vis[g[u][i]]){
                vis[g[u][i]]=1;
                q.push(g[u][i]);
            }
        }
    }
    return u;
}
int bfs_len(int u)
{
    int i,ans=1;
    queue<node>q;
    node cur,next;
    cur.u=u;
    cur.len=1;
    q.push(cur);
    memset(vis,0,sizeof(vis));
    vis[u]=1;
    while(!q.empty()){
        cur=q.front();
        q.pop();
        ans=max(ans,cur.len);
        for(i=0;i<(int)g[cur.u].size();++i){
            u=g[cur.u][i];
            if(!vis[u]){
                vis[u]=1;
                next.u=u;
                next.len=cur.len+1;
                q.push(next);
            }
        }
    }
    return ans;
}
int main()
{
    int i,t,n,a,b;
    LL x,y,ans,right,wrong;
    /*n=200000 ;
    x=999999999;
    y=1000000000;
    right=199998999997956;
    wrong=199998999999994;
    for(i=1;i<N;++i){
        ans=x*i+y*(n-i-1);
        if(ans==right)
        {
            printf("right i=%d \n",i);
        }
        if(ans==wrong)
        {
            printf("wrong i=%d\n ",i);
        }
    }*/
    while(~scanf("%d",&n)){
        cin>>x>>y;
        for(i=1;i<=n;++i){
            g[i].clear();
            num[i]=0;
        }
        for(i=1;i<n;++i){
            scanf("%d%d",&a,&b);
            g[a].push_back(b);
            g[b].push_back(a);
            ++num[a];
            ++num[b];
        }
        if(x>=y){
            int cnt=0;
            for(i=1;i<=n;++i){
                if(num[i]==n-1){
                    ++cnt;
                }
            }
            if(cnt>=1)
                ans=(n-2)*y+x;
            else
                ans=(n-1)*y;
        }
        else{
            a=bfs(1);
            t=bfs_len(a);
           // cout<<a<<t<<endl;
            ans=(t-1)*x+(n-t)*y;
        }
        //if(n==200000)
          //  cout<<t<<endl;
        printf("%I64d\n",ans);
    }
    return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<string.h>
#include<vector>
using namespace std;
#define LL __int64
#define N 200010
vector<int >g[N];
int vis[N];
int num[N];
int cnt;
struct node
{
    int u,len;
};

int dfs(int u)
{
    int i,v,t=0;
    for(i=0;i<(int)g[u].size();++i){
        v=g[u][i];
        if(!vis[v]){
            vis[v]=1;
            t+=dfs(v);
        }
    }
    //printf("u=%d child=%d cnt=%d\n",u,t,cnt);
    if(t==0)
        return 1;
    if(t==1){
        ++cnt;
        printf("u=%d child=%d cnt=%d\n",u,t,cnt);
        return 1;
    }
    if(t>=2){
        cnt+=2;
        printf("u=%d child=%d cnt=%d\n",u,t,cnt);
        return 0;
    }
}
int main()
{
    int i,n,a,b;
    LL x,y,ans;
    while(~scanf("%d",&n)){
        cin>>x>>y;
        for(i=1;i<=n;++i){
            g[i].clear();
            num[i]=0;
        }
        for(i=1;i<n;++i){
            scanf("%d%d",&a,&b);
            g[a].push_back(b);
            g[b].push_back(a);
            ++num[a];
            ++num[b];
        }
        if(x>=y){            //star graph
            int cnt=0;
            for(i=1;i<=n;++i){
                if(num[i]==n-1){
                    break;
                    cnt=1;
                }
            }
            if(cnt==1)
                ans=(n-2)*y+x;
            else
                ans=(n-1)*y;
        }
        else{
            memset(vis,0,sizeof(vis));
            vis[1]=1;
            cnt=0;
            dfs(1);
           // cout<<a<<t<<endl;
            ans=(n-1-cnt)*y+cnt*x;
            cout<<"cnt= "<<cnt<<endl;
        }
        printf("%I64d\n",ans);
    }
    return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<string.h>
#include<vector>
using namespace std;
#define LL __int64
#define N 200010
vector<int >g[N];
int vis[N];
int num[N];
int cnt;
struct node
{
    int u,len;
};

int dfs(int u)
{
    int i,v,t=0;
    for(i=0;i<(int)g[u].size();++i){
        v=g[u][i];
        if(!vis[v]){
            vis[v]=1;
            t+=dfs(v);
        }
    }
    //printf("u=%d child=%d cnt=%d\n",u,t,cnt);
    if(t==0)
        return 1;
    if(t==1){
        ++cnt;
       // printf("u=%d child=%d cnt=%d\n",u,t,cnt);
        return 1;
    }
    if(t>=2){
        cnt+=2;
       // printf("u=%d child=%d cnt=%d\n",u,t,cnt);
        return 0;
    }
}
int main()
{
    int i,n,a,b;
    LL x,y,ans;
   // LL Ans=1999880002,wrong=1999790001;

    while(~scanf("%d",&n)){
        cin>>x>>y;
       /* for(i=1;i<=n;++i){
            LL t=i*x+y*(n-1-i);
            if(t==Ans){
                printf("Ans  i=%d\n",i);
            }
            if(t==wrong){
                printf("wrong =%d\n",i);
            }
        }*/
        for(i=1;i<=n;++i){
            g[i].clear();
            num[i]=0;
        }
        for(i=1;i<n;++i){
            scanf("%d%d",&a,&b);
            g[a].push_back(b);
            g[b].push_back(a);
            ++num[a];
            ++num[b];
        }
        if(x>=y){            //star graph
            int cnt=0;
            for(i=1;i<=n;++i){
                if(num[i]==n-1){
                    cnt=1;
                    break;
                }
            }
            if(cnt==1)
                ans=(n-2)*y+x;
            else
                ans=(n-1)*y;
        }
        else{
            memset(vis,0,sizeof(vis));
            vis[1]=1;
            cnt=0;
            dfs(1);
           // cout<<a<<t<<endl;
            ans=(n-1-cnt)*y+cnt*x;
            //cout<<"cnt= "<<cnt<<endl;
        }
        printf("%I64d\n",ans);
    }
    return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<string.h>
#include<vector>
using namespace std;
#define LL __int64
#define N 200010
vector<int >g[N];
int vis[N];
int num[N];
struct node
{
    int u,len;
};
int bfs(int u)
{
    int i;
    queue<int>q;
    q.push(u);
    memset(vis,0,sizeof(vis));
    vis[u]=1;
    while(!q.empty()){
        u=q.front();
        q.pop();
        for(i=0;i<g[u].size();++i){
            if(!vis[g[u][i]]){
                vis[g[u][i]]=1;
                q.push(g[u][i]);
            }
        }
    }
    return u;
}
int bfs_len(int u)
{
    int i;
    queue<node>q;
    node cur,next;
    cur.u=u;
    cur.len=1;
    q.push(cur);
    memset(vis,0,sizeof(vis));
    vis[u]=1;
    while(!q.empty()){
        cur=q.front();
        q.pop();
        for(i=0;i<g[cur.u].size();++i){
            u=g[cur.u][i];
            if(!vis[u]){
                vis[u]=1;
                next.u=u;
                next.len=cur.len+1;
                q.push(next);
            }
        }
    }
    return cur.len;
}
int main()
{
    int i,t,n;
    int x,y,a,b;
    LL ans;
    while(~scanf("%d%d%d",&n,&x,&y)){
        for(i=0;i<=n;++i){
            g[i].clear();
            num[i]=0;
        }
        for(i=1;i<n;++i){
            scanf("%d%d",&a,&b);
            g[a].push_back(b);
            g[b].push_back(a);
            ++num[a];
            ++num[b];
        }
        if(x>=y){
            int cnt=0;
            for(i=1;i<=n;++i){
                if(num[i]==n-1){
                    ++cnt;
                }
            }
            if(cnt>=1)
                ans=(n-2)*y+x;
            else
                ans=(n-1)*y;
        }
        else{
            a=bfs(1);
            t=bfs_len(a);
           // cout<<a<<t<<endl;
            ans=(t-1)*x+(n-t)*y;
        }
        printf("%lld\n",ans);
        puts("");
    }
    return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<string.h>
#include<vector>
using namespace std;
#define LL __int64
#define N 200010
vector<int >g[N];
int vis[N];
int num[N];
int cnt;
struct node
{
    int u,len;
};

int dfs(int u)
{
    int i,v,t=0;
    for(i=0;i<(int)g[u].size();++i){
        v=g[u][i];
        if(!vis[v]){
            vis[v]=1;
            t+=dfs(v);
        }
    }
    //printf("u=%d child=%d cnt=%d\n",u,t,cnt);
    if(t==0)
        return 1;
    if(t==1){
        ++cnt;
       // printf("u=%d child=%d cnt=%d\n",u,t,cnt);
        return 1;
    }
    if(t>=2){
        cnt+=2;
       // printf("u=%d child=%d cnt=%d\n",u,t,cnt);
        return 0;
    }
}
int main()
{
    int i,n,a,b;
    LL x,y,ans;
    while(~scanf("%d",&n)){
        cin>>x>>y;
        for(i=1;i<=n;++i){
            g[i].clear();
            num[i]=0;
        }
        for(i=1;i<n;++i){
            scanf("%d%d",&a,&b);
            g[a].push_back(b);
            g[b].push_back(a);
            ++num[a];
            ++num[b];
        }
        if(x>=y){            //star graph
            int cnt=0;
            for(i=1;i<=n;++i){
                if(num[i]==n-1){
                    break;
                    cnt=1;
                }
            }
            if(cnt==1)
                ans=(n-2)*y+x;
            else
                ans=(n-1)*y;
        }
        else{
            memset(vis,0,sizeof(vis));
            vis[1]=1;
            cnt=0;
            dfs(1);
           // cout<<a<<t<<endl;
            ans=(n-1-cnt)*y+cnt*x;
            //cout<<"cnt= "<<cnt<<endl;
        }
        printf("%I64d\n",ans);
    }
    return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<string.h>
#include<vector>
using namespace std;
#define LL __int64
#define N 200010
vector<int >g[N];
int vis[N];
int num[N];
struct node
{
    int u,len;
};
int bfs(int u)
{
    int i;
    queue<int>q;
    q.push(u);
    memset(vis,0,sizeof(vis));
    vis[u]=1;
    while(!q.empty()){
        u=q.front();
        q.pop();
        for(i=0;i<(int)g[u].size();++i){
            if(!vis[g[u][i]]){
                vis[g[u][i]]=1;
                q.push(g[u][i]);
            }
        }
    }
    return u;
}
int bfs_len(int u)
{
    int i;
    queue<node>q;
    node cur,next;
    cur.u=u;
    cur.len=1;
    q.push(cur);
    memset(vis,0,sizeof(vis));
    vis[u]=1;
    while(!q.empty()){
        cur=q.front();
        q.pop();
        for(i=0;i<(int)g[cur.u].size();++i){
            u=g[cur.u][i];
            if(!vis[u]){
                vis[u]=1;
                next.u=u;
                next.len=cur.len+1;
                q.push(next);
            }
        }
    }
    return cur.len;
}
int main()
{
    int i,t,n,a,b;
    LL x,y,ans;
    while(~scanf("%d",&n)){
        cin>>x>>y;
        for(i=1;i<=n;++i){
            g[i].clear();
            num[i]=0;
        }
        for(i=1;i<n;++i){
            scanf("%d%d",&a,&b);
            g[a].push_back(b);
            g[b].push_back(a);
            ++num[a];
            ++num[b];
        }
        if(x>=y){
            int cnt=0;
            for(i=1;i<=n;++i){
                if(num[i]==n-1){
                    ++cnt;
                }
            }
            if(cnt>=1)
                ans=(n-2)*y+x;
            else
                ans=(n-1)*y;
        }
        else{
            a=bfs(1);
            t=bfs_len(a);
           // cout<<a<<t<<endl;
            ans=(t-1)*x+(n-t)*y;
        }
        printf("%I64d\n",ans);
    }
    return 0;
}


// Shalin
#include <bits/stdc++.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
using namespace std;
#define si(x) scanf("%d",&x)
#define slli(x) scanf("%lld",&x);
#define sc(x) scanf("%c",&x);
#define ss(x) scanf("%s",x);
#define sd(x) scanf("%lf",&x);
#define bitcount __builtin_popcount
#define gcd __gcd
#define llu long long unsigned int
#define lli long long int
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define mp make_pair
#define vi vector<int>
#define vlli vector<long long int>
#define pii pair<int,int>
lli maxi=-1;
vector<bool> visited(200010,0);
vector<lli> cnt(200010,0);
vector<lli> adj[200010];
void dfs(lli src,lli dep)
{
    maxi=max(maxi,dep);
    visited[src]=1;
    lli len=adj[src].size();
    for(lli i=0;i<len;i++)
    {
        if(visited[adj[src][i]]==0)
            dfs(adj[src][i],dep+1);
    }

}
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    lli n,x,y;
    slli(n);slli(x);slli(y);
    lli src=-1;
    int i;
    for(i=0;i<n-1;i++)
    {
        lli u,v;slli(u);slli(v);
        adj[u].pb(v);
        adj[v].pb(u);
        cnt[v]++;
        cnt[u]++;
    }
    if(x<y)
    {
        for(i=1;i<=n;i++)
        {
            if(cnt[i]==1)
            {
                src=i;
                break;
            }
        }
        dfs(src,1);
        lli depth=maxi;
        depth--;
     //   cout<<"dp : "<<depth<<endl;
        lli ans=x*(depth)+y*(n-1-depth);
        cout<<ans<<endl;
    }
    else if(x==y)
    {
        lli ans=(n-1)*x;
        cout<<ans<<endl;
    }
    else
    {
        lli flag=0;
        for(i=1;i<=n;i++)
        {
            if(cnt[i]==n-1)
            {
                flag=1;
                break;
            }
        }
        lli ans;
        if(flag)
        {
            ans=x+(n-2)*y;
        }
        else
        {
            ans=(n-1)*y;
        }
        cout<<ans<<endl;
    }
    return 0;
}


// Shalin
#include <bits/stdc++.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
using namespace std;
#define si(x) scanf("%d",&x)
#define slli(x) scanf("%lld",&x);
#define sc(x) scanf("%c",&x);
#define ss(x) scanf("%s",x);
#define sd(x) scanf("%lf",&x);
#define bitcount __builtin_popcount
#define gcd __gcd
#define llu long long unsigned int
#define lli long long int
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define mp make_pair
#define vi vector<int>
#define vlli vector<long long int>
#define pii pair<int,int>
lli maxi=-1;
vector<bool> visited(200010,0);
vector<lli> cnt(200010,0);
vector<lli> adj[200010];
void dfs(lli src,lli dep)
{
    maxi=max(maxi,dep);
    visited[src]=1;
    lli len=adj[src].size();
    for(lli i=0;i<len;i++)
    {
        if(visited[adj[src][i]]==0)
            dfs(adj[src][i],dep+1);
    }

}
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    lli n,x,y;
    slli(n);slli(x);slli(y);
    lli src=-1;
    int i;
    for(i=0;i<n-1;i++)
    {
        lli u,v;slli(u);slli(v);
        adj[u].pb(v);
        adj[v].pb(u);
        cnt[v]++;
        if(src==-1)
        {
            src=v;
        }
        cnt[u]++;
    }
    if(x<y)
    {
        dfs(src,1);
        lli depth=maxi;
        depth--;
     //   cout<<"dp : "<<depth<<endl;
        lli ans=x*(depth)+y*(n-1-depth);
        cout<<ans<<endl;
    }
    else if(x==y)
    {
        lli ans=(n-1)*x;
        cout<<ans<<endl;
    }
    else
    {
        lli flag=0;
        for(i=1;i<=n;i++)
        {
            if(cnt[i]==n-1)
            {
                flag=1;
                break;
            }
        }
        lli ans;
        if(flag)
        {
            ans=x+(n-2)*y;
        }
        else
        {
            ans=(n-1)*y;
        }
        cout<<ans<<endl;
    }
    return 0;
}


// Shalin
#include <bits/stdc++.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
using namespace std;
#define si(x) scanf("%d",&x)
#define slli(x) scanf("%lld",&x);
#define sc(x) scanf("%c",&x);
#define ss(x) scanf("%s",x);
#define sd(x) scanf("%lf",&x);
#define bitcount __builtin_popcount
#define gcd __gcd
#define llu long long unsigned int
#define lli long long int
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define mp make_pair
#define vi vector<int>
#define vlli vector<long long int>
#define pii pair<int,int>
lli maxi=-1,maxindex;
bool visited[200010];
vector<lli> cnt(200010,0);
vector<lli> adj[200010];
int depth=0;
bool dp[200010];
void init()
{
    lli i,j,k;
    for(i=0;i<=200000;i++)
    {
        visited[i]=0;
    }
}

void dfs(lli src)
{
   // cout<<"src : "<<src<<endl;
    visited[src]=1;
    int cnt=0;
    int len=adj[src].size();
    for(int i=0;i<len;i++)
    {
        if(visited[adj[src][i]]==0)
        {
            dfs(adj[src][i]);
            if(dp[adj[src][i]]==true)
                cnt++;
        }
    }
    if(cnt>2)
        cnt=2;
    depth+=cnt;
    if(cnt<2)
        dp[src]=true;
}

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    lli n,x,y;
    slli(n);slli(x);slli(y);
    lli src=-1;
    lli i;
    for(i=0;i<n-1;i++)
    {
        lli u,v;slli(u);slli(v);
        adj[u].pb(v);
        adj[v].pb(u);
        cnt[v]++;
        cnt[u]++;
    }
    if(x<y)
    {
        for(i=1;i<=n;i++)
        {
            if(cnt[i]==1)
            {
                src=i;
                break;
            }
        }
        memset(dp,0,sizeof(dp));
        memset(visited,0,sizeof(visited));
        dfs(src);
       // cout<<"depth : "<<depth<<endl;
        //int len=src.size();
             //   cout<<"dp : "<<depth<<endl;
        lli ans=x*(depth)+y*(n-1-depth);
        cout<<ans<<endl;
    }
    else if(x==y)
    {
        lli ans=(n-1)*x;
        cout<<ans<<endl;
    }
    else
    {
        lli flag=0;
        for(i=1;i<=n;i++)
        {
            if(cnt[i]==n-1)
            {
                flag=1;
                break;
            }
        }
        lli ans;
        if(flag)
        {
            ans=x+(n-2)*y;
        }
        else
        {
            ans=(n-1)*y;
        }
        cout<<ans<<endl;
    }
    return 0;
}


// Shalin
#include <bits/stdc++.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
using namespace std;
#define si(x) scanf("%d",&x)
#define slli(x) scanf("%lld",&x);
#define sc(x) scanf("%c",&x);
#define ss(x) scanf("%s",x);
#define sd(x) scanf("%lf",&x);
#define bitcount __builtin_popcount
#define gcd __gcd
#define llu long long unsigned int
#define lli long long int
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define mp make_pair
#define vi vector<int>
#define vlli vector<long long int>
#define pii pair<int,int>
lli maxi=-1,maxindex;
vector<bool> visited(200010,0);
vector<lli> cnt(200010,0);
vector<lli> adj[200010];

void init()
{
    lli i,j,k;
    for(i=0;i<=200000;i++)
    {
        visited[i]=0;
    }
}

void dfs(lli src,lli dep)
{
   // cout<<"src : "<<src<<endl;
    visited[src]=1;
    if(dep>maxi)
    {
        maxi=dep;
        maxindex=src;
    }
    lli len=adj[src].size();
    for(lli i=0;i<len;i++)
    {
        if(visited[adj[src][i]]==0)
        {
            dfs(adj[src][i],dep+1);
        }
    }
}

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    lli n,x,y;
    slli(n);slli(x);slli(y);
    lli src=-1;
    lli i;
    for(i=0;i<n-1;i++)
    {
        lli u,v;slli(u);slli(v);
        adj[u].pb(v);
        adj[v].pb(u);
        cnt[v]++;
        cnt[u]++;
    }
    if(x<y)
    {
        for(i=1;i<=n;i++)
        {
            if(cnt[i]==1)
            {
                src=i;
                break;
            }
        }
        //int len=src.size();
        maxindex=src;
        dfs(src,1);
        init();
        maxi=-1;
        dfs(maxindex,1);
        lli depth=maxi;
        depth--;
     //   cout<<"dp : "<<depth<<endl;
        lli ans=x*(depth)+y*(n-1-depth);
        cout<<ans<<endl;
    }
    else if(x==y)
    {
        lli ans=(n-1)*x;
        cout<<ans<<endl;
    }
    else
    {
        lli flag=0;
        for(i=1;i<=n;i++)
        {
            if(cnt[i]==n-1)
            {
                flag=1;
                break;
            }
        }
        lli ans;
        if(flag)
        {
            ans=x+(n-2)*y;
        }
        else
        {
            ans=(n-1)*y;
        }
        cout<<ans<<endl;
    }
    return 0;
}


// Shalin
#include <bits/stdc++.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
using namespace std;
#define si(x) scanf("%d",&x)
#define slli(x) scanf("%lld",&x);
#define sc(x) scanf("%c",&x);
#define ss(x) scanf("%s",x);
#define sd(x) scanf("%lf",&x);
#define bitcount __builtin_popcount
#define gcd __gcd
#define llu long long unsigned int
#define lli long long int
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define mp make_pair
#define vi vector<int>
#define vlli vector<long long int>
#define pii pair<int,int>
lli maxi=-1,maxindex;
vector<bool> visited(200010,0);
vector<lli> cnt(200010,0);
vector<lli> adj[200010];
stack<lli> S;

void init()
{
    int i,j,k;
    for(i=1;i<=200000;i++)
    {
        visited[i]=0;
    }
}
void dfs(int src)
{
    visited[src]=1;
    S.push(src);
    int len=adj[src].size();
    int i,j,k;
    for(i=0;i<len;i++)
    {
        if(visited[adj[src][i]]==0)
        {
            dfs(adj[src][i]);
        }
    }
    if((int)(S.size())>maxi)
    {
        maxi=(int)(S.size());
        maxindex=S.top();
    }
    S.pop();
}

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    lli n,x,y;
    slli(n);slli(x);slli(y);
    lli src=-1;
    lli i;
    for(i=0;i<n-1;i++)
    {
        lli u,v;slli(u);slli(v);
        adj[u].pb(v);
        adj[v].pb(u);
        cnt[v]++;
        cnt[u]++;
    }
    if(x<y)
    {
        for(i=1;i<=n;i++)
        {
            if(cnt[i]==1)
            {
                src=i;
                break;
            }
        }
        //int len=src.size();
        dfs(src);
        init();
        maxi=-1;
        dfs(maxindex);
        lli depth=maxi;
        depth--;
     //   cout<<"dp : "<<depth<<endl;
        lli ans=x*(depth)+y*(n-1-depth);
        cout<<ans<<endl;
    }
    else if(x==y)
    {
        lli ans=(n-1)*x;
        cout<<ans<<endl;
    }
    else
    {
        lli flag=0;
        for(i=1;i<=n;i++)
        {
            if(cnt[i]==n-1)
            {
                flag=1;
                break;
            }
        }
        lli ans;
        if(flag)
        {
            ans=x+(n-2)*y;
        }
        else
        {
            ans=(n-1)*y;
        }
        cout<<ans<<endl;
    }
    return 0;
}


// Shalin
#include <bits/stdc++.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
using namespace std;
#define si(x) scanf("%d",&x)
#define slli(x) scanf("%lld",&x);
#define sc(x) scanf("%c",&x);
#define ss(x) scanf("%s",x);
#define sd(x) scanf("%lf",&x);
#define bitcount __builtin_popcount
#define gcd __gcd
#define llu long long unsigned int
#define lli long long int
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define mp make_pair
#define vi vector<int>
#define vlli vector<long long int>
#define pii pair<int,int>
lli maxi=-1,maxindex;
vector<bool> visited(200010,0);
vector<lli> cnt(200010,0);
vector<lli> adj[200010];

void init()
{
    lli i,j,k;
    for(i=0;i<=200000;i++)
    {
        visited[i]=0;
    }
}

void dfs(lli src,lli dep)
{
   // cout<<"src : "<<src<<endl;
    visited[src]=1;
    if(dep>maxi)
    {
        maxi=dep;
        maxindex=src;
    }
    lli len=adj[src].size();
    for(lli i=0;i<len;i++)
    {
        if(visited[adj[src][i]]==0)
        {
            dfs(adj[src][i],dep+1);
        }
    }
}

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    lli n,x,y;
    slli(n);slli(x);slli(y);
    lli src=-1;
    lli i;
    for(i=0;i<n-1;i++)
    {
        lli u,v;slli(u);slli(v);
        adj[u].pb(v);
        adj[v].pb(u);
        cnt[v]++;
        cnt[u]++;
    }
    if(x<y)
    {
        for(i=1;i<=n;i++)
        {
            if(cnt[i]!=0)
            {
                src=i;
                break;
            }
        }
        //int len=src.size();
        maxindex=src;
        dfs(src,1);
        init();
        maxi=-1;
        dfs(maxindex,1);
        lli depth=maxi;
        depth--;
     //   cout<<"dp : "<<depth<<endl;
        lli ans=x*(depth)+y*(n-1-depth);
        cout<<ans<<endl;
    }
    else if(x==y)
    {
        lli ans=(n-1)*x;
        cout<<ans<<endl;
    }
    else
    {
        lli flag=0;
        for(i=1;i<=n;i++)
        {
            if(cnt[i]==n-1)
            {
                flag=1;
                break;
            }
        }
        lli ans;
        if(flag)
        {
            ans=x+(n-2)*y;
        }
        else
        {
            ans=(n-1)*y;
        }
        cout<<ans<<endl;
    }
    return 0;
}


#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#define N 200005
#define ll long long
const int INF = 0x3fffffff;
using namespace std;
int n, r;   //r为需要添加的生成树以外的边的数目
vector<int> vv[N];
int fun(int cur, int pre)   //cur为当前结点, pre为上一个结点
{
    int i, l = vv[cur].size(), t = 0, v;
    for (i = 0; i < l; i++)
    {
        v = vv[cur][i];
        if (v != pre)   //若v == pre, 则又向前递归了
        {
            t += fun(v, cur);
        }
    }
    if (cur == pre) //只有第一次的时候cur == pre, 其他递归的时候都有cur != pre
    {
        if (t < 3)  return 0;
        r += t - 2;
        return 0;
    }
    if (t < 2)  return 1;
    r += t - 1; //如果这个点之后又连了多于两个边
            //则需要在这里将树分开
            //并且需要添加t-1条树以外的边来连接着t条链
    return 0;
}
int main()
{
#ifndef ONLINE_JUDGE
    freopen("1.txt", "r", stdin);
#endif
    int i, j, k, u, v;
    int n, x, y;
    ll ans;
    scanf("%d%d%d", &n, &x, &y);
    for (i = 1; i < n; i++)
    {
        scanf("%d%d", &u, &v);
        vv[u].push_back(v);
        vv[v].push_back(u);
    }
    if (x > y)
    {
        ans = 1ll*y*(n-1);
        for (i = 1; i <= n; i++)
            if (vv[i].size() == n-1)    break;
        if (i <= n) ans += (ll)(x-y);
    }
    else if (x == y)
    {
        ans = 1ll*y*(n-1);
    }
    else
    {
        fun(1, 1);
        ans = 1ll*r*y+1ll*x*(n-r-1);
    }
    printf("%I64d", ans);
    return 0;
}


#define LL long long
#define INF 0x3f3f3f3f
#define MAXN 200005
#include <bits/stdc++.h>

using namespace std;
vector<int> G[MAXN];
bool vis[MAXN];
int dp[MAXN][5];
//dp[i][j]表示 i 节点到他的子节点连 j 条边后能得到最大的边数.
int temp1, temp2;
void dfs(int x, int father){
    if (vis[x]) return;
    vis[x] = true;
    for (int i = 0; i < G[x].size(); ++i){
        int son = G[x][i];
        if (son == father) continue;
        dfs(son, x);
        temp1 = max(dp[son][0], dp[son][1]);
        temp2 = max(temp1, dp[son][2]);
        dp[x][2] = max(dp[x][1] + temp1 + 1, dp[x][2] + temp2);
        dp[x][1] = max(dp[x][1] + temp2, dp[x][0] + temp1 + 1);
        dp[x][0] += temp2;
    }
}
int main(){
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
#endif // ONLIE_JUDGE
    LL n, x, y;
    int p, q;
    scanf("%I64d%I64d%I64d", &n, &x, &y);
    for (int i = 1; i < n; ++i){
        scanf("%d%d", &p, &q);
        G[p].push_back(q);
        G[q].push_back(p);
    }
    memset(vis, 0, sizeof(vis));
    memset(dp, 0, sizeof(dp));
    LL ans;
    if (x >= y){
        bool flag = false;
        for (int i = 1; i <= n; ++i){
            if (G[i].size() == n - 1){
                flag = true;
            }
        }
        if (flag){
            ans = ((n - 2) * y + x);
        }
        else{
            ans = ((n - 1) * y);
        }
    }
    else{
        dfs(1, 0);
        LL e = max(dp[1][0], max(dp[1][1], dp[1][2]));
        ans = (x * e + (n - 1 - e) * y);
    }
    printf("%I64d\n", ans);
}


#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{int a;
    int n, m, bx, by, x, y, c = 0;
    string s;
    cin >> n >> m;
    vector<vector<char> > map(n, vector<char> (m));
    for(int i = 0; i < n; i++)
        for(int q = 0; q < m; q++)
        {
            cin >> map[i][q];
            if(map[i][q] == 'S')
            {
                bx = q;
                by = i;
                x = q;
                y = i;
            }
        }
    cin >> s;
    string rules = "uuuu";
    for(int q = 0; q < 4; q++)
    for(int w = 0; w < 4; w++)
    for(int e = 0; e < 4; e++)
    for(int r = 0; r < 4; r++)
    {
      	if(q != w && q != e && q != r &&
           w != q && w != e && w != r &&
           e != q && e != w && e != r &&
           r != q && r != w && r != e)
      	{
        	switch(q)
        	{
	          	case 0: rules[0] = 'u'; break;
	          	case 1: rules[0] = 'r'; break;
	          	case 2: rules[0] = 'd'; break;
	          	case 3: rules[0] = 'l'; break;
        	}
        	switch(w)
        	{
          		case 0: rules[1] = 'u'; break;
          		case 1: rules[1] = 'r'; break;
          		case 2: rules[1] = 'd'; break;
          		case 3: rules[1] = 'l'; break;
        	}
        	switch(e)
        	{
          		case 0: rules[3] = 'u'; break;
         	 	case 1: rules[3] = 'r'; break;
          		case 2: rules[3] = 'd'; break;
          		case 3: rules[3] = 'l'; break;
        	}
        	switch(r)
        	{
          		case 0: rules[2] = 'u'; break;
          		case 1: rules[2] = 'r'; break;
          		case 2: rules[2] = 'd'; break;
          		case 3: rules[2] = 'l'; break;
        	}
      		for(int j = 0; j < s.size(); j++)
      		{
        		switch(rules[s.c_str()[j]-48])
        		{
					case 'u': y--; break;
          			case 'r': x++; break;
          			case 'd': y++; break;
          			case 'l': x--; break;
        		}
        		if(x > m-1 || x < 0 || y > n-1 || y < 0 || map[y][x] == '#')
        		{
            		x = bx;
            		y = by;
            		break;
        		}
        		if(map[y][x] == 'E')
        		{
        			x = bx;
            		y = by;
					c++;
					break;
				}
      		}
    	}
	}
    cout << c;
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
    int n, m, bx, by, x, y, c = 0;
    string s;
    cin >> n >> m;
    vector<vector<char> > map(n, vector<char> (m));
    for(int i = 0; i < n; i++)
        for(int q = 0; q < m; q++)
        {
            cin >> map[i][q];
            if(map[i][q] == 'S')
            {
                bx = q;
                by = i;
                x = q;
                y = i;
            }
        }
    cin >> s;
    string rules = "uuuu";
    for(int q = 0; q < 4; q++)
    for(int w = 0; w < 4; w++)
    for(int e = 0; e < 4; e++)
    for(int r = 0; r < 4; r++)
    {
      	if(q != w && q != e && q != r &&
           w != q && w != e && w != r &&
           e != q && e != w && e != r &&
           r != q && r != w && r != e)
      	{
        	switch(q)
        	{
	          	case 0: rules[0] = 'u'; break;
	          	case 1: rules[0] = 'r'; break;
	          	case 2: rules[0] = 'd'; break;
	          	case 3: rules[0] = 'l'; break;
        	}
        	switch(w)
        	{
          		case 0: rules[1] = 'u'; break;
          		case 1: rules[1] = 'r'; break;
          		case 2: rules[1] = 'd'; break;
          		case 3: rules[1] = 'l'; break;
        	}
        	switch(e)
        	{
          		case 0: rules[3] = 'u'; break;
         	 	case 1: rules[3] = 'r'; break;
          		case 2: rules[3] = 'd'; break;
          		case 3: rules[3] = 'l'; break;
        	}
        	switch(r)
        	{
          		case 0: rules[2] = 'u'; break;
          		case 1: rules[2] = 'r'; break;
          		case 2: rules[2] = 'd'; break;
          		case 3: rules[2] = 'l'; break;
        	}
      		for(int j = 0; j < s.size(); j++)
      		{
        		switch(rules[s.c_str()[j]-48])
        		{
					case 'u': y--; break;
          			case 'r': x++; break;
          			case 'd': y++; break;
          			case 'l': x--; break;
        		}
        		if(x > m-1 || x < 0 || y > n-1 || y < 0 || map[y][x] == '#')
        		{
            		x = bx;
            		y = by;
            		break;
        		}
        		if(map[y][x] == 'E')
        		{
        			x = bx;
            		y = by;
					c++;
					break;
				}
      		}
    	}
	}
    cout << c;
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
    int n, m, bx, by, x, y, c = 0;
    string s;
    cin >> n >> m;
    vector<vector<char> > map(n, vector<char> (m));
    for(int i = 0; i < n; i++)
        for(int q = 0; q < m; q++)
        {
            cin >> map[i][q];
            if(map[i][q] == 'S')
            {
                bx = q;
                by = i;
                x = q;
                y = i;
            }
        }
    cin >> s;
    string rules = "uuuu";
    for(int q = 0; q < 4; q++)
    for(int w = 0; w < 4; w++)
    for(int e = 0; e < 4; e++)
    for(int r = 0; r < 4; r++)
    {
      	if(q != w && q != e && q != r &&
           w != q && w != e && w != r &&
           e != q && e != w && e != r &&
           r != q && r != w && r != e)
      	{
        	switch(q)
        	{
	          	case 0: rules[0] = 'u'; break;
	          	case 1: rules[0] = 'r'; break;
	          	case 2: rules[0] = 'd'; break;
	          	case 3: rules[0] = 'l'; break;
        	}
        	switch(w)
        	{
          		case 0: rules[1] = 'u'; break;
          		case 1: rules[1] = 'r'; break;
          		case 2: rules[1] = 'd'; break;
          		case 3: rules[1] = 'l'; break;
        	}
        	switch(e)
        	{
          		case 0: rules[3] = 'u'; break;
         	 	case 1: rules[3] = 'r'; break;
          		case 2: rules[3] = 'd'; break;
          		case 3: rules[3] = 'l'; break;
        	}
        	switch(r)
        	{
          		case 0: rules[2] = 'u'; break;
          		case 1: rules[2] = 'r'; break;
          		case 2: rules[2] = 'd'; break;
          		case 3: rules[2] = 'l'; break;
        	}
      		for(int j = 0; j < s.size(); j++)
      		{
        		switch(rules[s.c_str()[j]-48])
        		{
					case 'u': y--; break;
          			case 'r': x++; break;
          			case 'd': y++; break;
          			case 'l': x--; break;
        		}
        		if(x > m-1 || x < 0 || y > n-1 || y < 0 || map[y][x] == '#')
        		{
            		x = bx;
            		y = by;
            		break;
        		}
        		if(map[y][x] == 'E')
        		{
        			x = bx;
            		y = by;
					c++;
					break;
				}
      		}
      		x = bx;
            y = by;
    	}
	}
    cout << c;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll arr[60][60];
ll dr[4]= {-1,-1,-1,-1};
ll r,c;
string d;
ll res;
map<string,ll>mm;
void fnc(ll sx,ll sy,ll ex,ll ey)
{

    ll i,j,k,l,m,n;
    ll aa,bb,cc,dd;
    aa=sx;
    bb=sy;
    cc=ex;
    dd=ey;
    for(i=0; i<d.size(); i++)
    {
        char c=d[i];
        ll tmp=c-'0';
        //cout<<tmp<<endl;
        ll tmp1=dr[tmp];
        if(dr[tmp]==1)
        {
            ll tx=aa-1;
            ll ty=bb;
            if(tx>=0&&tx<r&&ty>=0&&ty<c)
            {
                if(arr[tx][ty]>0)
                {
                    aa=tx;
                    bb=ty;
                }
                else
                {
                    return;
                }
            }
            else
            {
                return;
            }
        }
        else if(dr[tmp]==2)
        {
            ll tx=aa+1;
            ll ty=bb;
            if(tx>=0&&tx<r&&ty>=0&&ty<c)
            {
                if(arr[tx][ty]>0)
                {
                    aa=tx;
                    bb=ty;
                }
                else
                {
                    return;
                }
            }
            else
            {
                return;
            }
        }
        else if(dr[tmp]==3)
        {
            ll tx=aa;
            ll ty=bb-1;
            if(tx>=0&&tx<r&&ty>=0&&ty<c)
            {
                if(arr[tx][ty]>0)
                {
                    aa=tx;
                    bb=ty;
                }
                else
                {
                    return;
                }
            }
            else
            {
                return;
            }
        }
        else if(dr[tmp]==4)
        {
            ll tx=aa;
            ll ty=bb+1;
            if(tx>=0&&tx<r&&ty>=0&&ty<c)
            {
                if(arr[tx][ty]>0)
                {
                    aa=tx;
                    bb=ty;
                }
                else
                {
                    return;
                }
            }
            else
            {
                return;
            }
        }
        if(aa==ex&&bb==ey)
        {
            res++;
            return;
        }
    }
    return;
}
int main()
{
    ll i,j,k,l,m;
    while(cin>>r>>c)
    {
        res=0;
        memset(arr,-1,sizeof(arr));
        ll a,b,x,y;
        string s;
        for(i=0; i<r; i++)
        {
            cin>>s;
            for(j=0; j<s.size(); j++)
            {
                char c=s[j];
                if(c=='.')
                {
                    arr[i][j]=1;
                }
                if(c=='#')
                {
                    arr[i][j]=0;
                }
                if(c=='S')
                {
                    arr[i][j]=2;
                    a=i;
                    b=j;
                }
                if(c=='E')
                {
                    arr[i][j]=3;
                    x=i;
                    y=j;
                }
            }
        }
        cin>>d;
        map<char,ll>mp;
        for(i=0;i<d.size();i++)
        {
            char xx=d[i];
            mp[xx]++;
        }
        ll cx,cy;
        cx=a;
        cy=b;
        for(i=0;i<4;i++)
        {
            dr[i]=i+1;
        }
        mm.clear();
        do
        {
            string ss="";
            for(i=0;i<mp.size();i++)
            {
                char y;
                y=(char)(dr[i]);
                ss+=y;
            }
            //if(!mm[ss])
            {
                mm[ss]=1;
                fnc(a,b,x,y);
            }
        }
        while ( next_permutation(dr,dr+4) );
        cout<<res<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll arr[60][60];
ll dr[4]= {1,2,3,4};
ll r,c;
string d;
ll res;
void fnc(ll sx,ll sy,ll ex,ll ey)
{
    ll i,j,k,l,m,n;
    ll aa,bb,cc,dd;
    aa=sx;
    bb=sy;
    cc=ex;
    dd=ey;
    for(i=0; i<d.size(); i++)
    {
        char c=d[i];
        ll tmp=c-'0';
        //cout<<tmp<<" "<<dr[tmp]<<endl;
        ll tmp1=dr[tmp];
        if(dr[tmp]==1)
        {
            ll tx=aa-1;
            ll ty=bb;
            if(tx>=0&&tx<r&&ty>=0&&ty<c)
            {
                if(arr[tx][ty]>0)
                {
                    aa=tx;
                    bb=ty;
                }
            }
            else
            {
                return;
            }
        }
        else if(dr[tmp]==2)
        {
            ll tx=aa+1;
            ll ty=bb;
            if(tx>=0&&tx<r&&ty>=0&&ty<c)
            {
                if(arr[tx][ty]>0)
                {
                    aa=tx;
                    bb=ty;
                }
            }
            else
            {
                return;
            }
        }
        else if(dr[tmp]==3)
        {
            ll tx=aa;
            ll ty=bb-1;
            if(tx>=0&&tx<r&&ty>=0&&ty<c)
            {
                if(arr[tx][ty]>0)
                {
                    aa=tx;
                    bb=ty;
                }
            }
            else
            {
                return;
            }
        }
        else if(dr[tmp]==4)
        {
            ll tx=aa;
            ll ty=bb+1;
            if(tx>=0&&tx<r&&ty>=0&&ty<c)
            {
                if(arr[tx][ty]>0)
                {
                    aa=tx;
                    bb=ty;
                }
            }
            else
            {
                return;
            }
        }
        if(aa==ex&&bb==ey)
        {
            res++;
            return;
        }
    }
    return;
}
int main()
{
    ll i,j,k,l,m;
    while(cin>>r>>c)
    {
        res=0;
        memset(arr,-1,sizeof(arr));
        ll a,b,x,y;
        string s;
        for(i=0; i<r; i++)
        {
            cin>>s;
            for(j=0; j<s.size(); j++)
            {
                char c=s[j];
                if(c=='.')
                {
                    arr[i][j]=1;
                }
                if(c=='#')
                {
                    arr[i][j]=0;
                }
                if(c=='S')
                {
                    arr[i][j]=2;
                    a=i;
                    b=j;
                }
                if(c=='E')
                {
                    arr[i][j]=3;
                    x=i;
                    y=j;
                }
            }
        }
        cin>>d;
        ll cx,cy;
        cx=a;
        cy=b;
        do
        {
            fnc(a,b,x,y);
        }
        while ( next_permutation(dr,dr+4) );
        cout<<res<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll arr[60][60];
ll dr[4]= {-1,-1,-1,-1};
ll r,c;
string d;
ll res;
map<string,ll>mm;
void fnc(ll sx,ll sy,ll ex,ll ey)
{

    ll i,j,k,l,m,n;
    ll aa,bb,cc,dd;
    aa=sx;
    bb=sy;
    cc=ex;
    dd=ey;
    for(i=0; i<d.size(); i++)
    {
        char c=d[i];
        ll tmp=c-'0';
        //cout<<tmp<<endl;
        ll tmp1=dr[tmp];
        if(dr[tmp]==1)
        {
            ll tx=aa-1;
            ll ty=bb;
            if(tx>=0&&tx<r&&ty>=0&&ty<c)
            {
                if(arr[tx][ty]>0)
                {
                    aa=tx;
                    bb=ty;
                }
                else
                {
                    return;
                }
            }
            else
            {
                return;
            }
        }
        else if(dr[tmp]==2)
        {
            ll tx=aa+1;
            ll ty=bb;
            if(tx>=0&&tx<r&&ty>=0&&ty<c)
            {
                if(arr[tx][ty]>0)
                {
                    aa=tx;
                    bb=ty;
                }
                else
                {
                    return;
                }
            }
            else
            {
                return;
            }
        }
        else if(dr[tmp]==3)
        {
            ll tx=aa;
            ll ty=bb-1;
            if(tx>=0&&tx<r&&ty>=0&&ty<c)
            {
                if(arr[tx][ty]>0)
                {
                    aa=tx;
                    bb=ty;
                }
                else
                {
                    return;
                }
            }
            else
            {
                return;
            }
        }
        else if(dr[tmp]==4)
        {
            ll tx=aa;
            ll ty=bb+1;
            if(tx>=0&&tx<r&&ty>=0&&ty<c)
            {
                if(arr[tx][ty]>0)
                {
                    aa=tx;
                    bb=ty;
                }
                else
                {
                    return;
                }
            }
            else
            {
                return;
            }
        }
        if(aa==ex&&bb==ey)
        {
            res++;
            return;
        }
    }
    return;
}
int main()
{
    ll i,j,k,l,m;
    while(cin>>r>>c)
    {
        res=0;
        memset(arr,-1,sizeof(arr));
        ll a,b,x,y;
        string s;
        for(i=0; i<r; i++)
        {
            cin>>s;
            for(j=0; j<s.size(); j++)
            {
                char c=s[j];
                if(c=='.')
                {
                    arr[i][j]=1;
                }
                if(c=='#')
                {
                    arr[i][j]=0;
                }
                if(c=='S')
                {
                    arr[i][j]=2;
                    a=i;
                    b=j;
                }
                if(c=='E')
                {
                    arr[i][j]=3;
                    x=i;
                    y=j;
                }
            }
        }
        cin>>d;
        map<char,ll>mp;
        for(i=0;i<d.size();i++)
        {
            char xx=d[i];
            mp[xx]++;
        }
        ll cx,cy;
        cx=a;
        cy=b;
        for(i=0;i<4;i++)
        {
            dr[i]=i+1;
        }
        mm.clear();
        do
        {
            string ss="";
            for(i=0;i<mp.size();i++)
            {
                char y;
                y=(char)(dr[i]);
                ss+=y;
            }
            if(!mm[ss])
            {
                mm[ss]=1;
                fnc(a,b,x,y);
            }
        }
        while ( next_permutation(dr,dr+4) );
        cout<<res<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll arr[60][60];
ll dr[4]= {1,2,3,4};
ll r,c;
string d;
ll res;
void fnc(ll sx,ll sy,ll ex,ll ey)
{
    ll i,j,k,l,m,n;
    ll aa,bb,cc,dd;
    aa=sx;
    bb=sy;
    cc=ex;
    dd=ey;
    for(i=0; i<d.size(); i++)
    {
        char c=d[i];
        ll tmp=c-'0';
        //cout<<tmp<<" "<<dr[tmp]<<endl;
        ll tmp1=dr[tmp];
        if(dr[tmp]==1)
        {
            ll tx=aa-1;
            ll ty=bb;
            if(tx>=0&&tx<r&&ty>=0&&ty<c)
            {
                aa=tx;
                bb=ty;
            }
            else
            {
                return;
            }
        }
        else if(dr[tmp]==2)
        {
            ll tx=aa+1;
            ll ty=bb;
            if(tx>=0&&tx<r&&ty>=0&&ty<c)
            {
                aa=tx;
                bb=ty;
            }
            else
            {
                return;
            }
        }
        else if(dr[tmp]==3)
        {
            ll tx=aa;
            ll ty=bb-1;
            if(tx>=0&&tx<r&&ty>=0&&ty<c)
            {
                aa=tx;
                bb=ty;
            }
            else
            {
                return;
            }
        }
        else if(dr[tmp]==4)
        {
            ll tx=aa;
            ll ty=bb+1;
            if(tx>=0&&tx<r&&ty>=0&&ty<c)
            {
                aa=tx;
                bb=ty;
            }
            else
            {
                return;
            }
        }
        if(aa==ex&&bb==ey)
        {
            res++;
            return;
        }
    }
    return;
}
int main()
{
    ll i,j,k,l,m;
    while(cin>>r>>c)
    {
        res=0;
        memset(arr,-1,sizeof(arr));
        ll a,b,x,y;
        string s;
        for(i=0; i<r; i++)
        {
            cin>>s;
            for(j=0; j<s.size(); j++)
            {
                char c=s[j];
                if(c=='.')
                {
                    arr[i][j]=1;
                }
                if(c=='#')
                {
                    arr[i][j]=0;
                }
                if(c=='S')
                {
                    arr[i][j]=2;
                    a=i;
                    b=j;
                }
                if(c=='E')
                {
                    arr[i][j]=3;
                    x=i;
                    y=j;
                }
            }
        }
        cin>>d;
        ll cx,cy;
        cx=a;
        cy=b;
        do
        {
            fnc(a,b,x,y);
        }
        while ( next_permutation(dr,dr+4) );
        cout<<res<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll arr[60][60];
ll dr[4]= {-1,-1,-1,-1};
ll r,c;
string d;
ll res;
map<string,ll>mm;
void fnc(ll sx,ll sy,ll ex,ll ey)
{

    ll i,j,k,l,m,n;
    ll aa,bb,cc,dd;
    aa=sx;
    bb=sy;
    cc=ex;
    dd=ey;
    for(i=0; i<d.size(); i++)
    {
        char c=d[i];
        ll tmp=c-'0';
        //cout<<tmp<<endl;
        ll tmp1=dr[tmp];
        if(dr[tmp]==1)
        {
            ll tx=aa-1;
            ll ty=bb;
            if(tx>=0&&tx<r&&ty>=0&&ty<c)
            {
                if(arr[tx][ty]>0)
                {
                    aa=tx;
                    bb=ty;
                }
                else
                {
                    return;
                }
            }
            else
            {
                return;
            }
        }
        else if(dr[tmp]==2)
        {
            ll tx=aa+1;
            ll ty=bb;
            if(tx>=0&&tx<r&&ty>=0&&ty<c)
            {
                if(arr[tx][ty]>0)
                {
                    aa=tx;
                    bb=ty;
                }
                else
                {
                    return;
                }
            }
            else
            {
                return;
            }
        }
        else if(dr[tmp]==3)
        {
            ll tx=aa;
            ll ty=bb-1;
            if(tx>=0&&tx<r&&ty>=0&&ty<c)
            {
                if(arr[tx][ty]>0)
                {
                    aa=tx;
                    bb=ty;
                }
                else
                {
                    return;
                }
            }
            else
            {
                return;
            }
        }
        else if(dr[tmp]==4)
        {
            ll tx=aa;
            ll ty=bb+1;
            if(tx>=0&&tx<r&&ty>=0&&ty<c)
            {
                if(arr[tx][ty]>0)
                {
                    aa=tx;
                    bb=ty;
                }
                else
                {
                    return;
                }
            }
            else
            {
                return;
            }
        }
        if(aa==ex&&bb==ey)
        {
            res++;
            return;
        }
    }
    return;
}
int main()
{
    ll i,j,k,l,m;
    while(cin>>r>>c)
    {
        res=0;
        memset(arr,-1,sizeof(arr));
        ll a,b,x,y;
        string s;
        for(i=0; i<r; i++)
        {
            cin>>s;
            for(j=0; j<s.size(); j++)
            {
                char c=s[j];
                if(c=='.')
                {
                    arr[i][j]=1;
                }
                if(c=='#')
                {
                    arr[i][j]=0;
                }
                if(c=='S')
                {
                    arr[i][j]=2;
                    a=i;
                    b=j;
                }
                if(c=='E')
                {
                    arr[i][j]=3;
                    x=i;
                    y=j;
                }
            }
        }
        cin>>d;
        ll cx,cy;
        cx=a;
        cy=b;
        for(i=0;i<4;i++)
        {
            dr[i]=i+1;
        }
        do
        {
            fnc(a,b,x,y);
        }
        while ( next_permutation(dr,dr+4) );
        cout<<res<<endl;
    }
    return 0;
}


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

int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};
int N, M, i, j, x, y, sx, sy, p[4]={0,1,2,3}, ans;
string s[52], ins;

int main(){
	for(scanf("%d%d",&N,&M),i=0;i<N;i++){
		cin >> s[i];
		for(j=0;j<M;j++){
			if(s[i][j]=='S')
				sx=j,sy=i;
		}
	}
	cin >> ins;
	for(i=0;i<24;i++){
		x = sx; y = sy;
		for(char c : ins){
			int id = p[c-'0'];
			x += dx[id]; y += dy[id];
			if(y>=0&&y<N&&x>=0&&x<M&&s[y][x]!='#') x=x;
			else break;
			if(s[y][x] == 'E'){ans++; break;}
		}
		next_permutation(p, p+4);
	}
	printf("%d\n",ans);
	return 0;
}


#define ll long long
#define fs first
#define sc second
#include<bits/stdc++.h>
#define pi pair<int, int>
using namespace std;
string s;
int d[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
map<char, int> mp;
char m[150][150];
int rows, cols, rs = 0;
pi ss, ee;
void dfs(int r, int c, int index){
	if(r < 0 || c < 0 || r >= rows || c >= cols) return;
	if(m[r][c] == '#' || index >= s.size()) return;
	if(r == ee.fs && c == ee.sc){
		rs++;
		return;
	}
	char ch = s[index];
	int xx = d[mp[ch]][0], yy = d[mp[ch]][1];
	dfs(r + xx, c + yy, index + 1);
}
int main(){

	cin >> rows >> cols;
	for(int i = 0; i < rows; i++){
		string s1; cin >> s1;
		for(int j = 0; j < cols; j++){
			m[i][j] = s1[j];
			if(s1[i] == 'S'){
				ss.fs = i; ss.sc = j;
			}
			if(s1[i] == 'E'){
				ee.fs = i; ee.sc = j;
			}
		}
	}
	cin >> s;
	cout << "s la : " << s << endl;
	for(int i = 0; i < 4; i++){
		for(int j = 0; j < 4; j++){
			if(i == j) continue;
			for(int k = 0; k < 4; k++){
				if(k == i || k == j) continue;
				for(int v = 0; v < 4; v++){
					if(v == k || v == i || v == j) continue;
					mp['0'] = i;
					mp['1'] = j;
					mp['2'] = k;
					mp['3'] = v;
					dfs(ss.fs, ss.sc, 0);
				}
			}
		}
	}
	cout << rs << endl;
	return 0;
}


#define ll long long
#define fs first
#define sc second
#include<bits/stdc++.h>
#define pi pair<int, int>
using namespace std;
string s;
int d[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
map<char, int> mp;
char m[150][150];
int rows, cols, rs = 0;
pi ss, ee;
void dfs(int r, int c, int index){
	if(r < 0 || c < 0 || r >= rows || c >= cols) return;
	if(m[r][c] == '#' || index >= s.size()) return;
	if(r == ee.fs && c == ee.sc){
		rs++;
		return;
	}
	char ch = s[index];
	int xx = d[mp[ch]][0], yy = d[mp[ch]][1];
	dfs(r + xx, c + yy, index);
}
int main(){

	cin >> rows >> cols;
	for(int i = 0; i < rows; i++){
		cin >> s;
		for(int j = 0; j < s.size(); j++){
			m[i][j] = s[i];
			if(s[i] == 'S'){
				ss.fs = i; ss.sc = j;
			}
			if(s[i] == 'E'){
				ee.fs = i; ee.sc = j;
			}
		}
	}
	cin >> s;
	for(int i = 0; i < 4; i++){
		for(int j = 0; j < 4; j++){
			if(i == j) continue;
			for(int k = 0; k < 4; k++){
				if(k == i || k == j) continue;
				for(int v = 0; v < 4; v++){
					if(v == k || v == i || v == j) continue;
					mp['0'] = i;
					mp['1'] = j;
					mp['2'] = k;
					mp['3'] = v;
					dfs(ss.fs, ss.sc, 0);
				}
			}
		}
	}
	cout << rs << endl;
	return 0;
}


#define ll long long
#define fs first
#define sc second
#include<bits/stdc++.h>
#define pi pair<int, int>
using namespace std;
string s;
int d[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
map<char, int> mp;
char m[150][150];
int rows, cols, rs = 0;
pi ss, ee;
void dfs(int r, int c, int index){
	if(r < 0 || c < 0 || r >= rows || c >= cols) return;
	if(m[r][c] == '#' || index >= s.size()) return;
	if(r == ee.fs && c == ee.sc){
		rs++;
		return;
	}
	char ch = s[index];
	int xx = d[mp[ch]][0], yy = d[mp[ch]][1];
	dfs(r + xx, c + yy, index + 1);
}
int main(){

	cin >> rows >> cols;
	for(int i = 0; i < rows; i++){
		cin >> s;
		for(int j = 0; j < s.size(); j++){
			m[i][j] = s[i];
			if(s[i] == 'S'){
				ss.fs = i; ss.sc = j;
			}
			if(s[i] == 'E'){
				ee.fs = i; ee.sc = j;
			}
		}
	}
	cin >> s;
	for(int i = 0; i < 4; i++){
		for(int j = 0; j < 4; j++){
			if(i == j) continue;
			for(int k = 0; k < 4; k++){
				if(k == i || k == j) continue;
				for(int v = 0; v < 4; v++){
					if(v == k || v == i || v == j) continue;
					mp['0'] = i;
					mp['1'] = j;
					mp['2'] = k;
					mp['3'] = v;
					dfs(ss.fs, ss.sc, 0);
				}
			}
		}
	}
	cout << rs << endl;
	return 0;
}


#define ll long long
#define fs first
#define sc second
#include<bits/stdc++.h>
#define pi pair<int, int>
using namespace std;
string s;
int d[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
map<char, int> mp;
char m[150][150];
int rows, cols, rs = 0;
pi ss, ee;
void dfs(int r, int c, int index){
	if(r < 0 || c < 0 || r >= rows || c >= cols) return;
	if(m[r][c] == '#' || index >= s.size()) return;
	if(r == ee.fs && c == ee.sc){
		rs++;
		return;
	}
	char ch = s[index];
	int xx = d[mp[ch]][0], yy = d[mp[ch]][1];
	dfs(r + xx, c + yy, index + 1);
}
int main(){

	cin >> rows >> cols;
	for(int i = 0; i < rows; i++){
		string s1; cin >> s1;
		for(int j = 0; j < cols; j++){
			m[i][j] = s1[i];
			if(s1[i] == 'S'){
				ss.fs = i; ss.sc = j;
			}
			if(s1[i] == 'E'){
				ee.fs = i; ee.sc = j;
			}
		}
	}
	cin >> s;
	//cout << "s la : " << s << endl;
	for(int i = 0; i < 4; i++){
		for(int j = 0; j < 4; j++){
			if(i == j) continue;
			for(int k = 0; k < 4; k++){
				if(k == i || k == j) continue;
				for(int v = 0; v < 4; v++){
					if(v == k || v == i || v == j) continue;
					mp['0'] = i;
					mp['1'] = j;
					mp['2'] = k;
					mp['3'] = v;
					dfs(ss.fs, ss.sc, 0);
				}
			}
		}
	}
	cout << rs << endl;
	return 0;
}


#define ll long long
#define fs first
#define sc second
#include<bits/stdc++.h>
#define pi pair<int, int>
using namespace std;
string s;
int d[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
map<char, int> mp;
char m[150][150];
int rows, cols, rs = 0;
pi ss, ee;
void dfs(int r, int c, int index){
	if(r < 0 || c < 0 || r >= rows || c >= cols) return;
	if(m[r][c] == '#' || index >= s.size()) return;
	if(r == ee.fs && c == ee.sc){
		rs++;
		return;
	}
	char ch = s[index];
	int xx = d[mp[ch]][0], yy = d[mp[ch]][1];
	dfs(r + xx, c + yy, index + 1);
}
int main(){

	cin >> rows >> cols;
	for(int i = 0; i < rows; i++){
		cin >> s;
		for(int j = 0; j < cols; j++){
			m[i][j] = s[i];
			if(s[i] == 'S'){
				ss.fs = i; ss.sc = j;
			}
			if(s[i] == 'E'){
				ee.fs = i; ee.sc = j;
			}
		}
	}
	cin >> s;
	for(int i = 0; i < 4; i++){
		for(int j = 0; j < 4; j++){
			if(i == j) continue;
			for(int k = 0; k < 4; k++){
				if(k == i || k == j) continue;
				for(int v = 0; v < 4; v++){
					if(v == k || v == i || v == j) continue;
					mp['0'] = i;
					mp['1'] = j;
					mp['2'] = k;
					mp['3'] = v;
					dfs(ss.fs, ss.sc, 0);
				}
			}
		}
	}
	cout << rs << endl;
	return 0;
}


#define ll long long
#define fs first
#define sc second
#include<bits/stdc++.h>
#define pi pair<int, int>
using namespace std;
string s;
int d[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
map<char, int> mp;
char m[150][150];
int rows, cols, rs = 0;
pi ss, ee;
void dfs(int r, int c, int index){
	if(r < 0 || c < 0 || r >= rows || c >= cols) return;
	if(m[r][c] == '#' || index >= s.size()) return;
	if(r == ee.fs && c == ee.sc){
		rs++;
		return;
	}
	char ch = s[index];
	int xx = d[mp[ch]][0], yy = d[mp[ch]][1];
	dfs(r + xx, c + yy, index + 1);
}
int main(){

	cin >> rows >> cols;
	for(int i = 0; i < rows; i++){
		string s1; cin >> s1;
		for(int j = 0; j < cols; j++){
			m[i][j] = s1[j];
			if(s1[j] == 'S'){
				ss.fs = i; ss.sc = j;
			}
			if(s1[j] == 'E'){
				ee.fs = i; ee.sc = j;
			}
		}
	}
	cin >> s;
//	cout << "s la : " << s << endl;
	for(int i = 0; i < 4; i++){
		for(int j = 0; j < 4; j++){
			if(i == j) continue;
			for(int k = 0; k < 4; k++){
				if(k == i || k == j) continue;
				for(int v = 0; v < 4; v++){
					if(v == k || v == i || v == j) continue;
					mp['0'] = i;
					mp['1'] = j;
					mp['2'] = k;
					mp['3'] = v;
					dfs(ss.fs, ss.sc, 0);
				}
			}
		}
	}
	cout << rs << endl;
	return 0;
}


#define ll long long
#define fs first
#define sc second
#include<bits/stdc++.h>
#define pi pair<int, int>
using namespace std;
string s;
int d[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
map<char, int> mp;
char m[150][150];
int rows, cols, rs = 0;
pi ss, ee;
void dfs(int r, int c, int index){
	if(r < 0 || c < 0 || r >= rows || c >= cols) return;
	if(m[r][c] == '#' || index >= s.size()) return;
	if(r == ee.fs && c == ee.sc){
		rs++;
		return;
	}
	char ch = s[index];
	int xx = d[mp[ch]][0], yy = d[mp[ch]][1];
	dfs(r + xx, c + yy, index + 1);
}
int main(){

	cin >> rows >> cols;
	for(int i = 0; i < rows; i++){
		string s1; cin >> s1;
		for(int j = 0; j < cols; j++){
			m[i][j] = s1[j];
			if(s1[i] == 'S'){
				ss.fs = i; ss.sc = j;
			}
			if(s1[i] == 'E'){
				ee.fs = i; ee.sc = j;
			}
		}
	}
	cin >> s;
//	cout << "s la : " << s << endl;
	for(int i = 0; i < 4; i++){
		for(int j = 0; j < 4; j++){
			if(i == j) continue;
			for(int k = 0; k < 4; k++){
				if(k == i || k == j) continue;
				for(int v = 0; v < 4; v++){
					if(v == k || v == i || v == j) continue;
					mp['0'] = i;
					mp['1'] = j;
					mp['2'] = k;
					mp['3'] = v;
					dfs(ss.fs, ss.sc, 0);
				}
			}
		}
	}
	cout << rs << endl;
	return 0;
}


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

int main()
{
   int n,m;
   cin>>n>>m;

    vector<string>strvec;
    string st,instruction;

    for(int i=0;i<n;i++)
    {
       cin>>st;
       strvec.push_back(st);
    }
    cin>>instruction;

//   cout<<endl;
//   for(int i=0;i<strvec.size();i++)
//   {
//       cout<<strvec[i]<<endl;
//   }

   int start_row;
   int start_column;
   int End_row;
   int End_column;

    int row;
    int column;
   for(int i=0;i<n;i++)
   {    st=strvec[i];
       for(int j=0;j<st.length();j++)
       {    //char myword[]={st[j]};
            //string temp=myword;
            string temp="";
            temp+=st[j];
           if(temp=="S"){
            //start_row=i;
            row=i;
            //start_column=j;
            column=j;
           }
           else if(temp=="E"){
            End_row=i;
            End_column=j;
           }
       }
   }

   //cout<<start_row<<" "<<start_column<<endl;
   //cout<<End_row<<" "<<End_column<<endl;

   int cnt=0;
   int flag;

   for(int u=0;u<=3;u++)
   {    //start_row=row;
        //start_column=column;
       for(int d=0;d<=3;d++)
       {
           for(int l=0;l<=3;l++)
           {
               for(int r=0;r<=3;r++)
               {
                   if((u!=d && u!=l && u!=r) && (l!=u&&l!=d&&l!=r) &&(r!=u&&r!=d&&r!=l)&&(d!=l&&d!=u&&d!=r))
                   {    start_row=row;
                        start_column=column;
                       for(int i=0;i<instruction.length();i++)
                       {
                           stringstream ss;
                           ss<<u;
                           string upp=ss.str();/**for up**/

                            stringstream ss2;
                            ss2<<d;
                            string downn=ss2.str();/**for down**/

                            stringstream ss3;
                            ss3<<l;
                            string leftt=ss3.str();/**for left**/

                            stringstream ss4;
                            ss4<<r;
                            string rightt=ss4.str();/**for right**/

                            //char myword[]={instruction[i]};
                            //cout<<" myword = "<<myword[]<<endl;
                            string temp="";
                            temp=temp+instruction[i];
                            //cout<<"temp "<<temp<<" "<<"up ="<<upp<<" "<<"down = "<<downn<<" "<<"left = "<<leftt<<" "<<"right = "<<rightt<<endl;
                            if(temp==upp)start_row--;
                            else if(temp==downn)start_row++;
                            else if(temp==leftt)start_column--;
                            else if(temp==rightt)start_column++;

                            //if(start_row>=0 &&start_row<n)
                            st=strvec[start_row];
                            //if(start_column>=0&& start_column<m){
                                    //char tempword[]={st[start_column]};
                                    //temp=tempword;
                                    temp="";
                                    temp+=st[start_column];
                            //}

                            //cout<<"star rw "<<start_row<<endl;
                            //cout<<"start colmn "<<start_column<<endl;
                            string has="#";
                            if(start_row==End_row && start_column==End_column){cnt++;break;}
                            else if(start_row<0 || start_row==n)break;
                            else if(start_column<0 || start_column==m)break;
                            else if(temp==has)break;

                       }
                   }
               }
           }
       }
   }

   cout<<cnt<<endl;

return 0;
}