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

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

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

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


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

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

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

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


#include<iostream>
#include<vector>
#include<set>
using namespace std;
long long int n,x,y;
vector<int>adj[200007];
int dp[200007][3];
void dfs(int i,int parent)
{
dp[i][0]=0;
dp[i][1]=0;
dp[i][2]=0;
int temporary_child;
for(int j=0;j<adj[i].size();j++)
if(adj[i][j]!=parent)
{
dfs(adj[i][j],i);
dp[i][0]+=max(dp[adj[i][j]][0],max(dp[adj[i][j]][2],dp[adj[i][j]][1]));
temporary_child=adj[i][j];
}
for(int j=0;j<adj[i].size();j++)
if(adj[i][j]!=parent)
dp[i][1]=max(dp[i][1],1+dp[i][0]-max(dp[adj[i][j]][0],max(dp[adj[i][j]][2],dp[adj[i][j]][1]))+max(dp[adj[i][j]][0],dp[adj[i][j]][1]));
for(int j=0;j<adj[i].size();j++)
for(int k=j+1;k<adj[i].size();k++)
if(adj[i][j]!=parent&&adj[i][k]!=parent)
dp[i][2]=max(dp[i][2],2+dp[i][0]-max(dp[adj[i][j]][0],max(dp[adj[i][j]][2],dp[adj[i][j]][1]))-max(dp[adj[i][k]][0],max(dp[adj[i][k]][2],dp[adj[i][k]][1]))+max(dp[adj[i][j]][0],dp[adj[i][j]][1])+max(dp[adj[i][k]][0],dp[adj[i][k]][1]));
}

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

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


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

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

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

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


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

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

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

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


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

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

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

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


#include<iostream>
#include<vector>
#include<set>
using namespace std;
long long int n,x,y;
vector<int>adj[200007];
int dp[200007][3];
void dfs(int i,int parent)
{
dp[i][0]=0;
dp[i][1]=0;
dp[i][2]=0;
int temporary_child;
for(int j=0;j<adj[i].size();j++)
if(adj[i][j]!=parent)
{
dfs(adj[i][j],i);
dp[i][0]+=max(dp[adj[i][j]][0],max(dp[adj[i][j]][2],dp[adj[i][j]][1]));
}
for(int j=0;j<adj[i].size();j++)
if(adj[i][j]!=parent)
dp[i][1]=max(dp[i][1],1+dp[i][0]-max(dp[adj[i][j]][0],max(dp[adj[i][j]][2],dp[adj[i][j]][1]))+max(dp[adj[i][j]][0],dp[adj[i][j]][1]));
for(int j=0;j<adj[i].size();j++)
for(int k=j+1;k<adj[i].size();k++)
if(adj[i][j]!=parent&&adj[i][k]!=parent)
dp[i][2]=max(dp[i][2],2+dp[i][0]-max(dp[adj[i][j]][0],max(dp[adj[i][j]][2],dp[adj[i][j]][1]))-max(dp[adj[i][k]][0],max(dp[adj[i][k]][2],dp[adj[i][k]][1]))+max(dp[adj[i][j]][0],dp[adj[i][j]][1])+max(dp[adj[i][k]][0],dp[adj[i][k]][1]));
}

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

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


#include<bits/stdc++.h>//freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
using namespace std;
#define ll long long
#define mem(x,a) memset(x,a,sizeof(x))
#define pii pair<int,int>
#define fr(i,a,n) for(int i=(a);i<=(n);i++)
#define frd(i,a,n) for(int i=(a);i>=(n);i--)
#define s(n) scanf("%d",&(n))
#define sl(n) scanf("%lld",&(n))
#define nl printf("\n")
#define sp printf(" ")
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define V vector
ll mod=1e9+7;
int vis[200005],last,ans,ans2;
V<int> g[200005];
void dfs(int u,int lev=1)
{
	vis[u]=1;
	if(last ==-1)ans2=lev,last=u;
	else if(lev>ans2)last=u,ans2=lev;
	for(int i=0;i<g[u].size();i++)
		if(!vis[g[u][i]])dfs(g[u][i],lev+1);
}
void dfs1(int u,int p,int lev=1)
{
	ans=max(ans,lev);
	for(int i=0;i<g[u].size();i++){
		if(g[u][i] == p)continue;
		dfs1(g[u][i],u,lev+1);
	}
}
int main() {
	int n,u,v;
	ll x,y;
	cin>>n>>x>>y;
	fr(i,1,n-1)s(u),s(v),g[u].pb(v),g[v].pb(u);
	last=-1;
	dfs(1);
	dfs1(last,-1);
	ll r=0;
	if(x<=y)
		r= (ans-1LL)*x*1LL + (n-ans)*1LL*y;
	else
	{
		int bra=n-ans;
		if(n==3|| (n==4 && ans==4))
			r= (n-2LL)*y+ x;
		else r=(n-1LL)*y;
	}
	cout<<max(0LL,r)<<endl;
	return 0;
}


#include<bits/stdc++.h>//freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
using namespace std;
#define ll long long
#define mem(x,a) memset(x,a,sizeof(x))
#define pii pair<int,int>
#define fr(i,a,n) for(int i=(a);i<=(n);i++)
#define frd(i,a,n) for(int i=(a);i>=(n);i--)
#define s(n) scanf("%d",&(n))
#define sl(n) scanf("%lld",&(n))
#define nl printf("\n")
#define sp printf(" ")
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define V vector
ll mod=1e9+7;
int vis[200005],last,ans,ans2;
V<int> g[200005];
void dfs(int u,int lev=1)
{
	vis[u]=1;
	if(last ==-1)ans2=lev,last=u;
	else if(lev>ans2)last=u,ans2=lev;
	for(int i=0;i<g[u].size();i++)
		if(!vis[g[u][i]])dfs(g[u][i],lev+1);
}
void dfs1(int u,int p,int lev=1)
{
	ans=max(ans,lev);
	for(int i=0;i<g[u].size();i++){
		if(g[u][i] == p)continue;
		dfs1(g[u][i],u,lev+1);
	}
}
int in[200005];
int main() {
	int n,u,v;
	ll x,y;
	cin>>n>>x>>y;
	fr(i,1,n-1)s(u),s(v),in[u]++,in[v]++,g[u].pb(v),g[v].pb(u);
	last=-1;
	dfs(1);
	dfs1(last,-1);
	ll r=0;
	if(x<=y)
		r= (ans-1LL)*x*1LL + (n-ans)*1LL*y;
	else
	{
		int maxi=0;
		fr(i,1,n)maxi=max(maxi,in[i]);
		//cout<<maxi<<endl;
		if(maxi==(n-1))
			r= (n-2LL)*y+ x;
		else r=(n-1LL)*y;
	}
	cout<<r<<endl;
	return 0;
}


#include<bits/stdc++.h>//freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
using namespace std;
#define ll long long
#define mem(x,a) memset(x,a,sizeof(x))
#define pii pair<int,int>
#define fr(i,a,n) for(int i=(a);i<=(n);i++)
#define frd(i,a,n) for(int i=(a);i>=(n);i--)
#define s(n) scanf("%d",&(n))
#define sl(n) scanf("%lld",&(n))
#define nl printf("\n")
#define sp printf(" ")
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define V vector
ll mod=1e9+7;
int vis[200005],last,ans,ans2;
V<int> g[200005];

int as[200005];
int dfs1(int u,int p)
{
	int as=0;
	for(int i=0;i<g[u].size();i++){
		if(g[u][i] == p)continue;
		as+=dfs1(g[u][i],u);
	}
	if(as>1){
		ans+=(as-1);
		return 0;
	}
	return 1;
}
int in[200005];
int main() {
	int n,u,v;
	ll x,y;
	cin>>n>>x>>y;
	fr(i,1,n-1)s(u),s(v),in[u]++,in[v]++,g[u].pb(v),g[v].pb(u);
	dfs1(1,-1);
	ll r=0;
	//cout<<ans<<endl;
	if(x<=y)
		r= (n-ans-1LL)*x*1LL + (ans)*1LL*y;
	else
	{
		int maxi=0;
		fr(i,1,n)maxi=max(maxi,in[i]);
		//cout<<maxi<<endl;
		if(maxi==(n-1))
			r= (n-2LL)*y+ x;
		else r=(n-1LL)*y;
	}
	cout<<r<<endl;
	return 0;
}


#include<bits/stdc++.h>//freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
using namespace std;
#define ll long long
#define mem(x,a) memset(x,a,sizeof(x))
#define pii pair<int,int>
#define fr(i,a,n) for(int i=(a);i<=(n);i++)
#define frd(i,a,n) for(int i=(a);i>=(n);i--)
#define s(n) scanf("%d",&(n))
#define sl(n) scanf("%lld",&(n))
#define nl printf("\n")
#define sp printf(" ")
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define V vector
ll mod=1e9+7;
ll ans;
int in[200005];
V<int> g[200005];
ll dfs1(int u,int p)
{
	ll as=0;
	for(int i=0;i<g[u].size();i++){
		if(g[u][i] != p)as+=dfs1(g[u][i],u);
	}
	if(as>1){
		ans+=(as-1LL);
		return 0;
	}
	return 1LL;
}
int main() {
	ll n,u,v;
	ll x,y;
	cin>>n>>x>>y;
	fr(i,1,n-1)s(u),s(v),in[u]++,in[v]++,g[u].pb(v),g[v].pb(u);
	ans+=dfs1(1,-1);
	ll r=0;
	//cout<<ans<<endl;
	if(x<=y)
		r= (n-ans-1LL)*x*1LL + (ans)*1LL*y;
	else
	{
		int maxi=0;
		fr(i,1,n)maxi=max(maxi,in[i]);
		//cout<<maxi<<endl;
		if(maxi==(n-1))
			r= (n-2LL)*y+ x;
		else r=(n-1LL)*y;
	}
	cout<<r<<endl;
	return 0;
}


#include<bits/stdc++.h>//freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
using namespace std;
#define ll long long
#define mem(x,a) memset(x,a,sizeof(x))
#define pii pair<int,int>
#define fr(i,a,n) for(int i=(a);i<=(n);i++)
#define frd(i,a,n) for(int i=(a);i>=(n);i--)
#define s(n) scanf("%d",&(n))
#define sl(n) scanf("%lld",&(n))
#define nl printf("\n")
#define sp printf(" ")
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define V vector
ll mod=1e9+7;
ll ans;
int in[200005];
V<int> g[200005];
ll dfs1(int u,int p)
{
	ll as=0;
	for(int i=0;i<g[u].size();i++){
		if(g[u][i] != p)as+=dfs1(g[u][i],u);
	}
	if(as>1){
		ans+=(as-1LL);
		return 0;
	}
	return 1LL;
}
int main() {
	ll n,u,v;
	ll x,y;
	cin>>n>>x>>y;
	fr(i,1,n-1)s(u),s(v),in[u]++,in[v]++,g[u].pb(v),g[v].pb(u);
	ll r=0;
	//cout<<ans<<endl;
	if(x<=y)
		ans+=dfs1(1,-1),ans--,r= (n-ans-1LL)*x*1LL + (ans)*1LL*y;
	else
	{
		int maxi=0;
		fr(i,1,n)maxi=max(maxi,in[i]);
		//cout<<maxi<<endl;
		if(maxi==(n-1))
			r= (n-2LL)*y+ x;
		else r=(n-1LL)*y;
	}
	cout<<r<<endl;
	return 0;
}


#include<bits/stdc++.h>//freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
using namespace std;
#define ll long long
#define mem(x,a) memset(x,a,sizeof(x))
#define pii pair<int,int>
#define fr(i,a,n) for(int i=(a);i<=(n);i++)
#define frd(i,a,n) for(int i=(a);i>=(n);i--)
#define s(n) scanf("%d",&(n))
#define sl(n) scanf("%lld",&(n))
#define nl printf("\n")
#define sp printf(" ")
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define V vector
ll mod=1e9+7;
ll ans;
int in[200005];
V<int> g[200005];
ll dfs1(int u,int p)
{
	ll as=0;
	for(int i=0;i<g[u].size();i++){
		if(g[u][i] == p)continue;
		as+=dfs1(g[u][i],u);
	}
	if(as>1){
		ans+=(as-1LL);
		return 0;
	}
	return 1LL;
}
int main() {
	ll n,u,v;
	ll x,y;
	cin>>n>>x>>y;
	fr(i,1,n-1)s(u),s(v),in[u]++,in[v]++,g[u].pb(v),g[v].pb(u);
	dfs1(1,-1);
	ll r=0;
	//cout<<ans<<endl;
	if(x<=y)
		r= (n-ans-1LL)*x*1LL + (ans)*1LL*y;
	else
	{
		int maxi=0;
		fr(i,1,n)maxi=max(maxi,in[i]);
		//cout<<maxi<<endl;
		if(maxi==(n-1))
			r= (n-2LL)*y+ x;
		else r=(n-1LL)*y;
	}
	cout<<r<<endl;
	return 0;
}


#include <bits/stdc++.h>
#define  pb             push_back
#define  mp             make_pair
#define  MAX            200005
#define  INF            0x3fffffffffffffff
#define  MAXLOG         18
#define  MOD            1000000007LL

using namespace std;
typedef long long ll;
typedef vector<vector<int> > graph;
graph G;
bool seen[MAX], xd[MAX];

ll go ( int u ) {
    seen[u] = 1;
    int c = 0;
    ll best = 0;
    for ( int i = 0; i < G[u].size(); ++i ) {
        int v = G[u][i];
        if ( !seen[v] ) {
            best += go(v);
            c += xd[v];
        }
    }
    if ( c > 1 ) {
        best += 2;
        xd[u] = 0;
    } else if ( c == 1 )
        ++best;
    return best;
}

int main ( ) {
    cin.tie(0);
    ios_base::sync_with_stdio(0);

    int u, v;
    ll n, x, y;
    cin >> n >> x >> y;
    G = graph(n + 1);

    for ( int i = 1; i < n; ++i ) {
        cin >> u >> v;
        G[u].pb(v);
        G[v].pb(u);
    }

    if ( x < y ) {
        memset(seen, 0, sizeof seen);
        memset(xd, 1, sizeof xd);
        ll best = go(1);
        cout << best * x + y * (n - best - 1) << '\n';
    } else {
        bool special = false;
        for ( int i = 1; i <= n; ++i ) special |= G[i].size() == n - 1;
        cout << ( !special ? y * (n - 1) : y * (n - 2) + x ) << '\n';
    }
}


#include <bits/stdc++.h>
#define  pb             push_back
#define  mp             make_pair
#define  MAX            200005
#define  INF            0x3fffffffffffffff
#define  MAXLOG         18
#define  MOD            1000000007LL

using namespace std;
typedef long long ll;
typedef vector<vector<int> > graph;
graph G;
ll dp[MAX], depth[MAX];

ll go ( int u ) {
    dp[u] = depth[u] = 0;
    int xd = 0;
    for ( int i = 0; i < G[u].size(); ++i ) {
        int v = G[u][i];
        ll best_v;
        if ( dp[v] == -1 ) {
            best_v = go(v);
            depth[u] = max(depth[u], depth[v] + 1);
            if ( best_v == depth[v] ) ++xd;
        } else
            best_v = dp[v];
        dp[u] += best_v;
    }
    if ( xd ) dp[u] += ( xd > 1 ? 2 : 1 );
    return dp[u];
}

int main ( ) {
    cin.tie(0);
    ios_base::sync_with_stdio(0);

    int u, v;
    ll n, x, y;
    cin >> n >> x >> y;
    G = graph(n + 1);

    for ( int i = 1; i < n; ++i ) {
        cin >> u >> v;
        G[u].pb(v);
        G[v].pb(u);
    }

    if ( x < y ) {
        memset(dp, -1, sizeof dp);
        ll best = go(1);
        cout << best * x + y * (n - best - 1) << '\n';
    } else {
        cout << y * (n - 1) << '\n';
    }
}


#include <bits/stdc++.h>
#define  pb             push_back
#define  mp             make_pair
#define  MAX            200005
#define  INF            0x3fffffffffffffff
#define  MAXLOG         18
#define  MOD            1000000007LL

using namespace std;
typedef long long ll;
typedef vector<vector<int> > graph;
graph G;
bool seen[MAX], xd[MAX];

ll go ( int u ) {
    seen[u] = 1;
    int c = 0;
    ll best = 0;
    for ( int i = 0; i < G[u].size(); ++i ) {
        int v = G[u][i];
        if ( !seen[v] ) {
            best += go(v);
            c += xd[v];
        }
    }
    if ( c > 1 ) {
        best += 2;
        xd[u] = 0;
    } else if ( c == 1 )
        ++best;
    return best;
}

int main ( ) {
    cin.tie(0);
    ios_base::sync_with_stdio(0);

    int u, v;
    ll n, x, y;
    cin >> n >> x >> y;
    G = graph(n + 1);

    for ( int i = 1; i < n; ++i ) {
        cin >> u >> v;
        G[u].pb(v);
        G[v].pb(u);
    }

    if ( x < y ) {
        memset(seen, 0, sizeof seen);
        memset(xd, 1, sizeof xd);
        ll best = go(1);
        cout << best * x + y * (n - best - 1) << '\n';
    } else {
        bool special = false;
        for ( int i = 1; i <= n; ++i ) special |= G[i].size() == n;
        cout << ( !special ? y * (n - 1) : y * (n - 2) + x ) << '\n';
    }
}


#include <bits/stdc++.h>
#define  pb             push_back
#define  mp             make_pair
#define  MAX            200005
#define  INF            0x3fffffffffffffff
#define  MAXLOG         18
#define  MOD            1000000007LL

using namespace std;
typedef long long ll;
typedef vector<vector<int> > graph;
graph G;
ll dp[MAX], depth[MAX];

ll go ( int u ) {
    dp[u] = depth[u] = 0;
    int xd = 0;
    for ( int i = 0; i < G[u].size(); ++i ) {
        int v = G[u][i];
        ll best_v = 0;
        if ( dp[v] == -1 ) {
            best_v = go(v);
            depth[u] = max(depth[u], depth[v] + 1);
            if ( best_v == depth[v] ) ++xd;
        }
        dp[u] += best_v;
    }
    if ( depth[u] ) dp[u] += ( xd > 1 ? 2 : 1 );
    return dp[u];
}

int main ( ) {
    cin.tie(0);
    ios_base::sync_with_stdio(0);

    int u, v;
    ll n, x, y;
    cin >> n >> x >> y;
    G = graph(n + 1);

    for ( int i = 1; i < n; ++i ) {
        cin >> u >> v;
        G[u].pb(v);
        G[v].pb(u);
    }

    if ( x < y ) {
        memset(dp, -1, sizeof dp);
        ll best = go(1);
        cout << best * x + y * (n - best - 1) << '\n';
    } else {
        cout << y * (n - 1) << '\n';
    }
}


#include <bits/stdc++.h>
#define  pb             push_back
#define  mp             make_pair
#define  MAX            200005
#define  INF            0x3fffffffffffffff
#define  MAXLOG         18
#define  MOD            1000000007LL

using namespace std;
typedef long long ll;
typedef vector<vector<int> > graph;
graph G;
ll dp[MAX], depth[MAX];

ll go ( int u ) {
    dp[u] = depth[u] = 0;
    int xd = 0;
    for ( int i = 0; i < G[u].size(); ++i ) {
        int v = G[u][i];
        ll best_v;
        if ( dp[v] == -1 ) {
            best_v = go(v);
            depth[u] = max(depth[u], depth[v] + 1);
            if ( best_v == depth[v] ) ++xd;
        } else
            best_v = dp[v];
        dp[u] += best_v;
    }
    if ( xd ) dp[u] += ( xd > 1 ? 2 : 1 );
    return dp[u];
}

int main ( ) {
    cin.tie(0);
    ios_base::sync_with_stdio(0);

    int u, v;
    ll n, x, y;
    cin >> n >> x >> y;
    G = graph(n + 1);

    for ( int i = 1; i < n; ++i ) {
        cin >> u >> v;
        G[u].pb(v);
        G[v].pb(u);
    }

    if ( x < y ) {
        memset(dp, -1, sizeof dp);
        ll best = go(1);

        for ( int i = 1; i <= n; ++i )
            if ( dp[i] < 0 )
                cout << "Lel\n";

        cout << best * x + y * (n - best - 1) << '\n';
    } else {
        cout << y * (n - 1) << '\n';
    }
}


#include <bits/stdc++.h>
#define  pb             push_back
#define  mp             make_pair
#define  MAX            200005
#define  INF            0x3fffffffffffffff
#define  MAXLOG         18
#define  MOD            1000000007LL

using namespace std;
typedef long long ll;
typedef vector<vector<int> > graph;
graph G;
bool seen[MAX], xd[MAX];

ll go ( int u ) {
    seen[u] = 1;
    int c = 0;
    ll best = 0;
    for ( int i = 0; i < G[u].size(); ++i ) {
        int v = G[u][i];
        if ( !seen[v] ) {
            best += go(v);
            c += xd[v];
        }
    }
    if ( c > 1 ) {
        best += 2;
        xd[u] = 0;
    } else if ( c == 1 )
        ++best;
    return best;
}

int main ( ) {
    cin.tie(0);
    ios_base::sync_with_stdio(0);

    int u, v;
    ll n, x, y;
    cin >> n >> x >> y;
    G = graph(n + 1);

    for ( int i = 1; i < n; ++i ) {
        cin >> u >> v;
        G[u].pb(v);
        G[v].pb(u);
    }

    if ( x < y ) {
        memset(seen, 0, sizeof seen);
        memset(xd, 1, sizeof xd);
        ll best = go(1);
        cout << best * x + y * (n - best - 1) << '\n';
    } else {
        cout << y * (n - 1) << '\n';
    }
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
#include <cstring>
#include <queue>
using namespace std;

#define pb push_back
typedef long long ll;

ll n;
ll x, y, ans;

vector<int>G[200005];
int cover;
int dp[200005][2];

void dfs(int x, int from){
	int delt = 0, delt1 = 0, tot = 0;
	for(int i = 0; i < G[x].size(); ++i){
		int y = G[x][i];
		if(y == from) continue;
		dfs(y, x);
		if(dp[y][1]-dp[y][0] > delt){
			delt1 = delt;
			delt = dp[y][1]-dp[y][0];
		}
		else if(dp[y][1]-dp[y][0] > delt1){
			delt1 = dp[y][1] - dp[y][0];
		}
		tot += dp[y][0];
	}
	dp[x][0] = tot + delt + delt1;
	dp[x][1] = tot + delt + 1;
}

int main () {
	cin >> n >> x >> y;
	int de[200005] = {};
	int s = 0;
	for(int i = 0; i < n-1; ++i){
		int a, b;
		scanf("%d%d", &a, &b);
		de[a]++;
		de[b]++;
		if(!s) s = a;
		G[a].pb(b);
		G[b].pb(a);
	}
	if(x == y) {
		ans = x * (n-1);
	}
	else if(x < y){
		memset(dp, 0, sizeof(dp));
		dfs(1, 1);
		cover = dp[1][0];
//		for(int j = 1; j <= n; ++j) cout << j << ' '<<dp[j][0] << ' ' <<dp[j][1] <<endl;
		ans = cover*x + y *(n-1-cover);
	}
	else {
		int ok = 0;
		for(int i = 1; i <= n; ++i){
			if(de[i] == n-1){
				ok = 1;
				break;
			}
		}
		if(ok){
			ans = y * (n-2) + x;
		}
		else ans = y * (n-1);
	}
	printf("%lld\n" ,ans);
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
#include <cstring>
#include <queue>
using namespace std;

#define pb push_back
typedef long long ll;

int n;
ll x, y, ans;

vector<int>G[200005];

int main () {
	cin >> n >> x >> y;
	int de[200005] = {};
	int s = 0;
	for(int i = 0; i < n-1; ++i){
		int a, b;
		scanf("%d%d", &a, &b);
		de[a]++;
		de[b]++;
		if(!s) s = a;
		G[a].pb(b);
		G[b].pb(a);
	}
	if(x == y) {
		ans = x * (n-1);
	}
	else if(x < y){
		queue<int>q;
		int dis[200005];
		memset(dis, -1, sizeof(dis));
		dis[s] = 0;
		int p;
		q.push(s);
		while(!q.empty()){
			int fr = q.front();
			q.pop();
			for(int i = 0; i < G[ele.p].size(); ++i){
				int to = G[ele.p][i];
				if(dis[to] != -1) continue;
				dis[to] = dis[fr]+1;
				q.push(to);
			}
		}
		int far = -1;
		for(int i = 1; i <= n; ++i) if(dis[i] > far){
			far = dis[i];
			p = i;
		}
		q.push(p);
		memset(dis, -1, sizeof(dis));
		dis[p] = 0;
		while(!q.empty()){
			int fr = q.front();
			q.pop();
			for(int i = 0; i < G[ele.p].size(); ++i){
				int to = G[ele.p][i];
				if(dis[to] != -1) continue;
				dis[to] = dis[fr]+1;
				q.push(to);
			}
		}
		for(int i = 1; i <= n; ++i) if(dis[i] > far){
			far = dis[i];
		}
		ans = far * x + y * (n-1-far);
	}
	else {
		int ok = 0;
		for(int i = 1; i <= n; ++i){
			if(de[i] == n-1){
				ok = 1;
				break;
			}
		}
		if(ok){
			ans = y * (n-2) + x;
		}
		else ans = y * (n-1);
	}
	printf("%I64d\n" ,ans);
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
#include <cstring>
using namespace std;

#define pb push_back
typedef long long ll;

int n;
ll x, y;

int main () {
	cin >> n >> x >> y;
	int de[200005] = {};
	for(int i = 0; i < n-1; ++i){
		int a, b;
		scanf("%d%d", &a, &b);
		++de[a];
		++de[b];
	}
	if(n == 2) {
		cout << x << endl;
		return 0;
	}
	ll ans;
	if(x < y){
		int two = 0, one = 0;
		for(int i = 0; i < n; ++i) if(de[i] >= 2) two++;
	//	cout << two <<endl;
		ans = min(two+1, n-1)*x + max(n-two-2, 0)*y;
	}
	else {
		int two = 0;
		for(int i = 0; i < n; ++i) if(n-1-de[i] >= 2) two++;
		//cout << two <<endl;
		ans = min(two+1, n-1)*y + max(n-two-2, 0)*x;
	}
	printf("%lld\n" ,ans);
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
#include <cstring>
#include <queue>
using namespace std;

#define pb push_back
typedef long long ll;

ll n;
ll x, y, ans;

vector<int>G[200005];

int main () {
	cin >> n >> x >> y;
	int de[200005] = {};
	int s = 0;
	for(int i = 0; i < n-1; ++i){
		int a, b;
		scanf("%d%d", &a, &b);
		de[a]++;
		de[b]++;
		if(!s) s = a;
		G[a].pb(b);
		G[b].pb(a);
	}
	if(x == y) {
		ans = x * (n-1);
	}
	else if(x < y){
		queue<int>q;
		int dis[200005];
		memset(dis, -1, sizeof(dis));
		dis[s] = 0;
		int p;
		q.push(s);
		while(!q.empty()){
			int fr = q.front();
			q.pop();
			for(int i = 0; i < G[fr].size(); ++i){
				int to = G[fr][i];
				if(dis[to] != -1) continue;
				dis[to] = dis[fr]+1;
				q.push(to);
			}
		}
		ll far = -1;
		for(int i = 1; i <= n; ++i) if(dis[i] > far){
			far = dis[i];
			p = i;
		}
		q.push(p);
		memset(dis, -1, sizeof(dis));
		dis[p] = 0;
		while(!q.empty()){
			int fr = q.front();
			q.pop();
			for(int i = 0; i < G[fr].size(); ++i){
				int to = G[fr][i];
				if(dis[to] != -1) continue;
				dis[to] = dis[fr]+1;
				q.push(to);
			}
		}
		for(int i = 1; i <= n; ++i) if(dis[i] > far){
			far = dis[i];
		}
		ans = far * x + y * (n-1-far);
	}
	else {
		int ok = 0;
		for(int i = 1; i <= n; ++i){
			if(de[i] == n-1){
				ok = 1;
				break;
			}
		}
		if(ok && n !=3){
			ans = y * (n-2) + x;
		}
		else if(ok && n == 3){
			ans = x * 2 + y;
		}
		else ans = y * (n-1);
	}
	printf("%lld\n" ,ans);
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
#include <cstring>
#include <queue>
using namespace std;

#define pb push_back
typedef long long ll;

ll n;
ll x, y, ans;

vector<int>G[200005];
int cover;

int dfs(int x, int from){
	int degree = 0;
	for(int i = 0; i < G[x].size(); ++i){
		int y = G[x][i];
		if(y == from) continue;
		degree += dfs(y, x);
	}
	if(degree > 1){
		cover += 2;
		return 0;
	}
	cover += degree;
	return 1;
}

int main () {
	cin >> n >> x >> y;
	int de[200005] = {};
	int s = 0;
	for(int i = 0; i < n-1; ++i){
		int a, b;
		scanf("%d%d", &a, &b);
		de[a]++;
		de[b]++;
		if(!s) s = a;
		G[a].pb(b);
		G[b].pb(a);
	}
	if(x == y) {
		ans = x * (n-1);
	}
	else if(x < y){
		cover = 0;
		dfs(1, 1);
		//cout << "XD " << cover <<endl;
		ans = cover*x + y *(n-1-cover);
	}
	else {
		int ok = 0;
		for(int i = 1; i <= n; ++i){
			if(de[i] == n-1){
				ok = 1;
				break;
			}
		}
		if(ok){
			ans = y * (n-2) + x;
		}
		else ans = y * (n-1);
	}
	printf("%lld\n" ,ans);
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
#include <cstring>
#include <queue>
using namespace std;

#define pb push_back
typedef long long ll;

int n;
ll x, y, ans;

vector<int>G[200005];

int main () {
	cin >> n >> x >> y;
	int de[200005] = {};
	int s = 0;
	for(int i = 0; i < n-1; ++i){
		int a, b;
		scanf("%d%d", &a, &b);
		de[a]++;
		de[b]++;
		if(!s) s = a;
		G[a].pb(b);
		G[b].pb(a);
	}
	if(x == y) {
		ans = x * (n-1);
	}
	else if(x < y){
		queue<int>q;
		int dis[200005];
		memset(dis, -1, sizeof(dis));
		dis[s] = 0;
		int p;
		q.push(s);
		while(!q.empty()){
			int fr = q.front();
			q.pop();
			for(int i = 0; i < G[fr].size(); ++i){
				int to = G[fr][i];
				if(dis[to] != -1) continue;
				dis[to] = dis[fr]+1;
				q.push(to);
			}
		}
		int far = -1;
		for(int i = 1; i <= n; ++i) if(dis[i] > far){
			far = dis[i];
			p = i;
		}
		q.push(p);
		memset(dis, -1, sizeof(dis));
		dis[p] = 0;
		while(!q.empty()){
			int fr = q.front();
			q.pop();
			for(int i = 0; i < G[fr].size(); ++i){
				int to = G[fr][i];
				if(dis[to] != -1) continue;
				dis[to] = dis[fr]+1;
				q.push(to);
			}
		}
		for(int i = 1; i <= n; ++i) if(dis[i] > far){
			far = dis[i];
		}
		ans = far * x + y * (n-1-far);
	}
	else {
		int ok = 0;
		for(int i = 1; i <= n; ++i){
			if(de[i] == n-1){
				ok = 1;
				break;
			}
		}
		if(ok){
			ans = y * (n-2) + x;
		}
		else ans = y * (n-1);
	}
	printf("%I64d\n" ,ans);
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
#include <cstring>
#include <queue>
using namespace std;

#define pb push_back
typedef long long ll;

int n;
ll x, y, ans;

struct A{
	int stp, p;
}ele;

vector<int>G[200005];

int main () {
	cin >> n >> x >> y;
	int de[200005] = {};
	int s = 0;
	for(int i = 0; i < n-1; ++i){
		int a, b;
		scanf("%d%d", &a, &b);
		de[a]++;
		de[b]++;
		if(!s) s = a;
		G[a].pb(b);
		G[b].pb(a);
	}
	if(x < y){
		queue<A>q;
		ele.p = s;
		ele.stp = 0;
		int dis[200005];
		memset(dis, -1, sizeof(dis));
		dis[s] = 0;
		int p;
		q.push(ele);
		while(!q.empty()){
			ele = q.front();
			q.pop();
			for(int i = 0; i < G[ele.p].size(); ++i){
				int to = G[ele.p][i];
				if(dis[to] != -1) continue;
				dis[to] = ele.stp+1;
				A re;
				re.p = to;
				re.stp = ele.stp + 1;
				q.push(re);
			}
		}
		int far = -1;
		for(int i = 1; i <= n; ++i) if(dis[i] > far){
			far = dis[i];
			p = i;
		}
		ele.p = p;
		ele.stp = 0;
		q.push(ele);
		memset(dis, -1, sizeof(dis));
		dis[p] = 0;
		while(!q.empty()){
			ele = q.front();
			q.pop();
			for(int i = 0; i < G[ele.p].size(); ++i){
				int to = G[ele.p][i];
				if(dis[to] != -1) continue;
				dis[to] = ele.stp+1;
				A re;
				re.p = to;
				re.stp = ele.stp + 1;
				q.push(re);
			}
		}
		for(int i = 1; i <= n; ++i) if(dis[i] > far){
			far = dis[i];
		}
		ans = far * x + y * (n-1-far);
	}
	else {
		int ok = 0;
		for(int i = 1; i <= n; ++i){
			if(de[i] == n-1){
				ok = 1;
				break;
			}
		}
		if(ok){
			ans = y * (n-2) + x;
		}
		else ans = y * (n-1);
	}
	printf("%lld\n" ,ans);
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
#include <cstring>
#include <queue>
using namespace std;

#define pb push_back
typedef long long ll;

ll n;
ll x, y, ans;

vector<int>G[200005];

int main () {
	cin >> n >> x >> y;
	int de[200005] = {};
	int s = 0;
	for(int i = 0; i < n-1; ++i){
		int a, b;
		scanf("%d%d", &a, &b);
		de[a]++;
		de[b]++;
		if(!s) s = a;
		G[a].pb(b);
		G[b].pb(a);
	}
	if(x == y) {
		ans = x * (n-1);
	}
	else if(x < y){
		queue<int>q;
		int dis[200005];
		memset(dis, -1, sizeof(dis));
		dis[s] = 0;
		int p;
		q.push(s);
		while(!q.empty()){
			int fr = q.front();
			q.pop();
			for(int i = 0; i < G[fr].size(); ++i){
				int to = G[fr][i];
				if(dis[to] != -1) continue;
				dis[to] = dis[fr]+1;
				q.push(to);
			}
		}
		ll far = -1;
		for(int i = 1; i <= n; ++i) if(dis[i] > far){
			far = dis[i];
			p = i;
		}
		q.push(p);
		memset(dis, -1, sizeof(dis));
		dis[p] = 0;
		while(!q.empty()){
			int fr = q.front();
			q.pop();
			for(int i = 0; i < G[fr].size(); ++i){
				int to = G[fr][i];
				if(dis[to] != -1) continue;
				dis[to] = dis[fr]+1;
				q.push(to);
			}
		}
		for(int i = 1; i <= n; ++i) if(dis[i] > far){
			far = dis[i];
		}
		ans = far * x + y * (n-1-far);
	}
	else {
		int ok = 0;
		for(int i = 1; i <= n; ++i){
			if(de[i] == n-1){
				ok = 1;
				break;
			}
		}
		if(ok){
			ans = y * (n-2) + x;
		}
		else ans = y * (n-1);
	}
	printf("%lld\n" ,ans);
}


#include <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>
#include <cstdio>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << endl
#define _ << " _ " <<

typedef long long llint;

const int MAXN = 200100;

vector<int> E[MAXN];
llint f[MAXN], g[MAXN];
int n, c1, c2;

void solve(int x, int dad) {
  vector<int> v;
  llint total = 0;
  for (int y: E[x]) {
    if (y == dad) continue;
    solve(y, x);
    v.push_back(c1 + g[y] - f[y]);
    total += f[y];
  }

  sort(v.begin(), v.end());

  f[x] = g[x] = total;
  if (v.size() > 0) {
    f[x] += v[0], g[x] += v[0];
    g[x] += ((int)v.size()-1)*llint(c2);
  }
  if (v.size() > 1) {
    f[x] += v[1];
    f[x] += ((int)v.size()-2)*llint(c2);
  }
}

int main(void) {
  scanf("%d %d %d", &n, &c1, &c2);
  REP(i, n-1) {
    int a, b;
    scanf("%d %d", &a, &b);
    --a, --b;
    E[a].push_back(b);
    E[b].push_back(a);
  }

  solve(0, -1);
  llint ans = min(llint(n-1)*c2, f[0]);
  printf("%lld\n", ans);
  return 0;
}


#include <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>
#include <cstdio>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << endl
#define _ << " _ " <<

typedef long long llint;

const int MAXN = 200100;

vector<int> E[MAXN];
llint f[MAXN], g[MAXN];
int n, c1, c2;

void solve(int x, int dad) {
  vector<llint> v;
  llint total = 0;
  for (int y: E[x]) {
    if (y == dad) continue;
    solve(y, x);
    v.push_back(c1 - c2 + g[y] - f[y]);
    total += f[y];
  }
  total += (llint)v.size()*c2;

  sort(v.begin(), v.end());

  f[x] = g[x] = total;
  if (v.size() > 0 && v[0] < 0) f[x] += v[0], g[x] += v[0];
  if (v.size() > 1 && v[1] < 0) f[x] += v[1];
}

int main(void) {
  scanf("%d %d %d", &n, &c1, &c2);
  REP(i, n-1) {
    int a, b;
    scanf("%d %d", &a, &b);
    --a, --b;
    E[a].push_back(b);
    E[b].push_back(a);
  }

  solve(0, -1);

  llint cost1 = llint(n-1)*c2;
  REP(i, n)
    if ((int)E[i].size() == n-1) cost1 += c1 - c2;
  llint ans = min(cost1, f[0]);
  printf("%lld\n", ans);
  return 0;
}


#include <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>
#include <cstdio>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << endl
#define _ << " _ " <<

typedef long long llint;

const int MAXN = 200100;

vector<int> E[MAXN];
llint f[MAXN], g[MAXN];
int n, c1, c2;

void solve(int x, int dad) {
  vector<llint> v;
  llint total = 0;
  for (int y: E[x]) {
    if (y == dad) continue;
    solve(y, x);
    v.push_back(c1 - c2 + g[y] - f[y]);
    total += f[y];
  }
  total += (llint)v.size()*c2;

  sort(v.begin(), v.end());

  f[x] = g[x] = total;
  if (v.size() > 0 && v[0] < 0) f[x] += v[0], g[x] += v[0];
  if (v.size() > 1 && v[1] < 0) f[x] += v[1];
}

int main(void) {
  scanf("%d %d %d", &n, &c1, &c2);
  REP(i, n-1) {
    int a, b;
    scanf("%d %d", &a, &b);
    --a, --b;
    E[a].push_back(b);
    E[b].push_back(a);
  }

  solve(0, -1);

  llint cost1 = llint(n-1)*c2;
  REP(i, n)
    if ((int)E[i].size() == n-1) { cost1 += c1 - c2; break; }
  llint ans = min(cost1, f[0]);
  printf("%lld\n", ans);
  return 0;
}


#include <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>
#include <cstdio>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << endl
#define _ << " _ " <<

typedef long long llint;

const int MAXN = 200100;

vector<int> E[MAXN];
llint f[MAXN], g[MAXN];
int n, c1, c2;

void solve(int x, int dad) {
  vector<llint> v;
  llint total = 0;
  for (int y: E[x]) {
    if (y == dad) continue;
    solve(y, x);
    v.push_back(c1 + g[y] - f[y]);
    total += f[y];
  }

  sort(v.begin(), v.end());

  f[x] = g[x] = total;
  if (v.size() > 0) {
    f[x] += v[0], g[x] += v[0];
    g[x] += ((int)v.size()-1)*llint(c2);
  }
  if (v.size() > 1) {
    f[x] += v[1];
    f[x] += ((int)v.size()-2)*llint(c2);
  }
}

int main(void) {
  scanf("%d %d %d", &n, &c1, &c2);
  REP(i, n-1) {
    int a, b;
    scanf("%d %d", &a, &b);
    --a, --b;
    E[a].push_back(b);
    E[b].push_back(a);
  }

  solve(0, -1);
  llint ans = min(llint(n-1)*c2, f[0]);
  printf("%lld\n", ans);
  return 0;
}


#include <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>
#include <cstdio>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << endl
#define _ << " _ " <<

typedef long long llint;

const int MAXN = 200100;

vector<int> E[MAXN];
llint f[MAXN], g[MAXN];
int n, c1, c2;

void solve(int x, int dad) {
  vector<llint> v;
  llint total = 0;
  for (int y: E[x]) {
    if (y == dad) continue;
    solve(y, x);
    v.push_back(c1 - c2 + g[y] - f[y]);
    total += f[y];
  }
  total += (llint)v.size()*c2;

  sort(v.begin(), v.end());

  f[x] = g[x] = total;
  if (v.size() > 0) f[x] += v[0], g[x] += v[0];
  if (v.size() > 1) f[x] += v[1];
}

int main(void) {
  scanf("%d %d %d", &n, &c1, &c2);
  REP(i, n-1) {
    int a, b;
    scanf("%d %d", &a, &b);
    --a, --b;
    E[a].push_back(b);
    E[b].push_back(a);
  }

  solve(0, -1);

  llint cost1 = llint(n-1)*c2;
  REP(i, n)
    if ((int)E[i].size() == n-1) { cost1 += c1 - c2; break; }
  llint ans = min(cost1, f[0]);
  printf("%lld\n", ans);
  return 0;
}


#include <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>
#include <cstdio>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << endl
#define _ << " _ " <<

typedef long long llint;

const int MAXN = 200100;

vector<int> E[MAXN];
llint f[MAXN], g[MAXN];
int n, c1, c2;

void solve(int x, int dad) {
  vector<llint> v;
  llint total = 0;
  for (int y: E[x]) {
    if (y == dad) continue;
    solve(y, x);
    v.push_back(c1 - c2 + g[y] - f[y]);
    total += f[y];
  }
  total += (llint)v.size()*c2;

  sort(v.begin(), v.end());

  f[x] = g[x] = total;
  if (v.size() > 0 && v[0] < 0) f[x] += v[0], g[x] += v[0];
  if (v.size() > 1 && v[1] < 0) f[x] += v[1];
}

int main(void) {
  scanf("%d %d %d", &n, &c1, &c2);
  REP(i, n-1) {
    int a, b;
    scanf("%d %d", &a, &b);
    --a, --b;
    E[a].push_back(b);
    E[b].push_back(a);
  }

  solve(0, -1);
  llint ans = min(llint(n-1)*c2, f[0]);
  printf("%lld\n", ans);
  return 0;
}


#include <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>
#include <cstdio>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << endl
#define _ << " _ " <<

typedef long long llint;

const int MAXN = 200100;

int deg[MAXN];

int main(void) {
  int n, x, y;
  scanf("%d %d %d", &n, &x, &y);
  REP(i, n-1) {
    int a, b;
    scanf("%d %d", &a, &b);
    --a, --b;
    deg[a]++, deg[b]++;
  }

  int nl = 0;
  REP(i, n) nl += deg[i] == 1;

  llint ans = min(llint(n-1)*y, llint(nl-2)*y + llint(n-nl+1)*x);
  printf("%lld\n", ans);
  return 0;
}


#define LL long long
#include<bits/stdc++.h>
using namespace std;
const LL maxn=200000+5;
LL dp[maxn][4];
vector<int> G[maxn];
LL deg[maxn];
void dfs(LL now,LL fa)
{
    for(LL i=0;i<G[now].size();i++) if(G[now][i]!=fa) dfs(G[now][i],now);
    dp[now][0]=dp[now][1]=dp[now][2]=dp[now][3]=0;

    LL best1=0,best2=0;
    for(LL i=0;i<G[now].size();i++)
    {
        int& to=G[now][i];
        if(to==fa) continue;
        dp[now][0]+=dp[to][3];
        if(best1==0) best1=to;
        else if(best2==0)
        {
            if((max(dp[to][0],dp[to][1])-dp[to][3])>(max(dp[best1][0],dp[best1][1])-dp[best1][3]))
                swap(best1,best2);
            best1=to;
        }
        else if((max(dp[to][0],dp[to][1])-dp[to][3])>(max(dp[best1][0],dp[best1][1])-dp[best1][3]))
        {
            swap(best1,best2);
            best2=to;
        }
        else if((max(dp[to][0],dp[to][1])-dp[to][3])>(max(dp[best2][0],dp[best2][1])-dp[best2][3]))
            best2=to;
    }
    if(best1) dp[now][1]=1+dp[now][0]-dp[best1][3]+max(dp[best1][0],dp[best1][1]);
    if(best1 && best2)dp[now][2]=2+dp[now][0]-dp[best1][3]-dp[best2][3]+max(dp[best1][0],dp[best1][1])+max(dp[best2][0],dp[best2][1]);
    dp[now][3]=max(dp[now][0],max(dp[now][1],dp[now][2]));
//    for(LL i=0;i<4;i++) printf("dp[%I64d][%I64d]=%I64d ",now,i,dp[now][i]);puts("");
}
int main()
{
    LL n,x,y;
    scanf("%I64d%I64d%I64d",&n,&x,&y);
    for(LL i=0,a,b;i<n-1;i++)
    {
        scanf("%I64d%I64d",&a,&b);
        G[a].push_back(b);
        G[b].push_back(a);
        deg[a]++,deg[b]++;
    }
    if(x>y) // bad tree edges
    {
        for(LL i=1;i<=n;i++) if(deg[i]==n-1) {printf("%I64d\n",y*(n-2)+x);return 0;}
        printf("%I64d\n",y*(n-1));
    }
    else
    {
        dfs(1,-1);
        printf("%I64d\n",dp[1][3]*x+(n-1-dp[1][3])*y);
    }
}


#define LL long long
#include<bits/stdc++.h>
using namespace std;
const LL maxn=200000+5;
LL dp[maxn][4];
vector<int> G[maxn];
LL deg[maxn];
void dfs(LL now,LL fa)
{
    for(LL i=0;i<G[now].size();i++) if(G[now][i]!=fa) dfs(G[now][i],now);
    dp[now][0]=dp[now][1]=dp[now][2]=dp[now][3]=0;

    LL best1=0,best2=0;
    for(LL i=0;i<G[now].size();i++)
    {
        int& to=G[now][i];
        if(to==fa) continue;
        dp[now][0]+=dp[to][3];
        if(best1==0) best1=to;
        else if(best2==0)
        {
            if((max(dp[to][0],dp[to][1])-dp[to][3])>(max(dp[best1][0],dp[best1][1])-dp[best1][3]))
                swap(best1,best2);
            best2=to;
        }
        else if((max(dp[to][0],dp[to][1])-dp[to][3])>(max(dp[best1][0],dp[best1][1])-dp[best1][3]))
        {
            swap(best1,best2);
            best2=to;
        }
        else if((max(dp[to][0],dp[to][1])-dp[to][3])>(max(dp[best2][0],dp[best2][1])-dp[best2][3]))
            best2=to;
    }
    if(best1) dp[now][1]=1+dp[now][0]-dp[best1][3]+max(dp[best1][0],dp[best1][1]);
    if(best1 && best2)dp[now][2]=2+dp[now][0]-dp[best1][3]-dp[best2][3]+max(dp[best1][0],dp[best1][1])+max(dp[best2][0],dp[best2][1]);
    dp[now][3]=max(dp[now][0],max(dp[now][1],dp[now][2]));
//    for(LL i=0;i<4;i++) printf("dp[%I64d][%I64d]=%I64d ",now,i,dp[now][i]);puts("");
}
int main()
{
    LL n,x,y;
    scanf("%I64d%I64d%I64d",&n,&x,&y);
    for(LL i=0,a,b;i<n-1;i++)
    {
        scanf("%I64d%I64d",&a,&b);
        G[a].push_back(b);
        G[b].push_back(a);
        deg[a]++,deg[b]++;
    }
    if(x>y) // bad tree edges
    {
        for(LL i=1;i<=n;i++) if(deg[i]==n-1) {printf("%I64d\n",y*(n-2)+x);return 0;}
        printf("%I64d\n",y*(n-1));
    }
    else
    {
        dfs(1,-1);
        printf("%I64d\n",dp[1][3]*x+(n-1-dp[1][3])*y);
    }
}


#define LL long long
#include<bits/stdc++.h>
using namespace std;
const LL maxn=200000+5;
LL dp[maxn][4];
vector<int> G[maxn];
LL deg[maxn];
void dfs(LL now,LL fa)
{
    for(LL i=0;i<G[now].size();i++) if(G[now][i]!=fa) dfs(G[now][i],now);
    dp[now][0]=dp[now][1]=dp[now][2]=dp[now][3]=0;

    LL best1=0,best2=0;
    for(LL i=0;i<G[now].size();i++)
    {
        int& to=G[now][i];
        if(to==fa) continue;
        dp[now][0]+=dp[to][3];
        if(best1==0) best1=to;
        else if(best2==0) best2=to;
        else if((max(dp[to][0],dp[to][1])-dp[to][3])>(max(dp[best1][0],dp[best1][1])-dp[best1][3]))
        {
            swap(best1,best2);
            best2=to;
        }
        else if((max(dp[to][0],dp[to][1])-dp[to][3])>(max(dp[best2][0],dp[best2][1])-dp[best2][3]))
            best2=to;
    }
    if(best1) dp[now][1]=1+dp[now][0]-dp[best1][3]+max(dp[best1][0],dp[best1][1]);
    if(best1 && best2)dp[now][2]=2+dp[now][0]-dp[best1][3]-dp[best2][3]+max(dp[best1][0],dp[best1][1])+max(dp[best2][0],dp[best2][1]);
    dp[now][3]=max(dp[now][0],max(dp[now][1],dp[now][2]));
//    for(LL i=0;i<4;i++) printf("dp[%I64d][%I64d]=%I64d ",now,i,dp[now][i]);puts("");
}
int main()
{
    LL n,x,y;
    scanf("%I64d%I64d%I64d",&n,&x,&y);
    for(LL i=0,a,b;i<n-1;i++)
    {
        scanf("%I64d%I64d",&a,&b);
        G[a].push_back(b);
        G[b].push_back(a);
        deg[a]++,deg[b]++;
    }
    if(x>y) // bad tree edges
    {
        for(LL i=1;i<=n;i++) if(deg[i]==n-1) {printf("%I64d\n",y*(n-2)+x);return 0;}
        printf("%I64d\n",y*(n-1));
    }
    else
    {
        dfs(1,-1);
        printf("%I64d\n",dp[1][3]*x+(n-1-dp[1][3])*y);
    }
}


#define LL long long
#include<bits/stdc++.h>
using namespace std;
const LL maxn=200000+5;
LL dp[maxn][4];
vector<int> G[maxn];
LL deg[maxn];
void dfs(LL now,LL fa)
{
    for(LL i=0;i<G[now].size();i++) if(G[now][i]!=fa) dfs(G[now][i],now);
    dp[now][0]=dp[now][1]=dp[now][2]=dp[now][3]=0;

    LL best1=0,best2=0;
    for(LL i=0;i<G[now].size();i++)
    {
        int& to=G[now][i];
        if(to==fa) continue;
        dp[now][0]+=dp[to][3];
        if(best1==0) best1=to;
        else if(best2==0) best2=to;
        else if((max(dp[to][0],dp[to][1])-dp[to][3])>(max(dp[best1][0],dp[best1][1])-dp[best1][3]))
        {
            swap(best1,best2);
            best2=to;
        }
        else if((max(dp[to][0],dp[to][1])-dp[to][3])>(max(dp[best2][0],dp[best2][1])-dp[best2][3]))
            best2=to;
    }
    if(best1) dp[now][1]=1+dp[now][0]-dp[best1][3]+max(dp[best1][0],dp[best1][1]);
    if(best1 && best2)dp[now][2]=2+dp[now][0]-dp[best1][3]-dp[best2][3]+max(dp[best1][0],dp[best1][1])+max(dp[best2][0],dp[best2][1]);
    dp[now][3]=max(dp[now][0],max(dp[now][1],dp[now][2]));
//    for(LL i=0;i<4;i++) printf("dp[%I64d][%I64d]=%I64d ",now,i,dp[now][i]);puts("");
}
int main()
{
    LL n,x,y;
    scanf("%I64d%I64d%I64d",&n,&x,&y);
    for(LL i=0,a,b;i<n-1;i++)
    {
        scanf("%I64d%I64d",&a,&b);
        G[a].push_back(b);
        G[b].push_back(a);
        deg[a]++,deg[b]++;
    }
    if(x>y) // bad tree edges
    {
        for(LL i=1;i<=n;i++) if(deg[i]==n-1) {printf("%I64d\n",y*(n-2)+x);return 0;}
        printf("%I64d\n",y*(n-1));
    }
    else
    {
        printf("???\n");
        dfs(1,-1);
        printf("%I64d\n",dp[1][3]*x+(n-1-dp[1][3])*y);
    }
}


#define LL long long
#include<bits/stdc++.h>
using namespace std;
const LL maxn=200000+5;
LL dp[maxn][4];
vector<int> G[maxn];
LL deg[maxn];
void dfs(LL now,LL fa)
{
    for(LL i=0;i<G[now].size();i++) if(G[now][i]!=fa) dfs(G[now][i],now);
    dp[now][0]=dp[now][1]=dp[now][2]=dp[now][3]=0;

    LL best1=0,best2=0;
    for(LL i=0;i<G[now].size();i++)
    {
        int& to=G[now][i];
        if(to==fa) continue;
        dp[now][0]+=dp[to][3];
        if(best1==0) best1=to;
        else if(best2==0)
        {
            if((max(dp[to][0],dp[to][1])-dp[to][3])>(max(dp[best1][0],dp[best1][1])-dp[best1][3]))
                best2=best1,best1=to;
            else best2=to;
        }
        else if((max(dp[to][0],dp[to][1])-dp[to][3])>(max(dp[best1][0],dp[best1][1])-dp[best1][3]))
        {
            swap(best1,best2);
            best2=to;
        }
        else if((max(dp[to][0],dp[to][1])-dp[to][3])>(max(dp[best2][0],dp[best2][1])-dp[best2][3]))
            best2=to;
    }
    if(best1) dp[now][1]=1+dp[now][0]-dp[best1][3]+max(dp[best1][0],dp[best1][1]);
    if(best1 && best2)dp[now][2]=2+dp[now][0]-dp[best1][3]-dp[best2][3]+max(dp[best1][0],dp[best1][1])+max(dp[best2][0],dp[best2][1]);
    dp[now][3]=max(dp[now][0],max(dp[now][1],dp[now][2]));
    for(LL i=0;i<4;i++) printf("dp[%I64d][%I64d]=%I64d ",now,i,dp[now][i]);puts("");
}
int main()
{
    LL n,x,y;
    scanf("%I64d%I64d%I64d",&n,&x,&y);
    for(LL i=0,a,b;i<n-1;i++)
    {
        scanf("%I64d%I64d",&a,&b);
        G[a].push_back(b);
        G[b].push_back(a);
        deg[a]++,deg[b]++;
    }
    if(x>y) // bad tree edges
    {
        for(LL i=1;i<=n;i++) if(deg[i]==n-1) {printf("%I64d\n",y*(n-2)+x);return 0;}
        printf("%I64d\n",y*(n-1));
    }
    else
    {
        dfs(1,-1);
        printf("%I64d\n",dp[1][3]*x+(n-1-dp[1][3])*y);
    }
}


#define LL long long
#include<bits/stdc++.h>
using namespace std;
const LL maxn=200000+5;
LL dp[maxn][4];
vector<int> G[maxn];
LL deg[maxn];
void dfs(LL now,LL fa)
{
    for(LL i=0;i<G[now].size();i++) if(G[now][i]!=fa) dfs(G[now][i],now);
    dp[now][0]=dp[now][1]=dp[now][2]=dp[now][3]=0;

    LL best1=0,best2=0;
    for(LL i=0;i<G[now].size();i++)
    {
        int& to=G[now][i];
        if(to==fa) continue;
        dp[now][0]+=dp[to][3];
        if(best1==0) best1=to;
        else if(best2==0) best2=to;
        else if((max(dp[to][0],dp[to][1])-dp[to][3])>(max(dp[best1][0],dp[best1][1])-dp[best1][3]))
        {
            swap(best1,best2);
            best2=to;
        }
        else if((max(dp[to][0],dp[to][1])-dp[to][3])>(max(dp[best2][0],dp[best2][1])-dp[best2][3]))
            best2=to;
    }
    if(best1) dp[now][1]=1+dp[now][0]-dp[best1][3]+max(dp[best1][0],dp[best1][1]);
    if(best1 && best2)dp[now][2]=2+dp[now][0]-dp[best1][3]-dp[best2][3]+max(dp[best1][0],dp[best1][1])+max(dp[best2][0],dp[best2][1]);
    dp[now][3]=max(dp[now][0],max(dp[now][1],dp[now][2]));
//    for(LL i=0;i<4;i++) printf("dp[%I64d][%I64d]=%I64d ",now,i,dp[now][i]);puts("");
}
int main()
{
    LL n,x,y;
    scanf("%I64d%I64d%I64d",&n,&x,&y);
    for(LL i=0,a,b;i<n-1;i++)
    {
        scanf("%I64d%I64d",&a,&b);
        G[a].push_back(b);
        G[b].push_back(a);
        deg[a]++,deg[b]++;
    }
    if(x>y) // bad tree edges
    {
        for(LL i=1;i<=n;i++) if(deg[i]==n-1) {printf("%I64d\n",(LL)y*(n-2)+x);return 0;}
        printf("%I64d\n",(LL)y*(n-1));
    }
    else
    {
        dfs(1,-1);
        printf("%I64d\n",(LL)dp[1][3]*x+(n-1-dp[1][3])*y);
    }
}


#define LL long long
#include<bits/stdc++.h>
using namespace std;
const LL maxn=200000+5;
LL dp[maxn][4];
vector<int> G[maxn];
LL deg[maxn];
void dfs(LL now,LL fa)
{
    for(LL i=0;i<G[now].size();i++) if(G[now][i]!=fa) dfs(G[now][i],now);
    dp[now][0]=dp[now][1]=dp[now][2]=dp[now][3]=0;

    LL best1=0,best2=0;
    for(LL i=0;i<G[now].size();i++)
    {
        int& to=G[now][i];
        if(to==fa) continue;
        dp[now][0]+=dp[to][3];
        if(best1==0) best1=to;
        else if(best2==0)
        {
            if((max(dp[to][0],dp[to][1])-dp[to][3])>(max(dp[best1][0],dp[best1][1])-dp[best1][3]))
                best2=best1,best1=to;
            else best2=to;
        }
        else if((max(dp[to][0],dp[to][1])-dp[to][3])>(max(dp[best1][0],dp[best1][1])-dp[best1][3]))
        {
            swap(best1,best2);
            best1=to;
        }
        else if((max(dp[to][0],dp[to][1])-dp[to][3])>(max(dp[best2][0],dp[best2][1])-dp[best2][3]))
            best2=to;
    }
    if(best1) dp[now][1]=1+dp[now][0]-dp[best1][3]+max(dp[best1][0],dp[best1][1]);
    if(best1 && best2)dp[now][2]=2+dp[now][0]-dp[best1][3]-dp[best2][3]+max(dp[best1][0],dp[best1][1])+max(dp[best2][0],dp[best2][1]);
    dp[now][3]=max(dp[now][0],max(dp[now][1],dp[now][2]));
//    for(LL i=0;i<4;i++) printf("dp[%I64d][%I64d]=%I64d ",now,i,dp[now][i]);puts("");
}
int main()
{
    LL n,x,y;
    scanf("%I64d%I64d%I64d",&n,&x,&y);
    for(LL i=0,a,b;i<n-1;i++)
    {
        scanf("%I64d%I64d",&a,&b);
        G[a].push_back(b);
        G[b].push_back(a);
        deg[a]++,deg[b]++;
    }
    if(x>y) // bad tree edges
    {
        for(LL i=1;i<=n;i++) if(deg[i]==n-1) {printf("%I64d\n",y*(n-2)+x);return 0;}
        printf("%I64d\n",y*(n-1));
    }
    else
    {
        dfs(1,-1);
        printf("%I64d\n",dp[1][3]*x+(n-1-dp[1][3])*y);
    }
}


#define LL long long
#include<bits/stdc++.h>
using namespace std;
const LL maxn=200000+5;
LL dp[maxn][4];
vector<int> G[maxn];
LL deg[maxn];
void dfs(LL now,LL fa)
{
    for(LL i=0;i<G[now].size();i++) if(G[now][i]!=fa) dfs(G[now][i],now);
    dp[now][0]=dp[now][1]=dp[now][2]=dp[now][3]=0;

    LL best1=0,best2=0;
    for(LL i=0;i<G[now].size();i++)
    {
        int& to=G[now][i];
        if(to==fa) continue;
        dp[now][0]+=dp[to][3];
        if(best1==0) best1=to;
        else if(best2==0)
        {
            if((max(dp[to][0],dp[to][1])-dp[to][3])>(max(dp[best1][0],dp[best1][1])-dp[best1][3]))
                best2=best1,best1=to;
            else best2=to;
        }
        else if((max(dp[to][0],dp[to][1])-dp[to][3])>(max(dp[best1][0],dp[best1][1])-dp[best1][3]))
        {
            swap(best1,best2);
            best2=to;
        }
        else if((max(dp[to][0],dp[to][1])-dp[to][3])>(max(dp[best2][0],dp[best2][1])-dp[best2][3]))
            best2=to;
    }
    if(best1) dp[now][1]=1+dp[now][0]-dp[best1][3]+max(dp[best1][0],dp[best1][1]);
    if(best1 && best2)dp[now][2]=2+dp[now][0]-dp[best1][3]-dp[best2][3]+max(dp[best1][0],dp[best1][1])+max(dp[best2][0],dp[best2][1]);
    dp[now][3]=max(dp[now][0],max(dp[now][1],dp[now][2]));
//    for(LL i=0;i<4;i++) printf("dp[%I64d][%I64d]=%I64d ",now,i,dp[now][i]);puts("");
}
int main()
{
    LL n,x,y;
    scanf("%I64d%I64d%I64d",&n,&x,&y);
    for(LL i=0,a,b;i<n-1;i++)
    {
        scanf("%I64d%I64d",&a,&b);
        G[a].push_back(b);
        G[b].push_back(a);
        deg[a]++,deg[b]++;
    }
    if(x>y) // bad tree edges
    {
        for(LL i=1;i<=n;i++) if(deg[i]==n-1) {printf("%I64d\n",y*(n-2)+x);return 0;}
        printf("%I64d\n",y*(n-1));
    }
    else
    {
        dfs(1,-1);
        printf("%I64d\n",dp[1][3]*x+(n-1-dp[1][3])*y);
    }
}


#define LL long long
#include<bits/stdc++.h>
using namespace std;
const int maxn=200000+5;
LL dp[maxn][4];
vector<int> G[maxn];
int deg[maxn];
void dfs(int now,int fa)
{
    for(int i=0;i<G[now].size();i++) if(G[now][i]!=fa) dfs(G[now][i],now);
    dp[now][0]=dp[now][1]=dp[now][2]=dp[now][3]=0;

    int best1=0,best2=0;
    for(int i=0;i<G[now].size();i++)
    {
        int& to=G[now][i];
        if(to==fa) continue;
        dp[now][0]+=dp[to][3];
        if(best1==0) best1=to;
        else if(best2==0) best2=to;
        else if((max(dp[to][0],dp[to][1])-dp[to][3])>(max(dp[best1][0],dp[best1][1])-dp[best1][3]))
        {
            swap(best1,best2);
            best2=to;
        }
        else if((max(dp[to][0],dp[to][1])-dp[to][3])>(max(dp[best2][0],dp[best2][1])-dp[best2][3]))
            best2=to;
    }
    if(best1) dp[now][1]=1+dp[now][0]-dp[best1][3]+max(dp[best1][0],dp[best1][1]);
    if(best1 && best2)dp[now][2]=2+dp[now][0]-dp[best1][3]-dp[best2][3]+max(dp[best1][0],dp[best1][1])+max(dp[best2][0],dp[best2][1]);
    dp[now][3]=max(dp[now][0],max(dp[now][1],dp[now][2]));
//    for(int i=0;i<4;i++) printf("dp[%d][%d]=%I64d ",now,i,dp[now][i]);puts("");
}
int main()
{
    int n,x,y;
    scanf("%d%d%d",&n,&x,&y);
    for(int i=0,a,b;i<n-1;i++)
    {
        scanf("%d%d",&a,&b);
        G[a].push_back(b);
        G[b].push_back(a);
        deg[a]++,deg[b]++;
    }
    if(x>y) // bad tree edges
    {
        for(int i=1;i<=n;i++) if(deg[i]==n-1) {printf("%I64d\n",(LL)y*(n-2)+x);return 0;}
        printf("%I64d\n",(LL)y*(n-1));
    }
    else
    {
        dfs(1,-1);
        printf("%I64d\n",(LL)dp[1][3]*x+(n-1-dp[1][3])*y);
    }
}


//In The Name Of God
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

const int MAXN = 2e5+22;

int n,x,y;
int a[MAXN],dp[4][MAXN];
vector<int>G[MAXN];

void dfs(int v,int par=n)
{
	vector<int>vec;
	for(int u:G[v])
	{
		if(u==par)
			continue;
		dfs(u,v);
		dp[0][v]+=dp[3][u];
	}
	for(int u:G[v])
	{
		if(u==par)
			continue;
		dp[1][v]=max(dp[1][v],dp[0][v]-dp[3][u]+max(dp[0][u],dp[1][u])+1);
		vec.pb(dp[3][u]-max(dp[0][u],dp[1][u]));
	}
	if(vec.size()>1)
	{
		sort(vec.begin(),vec.end());
		dp[2][v]=dp[0][v]-vec[0]-vec[1]+2;
	}
	dp[3][v]=max(max(dp[0][v],dp[1][v]),dp[2][v]);
}

int main()
{
	cin>>n>>x>>y;
	for(int i=0,p,q;i<n-1;i++)
	{
		cin>>p>>q;
		p-- , q-- ;
		G[p].pb(q);
		G[q].pb(p);
	}
	for(int i=0;i<n;i++)
		cin>>a[i];
	if(y<x)
	{
		for(int i=0;i<n;i++)
			if(G[i].size()==n-1)
				return cout<<(ll)(n-2)*y+x,0;
		cout<<(ll)(n-1)*y;
		return 0;
	}
	dfs(0);
	cout<<(ll)(n-1-dp[3][0])*y+dp[3][0]*x;
	return 0;
}


// In The Name Of God
#include<bits/stdc++.h>
#define pb push_back
#define ll long long
#define int long long
using namespace std;

const int MAXN = 2e5+22;

int n,x,y;
int dp0[MAXN],dp1[MAXN],dp2[MAXN],dp3[MAXN];
vector<int>G[MAXN];

void dfs(int v,int par)
{
    vector<int>vec;
  int r0=0,r1=0,r2=0;
  for(int u:G[v])
    {
      if(u==par)
	continue;
      dfs(u,v);
      r0+=dp3[u];
      vec.pb((dp3[u]-max(dp1[u],dp0[u])));
    }
 for(int u:G[v])
    {
      if(u==par)
	continue;
      r1=max(r1,r0-dp3[u]+max(dp1[u],dp0[u])+1);
    }
 if(vec.size()>=2)
 	sort(vec.begin(),vec.begin()) , r2=r0-vec[0]-vec[1]+2;
   dp0[v]=r0 , dp1[v]=r1 , dp2[v]=r2 , dp3[v]=max(dp0[v],max(dp1[v],dp2[v]));
  //  cout<<v<<" : " << dp0[v] << " " << dp1[v] <<" "<<dp2[v] <<" " << dp3[v] << endl;
}

int32_t main()
{
  cin>>n>>x>>y;
  for(int i=0,p,q;i<n-1;i++)
    {
      cin>>p>>q;
      p-- , q--;
      G[p].pb(q);
      G[q].pb(p);
    }
  if(x>=y)
    {
      for(int i=0;i<n;i++)
	if(G[i].size()==n-1)
	  return cout<<(ll)(n-2)*y+x<<endl,0;
      cout<<(ll)(n-1)*y<<endl;
      return 0;
    }
  dfs(0,-1);
  cout<<(ll)(n-1-dp3[0])*y+dp3[0]*x<<endl;
  return 0;
}


// In The Name Of God
#include<bits/stdc++.h>
#define pb push_back
#define ll long long
#define int long long
using namespace std;

const int MAXN = 2e5+22;

int n,x,y;
int dp0[MAXN],dp1[MAXN],dp2[MAXN],dp3[MAXN];
vector<int>G[MAXN],vec;

void dfs(int v,int par)
{
  vec.clear();
  int r0=0,r1=0,r2=0;
  for(int u:G[v])
    {
      if(u==par)
	continue;
      dfs(u,v);
      r0+=dp3[u];
      vec.pb((dp3[u]-max(dp1[u],dp0[u])));
    }
 for(int u:G[v])
    {
      if(u==par)
	continue;
      r1=max(r1,r0-dp3[u]+max(dp1[u],dp0[u])+1);
    }
 if(vec.size()>=2)
 	sort(vec.begin(),vec.begin()) , r2=r0-vec[0]-vec[1]+2;
   dp0[v]=r0 , dp1[v]=r1 , dp2[v]=r2 , dp3[v]=max(dp0[v],max(dp1[v],dp2[v]));
  //  cout<<v<<" : " << dp0[v] << " " << dp1[v] <<" "<<dp2[v] <<" " << dp3[v] << endl;
}

int32_t main()
{
  cin>>n>>x>>y;
  for(int i=0,p,q;i<n-1;i++)
    {
      cin>>p>>q;
      p-- , q--;
      G[p].pb(q);
      G[q].pb(p);
    }
  if(x>=y)
    {
      for(int i=0;i<n;i++)
	if(G[i].size()==n-1)
	  return cout<<(ll)(n-2)*y+x<<endl,0;
      cout<<(ll)(n-1)*y<<endl;
      return 0;
    }
  dfs(0,-1);
  cout<<(ll)(n-1-dp3[0])*y+dp3[0]*x<<endl;
  return 0;
}


// In The Name Of God
#include<bits/stdc++.h>
#define pb push_back
#define ll long long
#define int long long
using namespace std;

const int MAXN = 2e5+22;

int n,x,y;
int dp0[MAXN],dp1[MAXN],dp2[MAXN],dp3[MAXN];
vector<int>G[MAXN],vec;

void dfs(int v,int par)
{
  vec.clear();
  int r0=0,r1=0,r2=0;
  for(int u:G[v])
    {
      if(u==par)
	continue;
      dfs(u,v);
      r0+=dp3[u];
      vec.pb((dp3[u]-max(dp1[u],dp0[u])));
    }
 for(int u:G[v])
    {
      if(u==par)
	continue;
      r1=max(r1,r0-dp3[u]+max(dp1[u],dp0[u])+1);
    }
 if(G[v].size()>=2)
 {
 	sort(vec.begin(),vec.begin()) , r2=r0-vec[0]-vec[1]+2;
 }
   dp0[v]=r0 , dp1[v]=r1 , dp2[v]=r2 , dp3[v]=max(dp0[v],max(dp1[v],dp2[v]));
  //  cout<<v<<" : " << dp0[v] << " " << dp1[v] <<" "<<dp2[v] <<" " << dp3[v] << endl;
}

int32_t main()
{
  cin>>n>>x>>y;
  for(int i=0,p,q;i<n-1;i++)
    {
      cin>>p>>q;
      p-- , q--;
      G[p].pb(q);
      G[q].pb(p);
    }
  if(x>=y)
    {
      for(int i=0;i<n;i++)
	if(G[i].size()==n-1)
	  return cout<<(ll)(n-2)*y+x<<endl,0;
      cout<<(ll)(n-1)*y<<endl;
      return 0;
    }
  dfs(0,-1);
  cout<<(ll)(n-1-dp3[0])*y+dp3[0]*x<<endl;
  return 0;
}


//In The Name Of God
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

const int MAXN = 2e5+22;

int n,x,y;
int dp[4][MAXN];
vector<int>G[MAXN];

void dfs(int v,int par=n)
{
	vector<int>vec;
	for(int u:G[v])
	{
		if(u==par)
			continue;
		dfs(u,v);
		dp[0][v]+=dp[3][u];
	}
	for(int u:G[v])
	{
		if(u==par)
			continue;
		dp[1][v]=max(dp[1][v],dp[0][v]-dp[3][u]+max(dp[0][u],dp[1][u])+1);
		vec.pb(dp[3][u]-max(dp[0][u],dp[1][u]));
	}
	if(vec.size()>1)
	{
		sort(vec.begin(),vec.end());
		dp[2][v]=dp[0][v]-vec[0]-vec[1]+2;
	}
	dp[3][v]=max(max(dp[0][v],dp[1][v]),dp[2][v]);
}

int main()
{
	cin>>n>>x>>y;
	for(int i=0,p,q;i<n-1;i++)
	{
		cin>>p>>q;
		p-- , q-- ;
		G[p].pb(q);
		G[q].pb(p);
	}
	if(y<x)
	{
		for(int i=0;i<n;i++)
			if(G[i].size()==n-1)
				return cout<<(ll)(n-2)*y+x,0;
		cout<<(ll)(n-1)*y;
		return 0;
	}
	dfs(0);
	cout<<(ll)(n-1-dp[3][0])*y+(ll)dp[3][0]*x;
	return 0;
}


//In The Name Of God
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define int long long
using namespace std;

const int MAXN = 2e5+22;

int n,x,y;
int dp[4][MAXN];
vector<int>G[MAXN];

void dfs(int v,int par=n)
{
	vector<int>vec;
	for(int u:G[v])
	{
		if(u==par)
			continue;
		dfs(u,v);
		dp[0][v]+=dp[3][u];
	}
	for(int u:G[v])
	{
		if(u==par)
			continue;
		dp[1][v]=max(dp[1][v],dp[0][v]-dp[3][u]+max(dp[0][u],dp[1][u])+1);
		vec.pb(dp[3][u]-max(dp[0][u],dp[1][u]));
	}
	if(vec.size()>1)
	{
		sort(vec.begin(),vec.end());
		dp[2][v]=dp[0][v]-vec[0]-vec[1]+2;
	}
	dp[3][v]=max(max(dp[0][v],dp[1][v]),dp[2][v]);
}

int32_t main()
{
	cin>>n>>x>>y;
	for(int i=0,p,q;i<n-1;i++)
	{
		cin>>p>>q;
		p-- , q-- ;
		G[p].pb(q);
		G[q].pb(p);
	}
	if(y<x)
	{
		for(int i=0;i<n;i++)
			if(G[i].size()==n-1)
				return cout<<(ll)(n-2)*y+x,0;
		cout<<(ll)(n-1)*y;
		return 0;
	}
	dfs(0);
	cout<<(ll)(n-1-dp[3][0])*y+dp[3][0]*x;
	return 0;
}


//In The Name Of God
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

const int MAXN = 2e5+22;

int n,x,y;
int a[MAXN],dp[4][MAXN];
vector<int>G[MAXN];

void dfs(int v,int par=n)
{
	vector<int>vec;
	for(int u:G[v])
	{
		if(u==par)
			continue;
		dfs(u,v);
		dp[0][v]+=dp[3][u];
	}
	for(int u:G[v])
	{
		if(u==par)
			continue;
		dp[1][v]=max(dp[1][v],dp[0][v]-dp[3][u]+max(dp[0][u],dp[1][u])+1);
		vec.pb(dp[3][u]-max(dp[0][u],dp[1][u]));
	}
	if(vec.size()>1)
	{
		sort(vec.begin(),vec.end());
		dp[2][v]=dp[0][v]-vec[0]-vec[1]+2;
	}
	dp[3][v]=max(max(dp[0][v],dp[1][v]),dp[2][v]);
}

int main()
{
	cin>>n>>x>>y;
	for(int i=0,p,q;i<n-1;i++)
	{
		cin>>p>>q;
		p-- , q-- ;
		G[p].pb(q);
		G[q].pb(p);
	}
	for(int i=0;i<n;i++)
		cin>>a[i];
	if(y<x)
	{
		for(int i=0;i<n;i++)
			if(G[i].size()==n-1)
				return cout<<(ll)(n-2)*y+x,0;
		cout<<(ll)(n-1)*y;
		return 0;
	}
	dfs(0);
	cout<<(ll)(n-1-dp[3][0])*y+(ll)dp[3][0]*x;
	return 0;
}


// In The Name Of God
#include<bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;

const int MAXN = 2e5+22;

int n,x,y;
int dp0[MAXN],dp1[MAXN],dp2[MAXN],dp3[MAXN];
vector<int>G[MAXN],vec;

void dfs(int v,int par)
{
  int r0=0,r1=0,r2=0;
  for(int u:G[v])
    {
      if(u==par)
	continue;
      dfs(u,v);
      r0+=dp3[u];
    }
 for(int u:G[v])
    {
      if(u==par)
	continue;
      r1=max(r1,r0-dp3[u]+max(dp1[u],dp0[u])+1);
    }
 if(G[v].size()>=2+(v!=0))
 {
	vec.clear();
	for(int u:G[v])
	{
		if(u==par)
			continue;
		vec.pb((dp3[u]-max(dp1[u],dp0[u])));
	}
 	sort(vec.begin(),vec.begin());
	r2=r0-vec[0]-vec[1]+2;
 }
   dp0[v]=r0 , dp1[v]=r1 , dp2[v]=r2 , dp3[v]=max(dp0[v],max(dp1[v],dp2[v]));
  //  cout<<v<<" : " << dp0[v] << " " << dp1[v] <<" "<<dp2[v] <<" " << dp3[v] << endl;
}

int main()
{
  cin>>n>>x>>y;
  for(int i=0,p,q;i<n-1;i++)
    {
      cin>>p>>q;
      p-- , q--;
      G[p].pb(q);
      G[q].pb(p);
    }
  if(x>=y)
    {
      for(int i=0;i<n;i++)
	if(G[i].size()==n-1)
	  return cout<<(ll)(n-2)*y+x<<endl,0;
      cout<<(ll)(n-1)*y<<endl;
      return 0;
    }
  dfs(0,-1);
  cout<<(ll)(n-1-dp3[0])*y+dp3[0]*x<<endl;
  return 0;
}


//In The Name Of God
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

const int MAXN = 2e5+22;

int n,x,y;
int a[MAXN],dp[4][MAXN];
vector<int>G[MAXN];

void dfs(int v,int par=n)
{
	vector<int>vec;
	for(int u:G[v])
	{
		if(u==par)
			continue;
		dfs(u,v);
		dp[0][v]+=dp[3][u];
	}
	for(int u:G[v])
	{
		if(u==par)
			continue;
		dp[1][v]=max(dp[1][v],dp[0][v]-dp[3][u]+max(dp[0][u],dp[1][u])+1);
		vec.pb(dp[0][v]-dp[3][u]+max(dp[0][u],dp[1][u]));
	}
	if(vec.size()>1)
	{
		sort(vec.begin(),vec.end());
		dp[2][v]=dp[0][v]-vec[0]-vec[1]+2;
	}
	dp[3][v]=max(max(dp[0][v],dp[1][v]),dp[2][v]);
}

int main()
{
	cin>>n>>x>>y;
	for(int i=0,p,q;i<n-1;i++)
	{
		cin>>p>>q;
		p-- , q-- ;
		G[p].pb(q);
		G[q].pb(p);
	}
	for(int i=0;i<n;i++)
		cin>>a[i];
	if(y<x)
	{
		for(int i=0;i<n;i++)
			if(G[i].size()==n-1)
				return cout<<(ll)(n-2)*y+x,0;
		cout<<(ll)(n-1)*y;
		return 0;
	}
	dfs(0);
	cout<<(ll)(n-1-dp[3][0])*y+dp[3][0]*x;
	return 0;
}


// In The Name Of God
#include<bits/stdc++.h>
#define pb push_back
#define ll long long
#define int long long
using namespace std;

const int MAXN = 2e5+22;

int n,x,y;
int dp0[MAXN],dp1[MAXN],dp2[MAXN],dp3[MAXN];
vector<int>G[MAXN],vec;

void dfs(int v,int par)
{
  vec.clear();
  int r0=0,r1=0,r2=0;
  for(int u:G[v])
    {
      if(u==par)
	continue;
      dfs(u,v);
      r0+=dp3[u];
      vec.pb((dp3[u]-max(dp1[u],dp0[u])));
    }
 for(int u:G[v])
    {
      if(u==par)
	continue;
      r1=max(r1,r0-dp3[u]+max(dp1[u],dp0[u])+1);
    }
 if(G[v].size()>=2)
 	sort(vec.begin(),vec.begin()) , r2=r0-vec[0]-vec[1]+2;
   dp0[v]=r0 , dp1[v]=r1 , dp2[v]=r2 , dp3[v]=max(dp0[v],max(dp1[v],dp2[v]));
  //  cout<<v<<" : " << dp0[v] << " " << dp1[v] <<" "<<dp2[v] <<" " << dp3[v] << endl;
}

int32_t main()
{
  cin>>n>>x>>y;
  for(int i=0,p,q;i<n-1;i++)
    {
      cin>>p>>q;
      p-- , q--;
      G[p].pb(q);
      G[q].pb(p);
    }
  if(x>=y)
    {
      for(int i=0;i<n;i++)
	if(G[i].size()==n-1)
	  return cout<<(ll)(n-2)*y+x<<endl,0;
      cout<<(ll)(n-1)*y<<endl;
      return 0;
    }
  dfs(0,-1);
  cout<<(ll)(n-1-dp3[0])*y+dp3[0]*x<<endl;
  return 0;
}


//
//  CPlibrary
//
//  Created by Tanmay Singh on 3/03/2020.
// INDIAN INSTITUTE OF TECHNOLOGY (BHU) , VARANASI
//  Copyright © 2020 Tanmay Singh. All rights reserved.
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstring>
#include <set>
#include <map>
#include <cstdio>
#include <iterator>
#include <string>
#include <stack>
#include <deque>
#include <unordered_set>
#include <unordered_map>

#define FAST(); ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl "\n"
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define MAX 1e9+7
#define loopchalao(i , N) for( int i = 0 ; i < N ; i++ )
typedef long long  int  bigint ;

using namespace std ;

int main(){
    int N ; cin >> N ; vector<int> v ;
    while( N > 0 ){
        if( N % 7 == 0 ){
             v.push_back(7) ;
            N -= 7 ;
        }
        else if( N % 4 == 0 ){
            v.push_back(4) ;
            N -= 4 ;
        }
        else{
            N -= 4 ;
            v.push_back(4) ;
        }
    }

    if( N < 0 ){
        cout << "-1" << endl ;
    }
    else{
        sort( v.begin() , v.end() );
        for(auto x : v ){
            cout << x ;
        }
        cout << endl ;
    }
    return 0 ;
}


//
//  CPlibrary
//
//  Created by Tanmay Singh on 3/03/2020.
// INDIAN INSTITUTE OF TECHNOLOGY (BHU) , VARANASI
//  Copyright © 2020 Tanmay Singh. All rights reserved.
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstring>
#include <set>
#include <map>
#include <cstdio>
#include <iterator>
#include <string>
#include <stack>
#include <deque>
#include <unordered_set>
#include <unordered_map>

#define FAST(); ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl "\n"
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define MAX 1e9+7
#define loopchalao(i , N) for( int i = 0 ; i < N ; i++ )
typedef long long  int  bigint ;

using namespace std ;

int main(){
    int N ; cin >> N ; vector<int> v ;
    while( N > 1 ){
        if( N % 7 == 0 ){
             v.push_back(7) ;
            N -= 7 ;
        }
        else if( N % 4 == 0 ){
            v.push_back(4) ;
            N -= 4 ;
        }
        else{
            N -= 4 ;
            v.push_back(4) ;
        }
    }

    if( N < 0 ){
        cout << "-1" << endl ;
    }
    else{
        sort( v.begin() , v.end() );
        for(auto x : v ){
            cout << x ;
        }
        cout << endl ;
    }
    return 0 ;
}


//
//  CPlibrary
//
//  Created by Tanmay Singh on 3/03/2020.
// INDIAN INSTITUTE OF TECHNOLOGY (BHU) , VARANASI
//  Copyright © 2020 Tanmay Singh. All rights reserved.
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstring>
#include <set>
#include <map>
#include <cstdio>
#include <iterator>
#include <string>
#include <stack>
#include <deque>
#include <unordered_set>
#include <unordered_map>

#define FAST(); ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl "\n"
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define MAX 1e9+7
#define loopchalao(i , N) for( int i = 0 ; i < N ; i++ )
typedef long long  int  bigint ;

using namespace std ;

int main(){
    int N ; cin >> N ; vector<int> v ;
    while( N > 1 ){
        if( N % 4 == 0 ){
            v.push_back(4) ;
            N -= 4 ;
        }
        else if( N % 7 == 0 ){
             v.push_back(7) ;
            N -= 7 ;
        }
        else{
            N -= 4 ;
            v.push_back(4) ;
        }
    }

    if( N < 0 ){
        cout << "-1" << endl ;
    }
    else{
        sort( v.begin() , v.end() );
        for(auto x : v ){
            cout << x ;
        }
        cout << endl ;
    }
    return 0 ;
}


#include<bits/stdc++.h>
using namespace std;
#define Khela_Sesh ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define llu long long unsigned int
#define sf scanf
#define pf printf
int main()
{
    Khela_Sesh;
    int a,b,c,i,j,k,n,p,q,x,y,sum,ct,ct1,m,mid,l,r,len,ans,mx,t,s,f;
    char ch;
    double d;
    string str1,str2,str;
    bool bl,bl1;
    while(cin>>n)
    {
        ll digit=1e17;
        bl=false,f=0,s=0;
        int svn;
        int fr;
         if(n%4==0){
            fr=(n/4);
            bl=true;
            s=0,f=fr;
            digit=fr;
        }
        else{
                fr=(n/4);
        while(fr)
        {
           x=(n)-(fr*4);
           if(x%7==0){
            bl=true;
            svn=(x/7);
            if(digit>(fr+svn)) digit=(fr+svn),s=svn,f=fr;
            break;
           }
           else --fr;
        }
        }
         if(n%7==0) {
            svn=(n/7);
            fr=0;
            if(svn<digit) s=svn,f=0;
            bl=true;
        }
        if(!bl) cout<<"-1"<<endl;
        else {
            string Ans=string(f,'4')+string(s,'7');
            cout<<Ans<<endl;
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
#define Khela_Sesh ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define llu long long unsigned int
#define sf scanf
#define pf printf
int main()
{
    Khela_Sesh;
    int a,b,c,i,j,k,n,p,q,x,y,sum,ct,ct1,m,mid,l,r,len,ans,mx,t,s,f;
    char ch;
    double d;
    string str1,str2,str;
    bool bl,bl1;
    while(cin>>n)
    {
       int sv=0,fr=0,left;
       bl=false;
       for(i=1;4*i<=n;i++){
        left=n-(4*i);
        if(left%7==0){
            sv=left/7,fr=i;
            break;
        }
       }
       if(n%7==0 && ((n/7)<(sv+fr) || (sv+fr==0))) sv=n/7,fr=0;
       string tl=string(fr,'4')+string(sv,'7');
       if(sv || fr) cout<<tl<<endl;
       else cout<<"-1"<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define Khela_Sesh ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define llu long long unsigned int
#define sf scanf
#define pf printf
int main()
{
    Khela_Sesh;
    int a,b,c,i,j,k,n,p,q,x,y,sum,ct,ct1,m,mid,l,r,len,ans,mx,t;
    char ch;
    double d;
    string str1,str2,str;
    bool bl,bl1;
    while(cin>>n)
    {
        bl=false;
        int svn=(n/7);
        int fr;
         if(n%4==0){
            fr=(n/4);
            svn=0,bl=true;
        }
        else{
                svn=(n/7);
        while(svn)
        {
           x=(n)-(svn*7);
           if(x%4==0){
            bl=true;
            fr=(x/4);
            break;
           }
           else --svn;
        }
        }
         if(n%7==0 && !bl) {
            svn=(n/7);
            fr=0;
            bl=true;
        }
        if(!bl) cout<<"-1"<<endl;
        else {
            string Ans=string(fr,'4')+string(svn,'7');
            cout<<Ans<<endl;
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
 int input_number,remainder,number_of_seven,i;
 cin>>input_number;
 number_of_seven=input_number/7;
 remainder=input_number%7;
 if(remainder==4){
 for(i=0;i<number_of_seven;i++)
 {
   cout<<7;
 }

   cout<<4<<endl;
 }
 else
  cout<<-1;
 return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
 int input_number,remainder,number_of_seven,i;
 cin>>input_number;
 number_of_seven=input_number/7;
 remainder=input_number%7;
 if(remainder==4){

   cout<<4<<endl;
   for(i=0;i<number_of_seven;i++)
 {
   cout<<7;
 }
 }
 else
  cout<<-1;
 return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
  int number,number_of_seven,a,b,i;
    cin>>number;
    if(number==4)
    {
     cout<<4;
     return 0;
    }
    if(number==7)
    {
     cout<<7;
     return 0;
    }
    if(number%4==0)
    {
     for(i=0;i<number/4;i++)
     {
      cout<<4;
     }
      return 0;
    }
    number_of_seven=number/7;
    while(number_of_seven>0)
    {
    a=number-number_of_seven*7;
    if(a%4==0)
    {
      b=a/4;
      for(i=0;i<b;i++)
      {
       cout<<4;
      }
      for(i=0;i<number_of_seven;i++)
      {
       cout<<7;
      }
      return 0;
    }
    number_of_seven--;
    }
    cout<<-1<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
 int input_number,remainder,number_of_seven,i;
 cin>>input_number;
 number_of_seven=input_number/7;
 remainder=input_number%7;
 if(remainder==4){

   cout<<4;
   for(i=0;i<number_of_seven;i++)
 {
   cout<<7;
 }
 }
 else
  cout<<-1;
 return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
  int number,number_of_seven,a,b,i;
    cin>>number;
    if(number==4)
    {
     cout<<4;
     return 0;
    }
    if(number==7)
    {
     cout<<7;
     return 0;
    }
    number_of_seven=number/7;
    while(number_of_seven>0)
    {
    a=number-number_of_seven*7;
    if(a%4==0)
    {
      b=a/4;
      for(i=0;i<b;i++)
      {
       cout<<4;
      }
      for(i=0;i<number_of_seven;i++)
      {
       cout<<7;
      }
      return 0;
    }
    number_of_seven--;
    }
     if(number%4==0)
    {
     for(i=0;i<number/4;i++)
     {
      cout<<4;
     }
      return 0;
    }
    cout<<-1<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
  int number,number_of_seven,a,b,i;
    cin>>number;
    if(number==4)
    {
     cout<<4;
     return 0;
    }
    if(number==7)
    {
     cout<<7;
     return 0;
    }
    number_of_seven=number/7;
    while(number_of_seven>0)
    {
    a=number-number_of_seven*7;
    if(a%4==0)
    {
      b=a/4;
      for(i=0;i<b;i++)
      {
       cout<<4;
      }
      for(i=0;i<number_of_seven;i++)
      {
       cout<<7;
      }
      return 0;
    }
    number_of_seven--;
    }
    cout<<-1<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
  int number,number_of_seven,a,b,i;
    cin>>number;
    number_of_seven=number/7;
    while(number_of_seven>0)
    {
    a=number-number_of_seven*7;
    if(a%4==0)
    {
      b=a/4;
      for(i=0;i<b;i++)
      {
       cout<<4;
      }
      for(i=0;i<number_of_seven;i++)
      {
       cout<<7;
      }
      return 0;
    }
    number_of_seven--;
    }
    cout<<-1<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
 int input_number,remainder,number_of_seven,i;
 cin>>input_number;
 number_of_seven=input_number/7;
 remainder=input_number%7;
 if(remainder==4){

   cout<<4;
   for(i=0;i<number_of_seven;i++)
 {
   cout<<7;
 }
 }
 number_of_seven=input_number/4;
 remainder=input_number%4;
if(remainder==7){

   cout<<7;
   for(i=0;i<number_of_seven;i++)
 {
   cout<<4;
 }

}
else
   cout<<-1;
return 0;
}


#include <bits/stdc++.h>
#define endl "\n"
#define ll long long
#define pll pair<ll,ll>
#define vll vector<ll>
#define vint vector<int>
#define usll unordered_set<ll>
#define sll set<ll>
#define mll map<ll,ll>
#define pb push_back
#define mp make_pair
#define forr(i, n) for(ll int i = 0; i < n; i++)
#define forr1(i,n) for(ll int i=1;i<n;i++)
#define forra(i,a,b) for(ll int i=a;i<b;i++)
#define arrin(a,n) forr(i,n) cin>>a[i];
#define arrout(a,n) forr(i,n) {cout<<a[i]<<' ';} cout<<'\n';
#define umap unordered_map
typedef long long int lli;
typedef long int li;
using namespace std;
bool primes[1000000+1];
void sieve(lli n){
	 primes[0]=false;
	 primes[1]=false;
	 for(lli i{2};i<=n;i++){primes[i]=true;}
	 for(lli i{2};i<=sqrt(n);i++){
			 if(primes[i]==true){
				for(lli j{2};j*i<=n;j++){primes[i*j]=false;}
			 }
	 }
}
bool comp(pair<int,int> &a, pair<int,int> &b)
{
    return (a.first < b.first);
}
lli gcd(lli a,lli b){
	if(a==0) return b;
	return gcd(b%a,a);
}
lli lcm(lli a,lli b){
	return a*b/gcd(a,b);
}
lli fastpow(long long base, long long n)
{
    if(n==0)
       return 1;
    if(n==1)
    return base;
    long long halfn=fastpow(base,n/2);
    if(n%2==0)
        return ( halfn * halfn );
    else
        return ( ( ( halfn * halfn ) ) * base );
}
void bfs(lli s, vector<lli> v[], bool vis[])
{
    queue<lli> q;
    q.push(s);
    vis[s]=true;
    while(!q.empty())
    {
        lli a=q.front();
        q.pop();
        //process node 'a'
        for(auto x : v[a])
        {
            if(!vis[x])
            {
                q.push(x);
                vis[x]=true;
                //e[x] = e[a]+1; where e[i] is distance from 0/root and e[0/root]=0
            }
        }
    }
}
void dfs(lli s, vector<lli> v[], bool vis[])
{
    //process node 's'
    vis[s]=true;
    for(auto x : v[s])
    {
        if(!vis[x])
        {
            dfs(x,v,vis);
        }
    }
}
bool checksubsq(string s,lli l,string t,lli j){
	for(lli i{l};i<s.size();i++){
		if(s[i]==t[j]){
			if(j==t.size()-1){
				return true;
			}
			else{
				return checksubsq(s,i+1,t,j+1);
			}
		}
	}
	return false;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	lli n;
	cin>>n;
	lli x=-1,y=-1;
	lli i=0;
	while(1){
		lli t=(n-(4*i));
		if(t<0){
			break;
		}
		if(t%7==0){
			x=i;
		}
		i++;
	}
	if(x==-1){
		cout<<-1<<endl;
	}
	else{
		y=(n-(4*x))/7;
		forr(i,x){
			cout<<4;
		}
		forr(i,y){
			cout<<7;
		}
	}
	return 0;
}


#include <bits/stdc++.h>
#define endl "\n"
#define ll long long
#define pll pair<ll,ll>
#define vll vector<ll>
#define vint vector<int>
#define usll unordered_set<ll>
#define sll set<ll>
#define mll map<ll,ll>
#define pb push_back
#define mp make_pair
#define forr(i, n) for(ll int i = 0; i < n; i++)
#define forr1(i,n) for(ll int i=1;i<n;i++)
#define forra(i,a,b) for(ll int i=a;i<b;i++)
#define arrin(a,n) forr(i,n) cin>>a[i];
#define arrout(a,n) forr(i,n) {cout<<a[i]<<' ';} cout<<'\n';
#define umap unordered_map
typedef long long int lli;
typedef long int li;
using namespace std;
bool primes[1000000+1];
void sieve(lli n){
	 primes[0]=false;
	 primes[1]=false;
	 for(lli i{2};i<=n;i++){primes[i]=true;}
	 for(lli i{2};i<=sqrt(n);i++){
			 if(primes[i]==true){
				for(lli j{2};j*i<=n;j++){primes[i*j]=false;}
			 }
	 }
}
bool comp(pair<int,int> &a, pair<int,int> &b)
{
    return (a.first < b.first);
}
lli gcd(lli a,lli b){
	if(a==0) return b;
	return gcd(b%a,a);
}
lli lcm(lli a,lli b){
	return a*b/gcd(a,b);
}
lli fastpow(long long base, long long n)
{
    if(n==0)
       return 1;
    if(n==1)
    return base;
    long long halfn=fastpow(base,n/2);
    if(n%2==0)
        return ( halfn * halfn );
    else
        return ( ( ( halfn * halfn ) ) * base );
}
void bfs(lli s, vector<lli> v[], bool vis[])
{
    queue<lli> q;
    q.push(s);
    vis[s]=true;
    while(!q.empty())
    {
        lli a=q.front();
        q.pop();
        //process node 'a'
        for(auto x : v[a])
        {
            if(!vis[x])
            {
                q.push(x);
                vis[x]=true;
                //e[x] = e[a]+1; where e[i] is distance from 0/root and e[0/root]=0
            }
        }
    }
}
void dfs(lli s, vector<lli> v[], bool vis[])
{
    //process node 's'
    vis[s]=true;
    for(auto x : v[s])
    {
        if(!vis[x])
        {
            dfs(x,v,vis);
        }
    }
}
bool checksubsq(string s,lli l,string t,lli j){
	for(lli i{l};i<s.size();i++){
		if(s[i]==t[j]){
			if(j==t.size()-1){
				return true;
			}
			else{
				return checksubsq(s,i+1,t,j+1);
			}
		}
	}
	return false;
}
lli solve(lli x,lli y){

}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	lli n;
	cin>>n;
	lli x=-1,y=-1;
	lli i=0;
	while(1){
		lli t=(n-(4*i));
		if(t<0){
			break;
		}
		if(t%7==0){
			x=i;
		}
		i++;
	}
	if(x==-1){
		cout<<-1<<endl;
	}
	else{
		y=(n-(4*x))/7;
		y+=(x/7);
		x=x%7;
		forr(i,x){
			cout<<4;
		}
		forr(i,y){
			cout<<7;
		}
	}
	return 0;
}


#include <bits/stdc++.h>
#define endl "\n"
#define ll long long
#define pll pair<ll,ll>
#define vll vector<ll>
#define vint vector<int>
#define usll unordered_set<ll>
#define sll set<ll>
#define mll map<ll,ll>
#define pb push_back
#define mp make_pair
#define forr(i, n) for(ll int i = 0; i < n; i++)
#define forr1(i,n) for(ll int i=1;i<n;i++)
#define forra(i,a,b) for(ll int i=a;i<b;i++)
#define arrin(a,n) forr(i,n) cin>>a[i];
#define arrout(a,n) forr(i,n) {cout<<a[i]<<' ';} cout<<'\n';
#define umap unordered_map
typedef long long int lli;
typedef long int li;
using namespace std;
bool primes[1000000+1];
void sieve(lli n){
	 primes[0]=false;
	 primes[1]=false;
	 for(lli i{2};i<=n;i++){primes[i]=true;}
	 for(lli i{2};i<=sqrt(n);i++){
			 if(primes[i]==true){
				for(lli j{2};j*i<=n;j++){primes[i*j]=false;}
			 }
	 }
}
bool comp(pair<int,int> &a, pair<int,int> &b)
{
    return (a.first < b.first);
}
lli gcd(lli a,lli b){
	if(a==0) return b;
	return gcd(b%a,a);
}
lli lcm(lli a,lli b){
	return a*b/gcd(a,b);
}
lli fastpow(long long base, long long n)
{
    if(n==0)
       return 1;
    if(n==1)
    return base;
    long long halfn=fastpow(base,n/2);
    if(n%2==0)
        return ( halfn * halfn );
    else
        return ( ( ( halfn * halfn ) ) * base );
}
void bfs(lli s, vector<lli> v[], bool vis[])
{
    queue<lli> q;
    q.push(s);
    vis[s]=true;
    while(!q.empty())
    {
        lli a=q.front();
        q.pop();
        //process node 'a'
        for(auto x : v[a])
        {
            if(!vis[x])
            {
                q.push(x);
                vis[x]=true;
                //e[x] = e[a]+1; where e[i] is distance from 0/root and e[0/root]=0
            }
        }
    }
}
void dfs(lli s, vector<lli> v[], bool vis[])
{
    //process node 's'
    vis[s]=true;
    for(auto x : v[s])
    {
        if(!vis[x])
        {
            dfs(x,v,vis);
        }
    }
}
bool checksubsq(string s,lli l,string t,lli j){
	for(lli i{l};i<s.size();i++){
		if(s[i]==t[j]){
			if(j==t.size()-1){
				return true;
			}
			else{
				return checksubsq(s,i+1,t,j+1);
			}
		}
	}
	return false;
}
lli solve(lli x,lli y){

}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	lli n;
	cin>>n;
	lli x=-1,y=-1;
	lli i=0;
	while(1){
		lli t=(n-(4*i));
		if(t<0){
			break;
		}
		if(t%7==0){
			x=i;
		}
		i++;
	}
	if(x==-1){
		cout<<-1<<endl;
	}
	else{
		y=(n-(4*x))/7;
		y+=4*(x/7);
		x=x%7;
		forr(i,x){
			cout<<4;
		}
		forr(i,y){
			cout<<7;
		}
	}
	return 0;
}


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

int main()
{
    long long int seven,four,sum=0,n,limit;
    cin>>n;
    int j=-1;

     if(n%7==0)
     {
         limit=n/7;
     }
     else if(n%7>4)
     {
         limit=(n/7)+2;
     }
     else
     {
         limit=(n/7)+1;
     }

    for(int i=1; i<=limit; i++)
    {
        j+=1;
        sum=0;

        for(int k=1; k<=limit-j; k++)
        {
            sum=sum+7;
            seven=limit-j;
        }
        //cout<<seven<<endl;
        four=j;
        while(four!=0)
        {
            sum=sum+4;
            four--;
        }
        if(sum==n)
        {

            while(j!=0)
            {
                cout<<4;
                j--;
            }
            for(int x=1; x<=seven; x++)
            {
                cout<<7;
            }
            return 0;
        }

    }
    cout<<"-1"<<endl;

    return 0;
}


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

int main()
{
    long long int seven,four,sum=0,n,limit;
    cin>>n;
    int j=-1;

     if(n==4 || n==7)
     {
         cout<<n<<endl;
         return 0;
     }
     else if(n%7==0)
     {
         limit=n/7;
     }
     else if(n%7>4)
     {
         limit=(n/7)+2;
     }
     else
     {
         limit=(n/7)+1;
     }

    for(int i=1; i<=limit; i++)
    {
        j+=1;
        sum=0;

        for(int k=1; k<=limit-j; k++)
        {
            sum=sum+7;
            seven=limit-j;
        }
        //cout<<seven<<endl;
        four=j;
        while(four!=0)
        {
            sum=sum+4;
            four--;
        }
        if(sum==n)
        {

            while(j!=0)
            {
                cout<<4;
                j--;
            }
            for(int x=1; x<=seven; x++)
            {
                cout<<7;
            }
            return 0;
        }

    }
    cout<<"-1"<<endl;

    return 0;
}


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

int main()
{
    int n;
    cin>>n;
    string rslt="";
    for(int i=n/7;i>=0;i--)
    {
        if((n-7*i)%4==0)
        {
            int cnt=(n-7*i)/4;
            for(int i=0;i<cnt;i++)
                rslt+='4';
            for(int j=0;j<i;j++)
                rslt+='7';

            cout<<rslt<<endl;
            return 0;
        }
    }
    cout<<"-1"<<endl;
    return 0;
}


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

int main()
{
    long long int seven,four,sum=0,n;
    cin>>n;
    int j=-1;
    for(int i=1; i<=n/7+1; i++)
    {
        j+=1;
        sum=0;
        for(int k=1; k<=(n/7+1)-j; k++)
        {
            sum=sum+7;
            seven=(n/7+1)-j;
        }
        four=j;
        while(j!=0)
        {
            sum=sum+4;
            j--;
        }
        if(sum==n)
        {

            while(four!=0)
            {
                cout<<4;
                four--;
            }
            for(int x=1; x<=seven; x++)
            {
                cout<<7;
            }
            return 0;
        }

    }
    for(int i=1; i<=n/4+1; i++)
    {
        j+=1;
        sum=0;
        for(int k=1; k<=(n/4+1)-j; k++)
        {
            sum=sum+4;
            four=(n/4+1)-j;
        }
        seven=j;
        while(j!=0)
        {
            sum=sum+7;
            j--;
        }
        if(sum==n)
        {

            for(int x=1; x<=four; x++)
            {
                cout<<4;
            }

            while(seven!=0)
            {
                cout<<7;
                seven--;
            }

            return 0;
        }
    }

    if(n%4==0)
    {
        for(int y=0;y<n/4;y++){

            cout<<"4";
        }
    }
    else if(n%7==0)
    {
        for(int p=1; p<=n/7; p++)
        {
            cout<<"7";
        }
    }
    else
    {
        cout<<"-1";
        cout<<endl;
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define zhalok Zhalok
#define inf 100000.0
#define ll long long int
#define ull unsigned long long
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define negloop(i,a,b) for(ll i=a;i>=b;i--)
#define vi vector<int>
#define vll vector<ll>
#define vull vector<ull>
#define pb push_back
#define be begin()
#define en end()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define MOD 1000000007
#define sz 200000

ll cill(ll a,ll b)
{
	if(a%b==0)
	return a/b;
	return a/b+1;
	}

ll maxx(ll a,ll b)
{
	return a>b?a:b;
}

ll minn(ll a,ll b)
{
	return a<b?a:b;
}

vll take_input(ll n)
{
	vll v;
//	v.pb(0);
	loop(i,0,n)
	{
		ll x;
		cin>>x;
		v.pb(x);
	}

	return v;
}

vi take_input(int n)
{
	vi v;
	v.pb(0);
	loop(i,0,n)
	{
		int x;
		cin>>x;
		v.pb(x);
	}

	return v;
}

void print(vll v)
{
	loop(i,0,v.size())
	cout<<v[i]<<" ";
	cout<<endl;
}

void print(vpll pairs)
{
	for(int i=0;i<pairs.size();i++) cout<<pairs[i].ff<<" "<<pairs[i].ss<<endl;
}

vll num_to_vect(ll n)
{
	vll v,temp;
	v.pb(0);
	while(n)
	{
		temp.pb(n%10);
		n/=10;
	}
	reverse(temp.begin(),temp.end());
	loop(i,0,temp.size())
	v.pb(temp[i]);
	return v;
 }

ll odd_n(ll n)
{
	return (n-1)/2+1;
}

	int gcd(int a ,int b)
	{
		if(a%b==0)
		return b;
		return gcd(b,a%b);
	}

ll get_min(vll v)
{
	ll mn=inf;
	loop(i,0,v.size())
	mn=minn(mn,v[i]);

	return mn;
}

void printt(vi v)
{
	loop(i,0,v.size()) cout<<v[i]<<" "; cout<<endl;
}

int bin_to_dec(string bin)
{
	int sum=0;
	for(int i=0;i<bin.size();i++)
	{
		sum*=10;
		sum+=(bin[i]-'0');

	}
	return sum;
}

double find_dis(pair <double,double> p1,pair <double,double> p2)
{
	return sqrt((p1.ff-p2.ff)*(p1.ff-p2.ff)+(p1.ss-p2.ss)*(p1.ss-p2.ss));
}

/*vll v;

ll ans;

void merge(int l,int r)
{
	int mid=(l+r)/2;
	vll temp(r-l+1,0);
	int i=l;
	int j=mid+1;
    int k=0;
	while(i<=mid&&j<=r)
	{
		if(v[i]<=v[j]) temp[k++]=v[i++];
		else
		{
			ans+=abs(k-(j-l));
			temp[k++]=v[j++];
		}
	}
	while(i<=mid) temp[k++]=(v[i++]);
	while(j<=r) temp[k++]=(v[j++]);

	for(int i=0,k=l;i<temp.size(),k<=r;i++,k++)
	v[k]=temp[i];

}

void mergesort(int l,int r)
{
	if(l>=r) return ;
    else
    {
    	int mid=(l+r)/2;
    	mergesort(l,mid);
    	mergesort(mid+1,r);
    	merge(l,r);
	}
}

*/

//*************************************

//*********************************************************

// the code starts here ...

ll how_many_substring(string s,string sub)
{
	ll cnt=0;
	loop(i,0,(s.size()-sub.size())+1)
	{
		bool flag=true;
		for(int k=i,j=0;j<sub.size();j++,k++)
		if(s[k]!=sub[j])
		{
			flag=false;
			break;
		}
		if(flag)
		cnt++;
	}
	return cnt;
}

vi v;

int find_ans(int lo,int hi)
{
	if(lo==hi) return v[lo];

	int mid=(lo+hi)/2;
	int left=find_ans(lo,mid);
	int right=find_ans(mid+1,hi);
	return max(max(left,right),left^right);
}

ll abss(ll a,ll b)
{
	if(a>b) return a-b;
	else return b-a;
}

ll mod_exp(ll a,ll n,ll mod)
{
	if(n==0) return 1;
	if(n%2==0) return (mod_exp(a,n/2,mod)*mod_exp(a,n/2,mod))%mod;
	else return (a*mod_exp(a,n-1,mod))%mod;

}

void solve()
{

ll n;
cin>>n;
ll len1=cill(n,7);

for(int i=0;i<=len1;i++)
{

ll fours=i;
ll sevens=len1-i;
if(fours*4+sevens*7==n)
{
	for(int i=0;i<fours;i++) cout<<"4";
	for(int i=0;i<sevens;i++) cout<<"7";
	cout<<endl;
	return;
}

}

ll len2=len1+1;

for(int i=0;i<=len2;i++)
{

ll fours=i;
ll sevens=len2-i;
if(fours*4+sevens*7==n)
{
	for(int i=0;i<fours;i++) cout<<"4";
	for(int i=0;i<sevens;i++) cout<<"7";
	cout<<endl;
	return;
}

}

cout<<"-1"<<endl;

}

int main()
{

  //int t;
//  cin>>t;
 // t=100;
 // while(t--)
  solve();

}


#include<bits/stdc++.h>
using namespace std;
#define zhalok Zhalok
#define inf 100000.0
#define ll long long int
#define ull unsigned long long
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define negloop(i,a,b) for(ll i=a;i>=b;i--)
#define vi vector<int>
#define vll vector<ll>
#define vull vector<ull>
#define pb push_back
#define be begin()
#define en end()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define MOD 1000000007
#define sz 200000

ll cill(ll a,ll b)
{
	if(a%b==0)
	return a/b;
	return a/b+1;
	}

ll maxx(ll a,ll b)
{
	return a>b?a:b;
}

ll minn(ll a,ll b)
{
	return a<b?a:b;
}

vll take_input(ll n)
{
	vll v;
//	v.pb(0);
	loop(i,0,n)
	{
		ll x;
		cin>>x;
		v.pb(x);
	}

	return v;
}

vi take_input(int n)
{
	vi v;
	v.pb(0);
	loop(i,0,n)
	{
		int x;
		cin>>x;
		v.pb(x);
	}

	return v;
}

void print(vll v)
{
	loop(i,0,v.size())
	cout<<v[i]<<" ";
	cout<<endl;
}

void print(vpll pairs)
{
	for(int i=0;i<pairs.size();i++) cout<<pairs[i].ff<<" "<<pairs[i].ss<<endl;
}

vll num_to_vect(ll n)
{
	vll v,temp;
	v.pb(0);
	while(n)
	{
		temp.pb(n%10);
		n/=10;
	}
	reverse(temp.begin(),temp.end());
	loop(i,0,temp.size())
	v.pb(temp[i]);
	return v;
 }

ll odd_n(ll n)
{
	return (n-1)/2+1;
}

	int gcd(int a ,int b)
	{
		if(a%b==0)
		return b;
		return gcd(b,a%b);
	}

ll get_min(vll v)
{
	ll mn=inf;
	loop(i,0,v.size())
	mn=minn(mn,v[i]);

	return mn;
}

void printt(vi v)
{
	loop(i,0,v.size()) cout<<v[i]<<" "; cout<<endl;
}

int bin_to_dec(string bin)
{
	int sum=0;
	for(int i=0;i<bin.size();i++)
	{
		sum*=10;
		sum+=(bin[i]-'0');

	}
	return sum;
}

double find_dis(pair <double,double> p1,pair <double,double> p2)
{
	return sqrt((p1.ff-p2.ff)*(p1.ff-p2.ff)+(p1.ss-p2.ss)*(p1.ss-p2.ss));
}

/*vll v;

ll ans;

void merge(int l,int r)
{
	int mid=(l+r)/2;
	vll temp(r-l+1,0);
	int i=l;
	int j=mid+1;
    int k=0;
	while(i<=mid&&j<=r)
	{
		if(v[i]<=v[j]) temp[k++]=v[i++];
		else
		{
			ans+=abs(k-(j-l));
			temp[k++]=v[j++];
		}
	}
	while(i<=mid) temp[k++]=(v[i++]);
	while(j<=r) temp[k++]=(v[j++]);

	for(int i=0,k=l;i<temp.size(),k<=r;i++,k++)
	v[k]=temp[i];

}

void mergesort(int l,int r)
{
	if(l>=r) return ;
    else
    {
    	int mid=(l+r)/2;
    	mergesort(l,mid);
    	mergesort(mid+1,r);
    	merge(l,r);
	}
}

*/

//*************************************

//*********************************************************

// the code starts here ...

ll how_many_substring(string s,string sub)
{
	ll cnt=0;
	loop(i,0,(s.size()-sub.size())+1)
	{
		bool flag=true;
		for(int k=i,j=0;j<sub.size();j++,k++)
		if(s[k]!=sub[j])
		{
			flag=false;
			break;
		}
		if(flag)
		cnt++;
	}
	return cnt;
}

vi v;

int find_ans(int lo,int hi)
{
	if(lo==hi) return v[lo];

	int mid=(lo+hi)/2;
	int left=find_ans(lo,mid);
	int right=find_ans(mid+1,hi);
	return max(max(left,right),left^right);
}

ll abss(ll a,ll b)
{
	if(a>b) return a-b;
	else return b-a;
}

ll mod_exp(ll a,ll n,ll mod)
{
	if(n==0) return 1;
	if(n%2==0) return (mod_exp(a,n/2,mod)*mod_exp(a,n/2,mod))%mod;
	else return (a*mod_exp(a,n-1,mod))%mod;

}

void solve()
{

ll n;
cin>>n;
ll len=cill(n,7);

for(int i=0;i<=len;i++)
{

ll fours=i;
ll sevens=len-i;
if(fours*4+sevens*7==n)
{
	for(int i=0;i<fours;i++) cout<<"4";
	for(int i=0;i<sevens;i++) cout<<"7";
	cout<<endl;
	return;
}

if(n%4==0)
{
	for(int i=0;i<n/4;i++) cout<<"4";
	cout<<endl;
	return ;
}

}

cout<<"-1"<<endl;

}

int main()
{

  //int t;
//  cin>>t;
 // t=100;
 // while(t--)
  solve();

}