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

#define pb push_back
#define mod 1000000007
#define rep(i, n)    for(long long int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(long long int i = a; i <= (n); ++i)
#define fill(a)  memset(a, 0, sizeof (a))
#define endl '\n'

typedef long long int ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef vector<pair<ll,ll>> vpll;
typedef vector<int> vi;

void solve(){
	ll n;
	cin >> n;
	vll a(n);
	rep(i,n)	cin >> a[i];
	ll i=0,j=n-1;
	while(i<j){
		if(i==j-1){
			ll temp = (a[i]+a[i+1])/2;
			a[j] += a[i]-temp;
			a[i] = temp;
			i++,j--;
		}
		else{
			if(a[i+1]-a[i] < a[j]-a[j-1]){
				ll temp = a[i+1]-a[i];
				a[i] = a[i+1];
				a[j] -= temp;
				i++;
			}
			else{
				ll temp = a[j]-a[j-1];
				a[j] = a[j-1];
				a[i] += temp;
				j--;
			}
		}
	}
	rep(i,n)	cout << a[i] << " ";
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	#endif

	int t=1;
	// cin >> t;
	// pre();
	// int cnt=0;
	while(t--){
		// cout << "Case #" << ++cnt << ": ";
		solve();
	}

	return 0;
}


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

#define pb push_back
#define mod 1000000007
#define rep(i, n)    for(long long int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(long long int i = a; i <= (n); ++i)
#define fill(a)  memset(a, 0, sizeof (a))
#define endl '\n'

typedef long long int ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef vector<pair<ll,ll>> vpll;
typedef vector<int> vi;

void solve(){
	ll n;
	cin >> n;
	vll a(n);
	rep(i,n)	cin >> a[i];
	int flag=0;
	for(ll i=0;i<n-1;i++){
		if(a[i+1]-a[i]!=1){
			flag=1;
			break;
		}
	}
	vll dp(n, n-1);
	for(ll i=n-2;i>=0;i--){
		if(a[i]==a[i+1]-1){
			dp[i] = dp[i+1];
		}
		else{
			dp[i] = i;
		}
	}
	ll i=0,j=n-1;
	while(flag && i<j){
		if(dp[i] >= j || (dp[i] >= j-1 && a[j-1]==a[j]-1))
			break;

		if(i==j-1){
			ll temp = (a[i]+a[i+1])/2;
			a[j] += a[i]-temp;
			a[i] = temp;
			i++,j--;
		}
		else{
			if(a[i+1]-a[i] < a[j]-a[j-1]){
				ll temp = a[i+1]-a[i];
				a[i] = a[i+1];
				a[j] -= temp;
				i++;
			}
			else{
				ll temp = a[j]-a[j-1];
				a[j] = a[j-1];
				a[i] += temp;
				j--;
			}
		}
	}
	rep(i,n)	cout << a[i] << " ";
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	#endif

	int t=1;
	// cin >> t;
	// pre();
	// int cnt=0;
	while(t--){
		// cout << "Case #" << ++cnt << ": ";
		solve();
	}

	return 0;
}


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

#define pb push_back
#define mod 1000000007
#define rep(i, n)    for(long long int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(long long int i = a; i <= (n); ++i)
#define fill(a)  memset(a, 0, sizeof (a))
#define endl '\n'

typedef long long int ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef vector<pair<ll,ll>> vpll;
typedef vector<int> vi;

void solve(){
	ll n;
	cin >> n;
	vll a(n);
	rep(i,n)	cin >> a[i];
	int flag=0;
	for(ll i=0;i<n-1;i++){
		if(a[i+1]-a[i]!=1){
			flag=1;
			break;
		}
	}
	ll i=0,j=n-1;
	while(flag && i<j){
		if(i==j-1){
			ll temp = (a[i]+a[i+1])/2;
			a[j] += a[i]-temp;
			a[i] = temp;
			i++,j--;
		}
		else{
			if(a[i+1]-a[i] < a[j]-a[j-1]){
				ll temp = a[i+1]-a[i];
				a[i] = a[i+1];
				a[j] -= temp;
				i++;
			}
			else{
				ll temp = a[j]-a[j-1];
				a[j] = a[j-1];
				a[i] += temp;
				j--;
			}
		}
	}
	rep(i,n)	cout << a[i] << " ";
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	#endif

	int t=1;
	// cin >> t;
	// pre();
	// int cnt=0;
	while(t--){
		// cout << "Case #" << ++cnt << ": ";
		solve();
	}

	return 0;
}


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

#define pb push_back
#define mod 1000000007
#define rep(i, n)    for(long long int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(long long int i = a; i <= (n); ++i)
#define fill(a)  memset(a, 0, sizeof (a))
#define endl '\n'

typedef long long int ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef vector<pair<ll,ll>> vpll;
typedef vector<int> vi;

void solve(){
	ll n;
	cin >> n;
	vll a(n);
	rep(i,n)	cin >> a[i];
	ll sum=0;
	rep(i,n)	sum+=a[i];
	ll len=n;
	rep(i,n){
		long double x = (long double)(sum)/len - (long double)(len-1)/2;
		ll val = ceil(x);
		a[i] = val;
		sum -= val;
		len--;
	}
	rep(i,n)	cout << a[i] << " ";
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	#endif

	int t=1;
	// cin >> t;
	// pre();
	// int cnt=0;
	while(t--){
		// cout << "Case #" << ++cnt << ": ";
		solve();
	}

	return 0;
}


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

#define pb push_back
#define mod 1000000007
#define rep(i, n)    for(long long int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(long long int i = a; i <= (n); ++i)
#define fill(a)  memset(a, 0, sizeof (a))
#define endl '\n'

typedef long long int ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef vector<pair<ll,ll>> vpll;
typedef vector<int> vi;

void solve(){
	ll n;
	cin >> n;
	vll a(n);
	rep(i,n)	cin >> a[i];
	int flag=0;
	for(ll i=0;i<n-1;i++){
		if(a[i+1]-a[i]!=1){
			flag=1;
			break;
		}
	}
	vll dp(n, n-1);
	for(ll i=n-2;i>=0;i--){
		if(a[i]==a[i+1]-1){
			dp[i] = dp[i+1];
		}
		else{
			dp[i] = i;
		}
	}
	ll i=0,j=n-1;
	while(flag && i<j){
		if(dp[i] >= j || (dp[i] >= j-1 && a[j-1]==a[j]-1) || (dp[i+1] >= j && a[i]==a[i+1]-1))
			break;

		if(i==j-1){
			ll temp = (a[i]+a[i+1])/2;
			a[j] += a[i]-temp;
			a[i] = temp;
			i++,j--;
		}
		else{
			if(a[i+1]-a[i] < a[j]-a[j-1]){
				ll temp = a[i+1]-a[i];
				a[i] = a[i+1];
				a[j] -= temp;
				i++;
			}
			else{
				ll temp = a[j]-a[j-1];
				a[j] = a[j-1];
				a[i] += temp;
				j--;
			}
		}
	}
	rep(i,n)	cout << a[i] << " ";
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	#endif

	int t=1;
	// cin >> t;
	// pre();
	// int cnt=0;
	while(t--){
		// cout << "Case #" << ++cnt << ": ";
		solve();
	}

	return 0;
}


#include <iostream>
#define NMAX 1000005

using namespace std;

int n;
long long v[NMAX + 2],s,inc,r,curr;

int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0)
    cin >> n;
    for(int i = 1;i <= n;i++) {
        cin >> v[i];
        s += v[i];
    }
    inc = (s - 1LL * (n - 1) * n / 2) / n;
    r = (s - 1LL * (n - 1) * n / 2) % n;
    if(r != 0)
        inc++;
    curr = inc;
    for(int i = 1;i <= n;i++)
        if(i != r)
            cout << curr++ << ' ';
        else
            cout << curr << ' ';
    return 0;
}


#include <bits/stdc++.h>
#define NMAX 1000005

using namespace std;

long long a[NMAX],s,d,m;
int n;

int main()
{
    cin >> n;
    for(int i = 1;i <= n;i++) {
        cin >> a[i];
        s += a[i] - a[1] - i+1;
    }
    d = s / n;
    m = s % n;
    for(int i = 1;i <= n;i++)
    {
        if(i != 1)
            cout<<' ';
        cout << a[1] + d + i - 1 + (i <= m);
    }
    return 0;
}


#include <bits/stdc++.h>
#define NMAX 1000005

using namespace std;

long long v[NMAX],s,n,a,b;

int main()
{
    cin >> n;
    for(int i = 0;i < n;i++) {
        cin >> v[i];
        s += v[i] - v[0] - i;
    }
    a = s / n;
    b = s % n;
    for(int i = 0;i < n;i++)
        if (i < b)
            cout << v[0] + a + i + 1 << " ";
        else
            cout << v[0] + a + i << " ";
    return 0;
}


#include <bits/stdc++.h>
#define NMAX 1000005

using namespace std;

int n;
long long v[NMAX + 2],s,inc,r,curr;

int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for(int i = 1;i <= n;i++) {
        cin >> v[i];
        s += v[i];
    }
    inc = (s - 1LL * (n - 1) * n / 2) / n;
    r = (s - 1LL * (n - 1) * n / 2) % n;
    if(r != 0)
        inc++;
    curr = inc;
    for(int i = 1;i <= n;i++)
        if(i != r)
            cout << curr++ << ' ';
        else
            cout << curr << ' ';
    return 0;
}


#include <iostream>
#define NMAX 1000005

using namespace std;

int n;
long long v[NMAX + 2],s,inc,r,curr;

int main()
{
    cin >> n;
    for(int i = 1;i <= n;i++) {
        cin >> v[i];
        s += v[i];
    }
    inc = (s - 1LL * (n - 1) * n / 2) / n;
    r = (s - 1LL * (n - 1) * n / 2) % n;
    if(r != 0)
        inc++;
    curr = inc;
    for(int i = 1;i <= n;i++)
        if(i != r)
            cout << curr++ << ' ';
        else
            cout << curr << ' ';
    return 0;
}


#include<cstdio>
//cnt0<=1 is enough

int main(){
    long long n;
    scanf("%lld",&n);
    long long sum = 0;
    for(int i = 1; i <= n; i++){
        long long u;
        scanf("%lld",&u);
        sum += u;
    }
    long long k = n-(sum-n*(n-1)/2)%n;
    long long x = (sum-n*(n-1)/2+k)/n;
    long long diff = 0;
    for(int i = 1; i <= n; i++){
        printf("%lld ",x+diff);
        if(k+i==n){}
        else diff++;
    }
    printf("\n");
    return 0;
}


#include<cstdio>
//cnt0<=1 is enough

int main(){
    long long n;
    scanf("%lld",&n);
    long long sum = 0;
    for(int i = 1; i <= n; i++){
        long long u;
        scanf("%lld",&u);
        sum += u;
    }
    long long k = (n-(sum-n*(n-1)/2)%n)%n;
    long long x = (sum-n*(n-1)/2+k)/n;
    //printf("x = %lld, k = %lld\n",x,k);
    long long diff = 0;
    for(int i = 1; i <= n; i++){
        printf("%lld ",x+diff);
        if(k+i==n){}
        else diff++;
    }
    printf("\n");
    return 0;
}


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

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a)  memset(a, 0, sizeof (a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

void pre(){

}

void solve(){

}
ll h[1000009];
ll ans[1000009];
struct Node {
	Node *l = 0, *r = 0;
	int lo, hi;
	ll madd = 0, val = 0;
	Node(int lo, int hi) : lo(lo), hi(hi) {
		if (lo + 1 < hi) {
			int mid = lo + (hi - lo)/2;
			l = new Node(lo, mid); r = new Node(mid, hi);
		}
		else val = 0;
	}
	ll query(int L, int R) {
		if (R <= lo || hi <= L) return 0;
		if (L <= lo && hi <= R) return val;
		push();
		return max(l->query(L, R), r->query(L, R));
	}
	void add(int L, int R, ll x) {
		if (R <= lo || hi <= L) return;
		if (L <= lo && hi <= R) {
			madd += x;
			val += x;
		}
		else {
			push(), l->add(L, R, x), r->add(L, R, x);
			val = max(l->val, r->val);
		}
	}
	void push() {
		if (madd)
			l->add(lo,hi,madd), r->add(lo,hi,madd), madd = 0;
	}
};
struct FT {
	vector<ll> s;
	FT(int n) : s(n+7,0ll) {}
	void update(int pos, ll dif) { // a[pos] += dif
		for (; pos < sz(s); pos |= pos + 1) s[pos] += dif;
	}
	void add(int l,int r,ll x){
		update(l,x);
		update(r,-x);
	}
	ll query(int pos) { // sum of values in [0, pos)
		ll res = 0;
		for (; pos > 0; pos &= pos - 1) res += s[pos-1];
		return res;
	}
	int lower_bound(ll sum) {// min pos st sum of [0, pos] >= sum
		// Returns n if no sum is >= sum, or -1 if empty sum is.
		if (sum <= 0) return -1;
		int pos = 0;
		for (int pw = 1 << 25; pw; pw >>= 1) {
			if (pos + pw <= sz(s) && s[pos + pw-1] < sum)
				pos += pw, sum -= s[pos-1];
		}
		return pos;
	}
};
int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit);
	pre();
	int n;cin>>n;
	rep(i,n){
		cin>>h[i];
	}
	FT N(n);
	vi v;
	v.pb(0);
	N.add(0,1,h[0]);
	repA(i,1,n-1){
		ll lst = N.query(i);
		bool fg=0;
		while(sz(v)>1){
			int j = v.back();
			int l = i-j;
			if(h[i]-l>=lst+1) {
				N.add(j,i,1);
				lst++;
				h[i]-=l;
				v.pop_back();
				continue;
			}
			else{
				fg=1;
				if(h[i]==lst){
					v.pb(i);
				}
				else if(h[i]==lst+1){

				}
				else{
					ll x = h[i]-lst-1;
					N.add(j,j+x,1);
					v.pop_back();
					v.pb(j+x);
					h[i]=lst+1;
				}
				N.add(i,i+1,h[i]);
				break;
			}
		}
		if(!fg){
			ll lo = 0,hi = h[i]-lst-1;
			while(lo<hi){
				ll mid = (lo+hi)/2;mid++;
				if(mid%i!=0){
					if(lst+mid/i<h[i]-mid){
						lo=mid;
					}
					else hi=mid-1;
				}
				if(mid%i==0){
					if(lst+mid/i<=h[i]-mid){
						lo=mid;
					}
					else hi=mid-1;
				}
			}
			h[i]-=lo;
			lst+=lo/i;
			N.add(0,i,lo/i);
			if(lo%i!=0){
				N.add(0,lo%i,1);
				v.pb(lo%i);
			}
			N.add(i,i+1,h[i]);
			if(h[i]==lst) v.pb(i);
		}
	}
	rep(i,n) cout<<N.query(i+1)<<' ';
	return 0;
}


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

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a)  memset(a, 0, sizeof (a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

void pre(){

}

void solve(){

}
ll h[1000009];
ll ans[1000009];
struct Node {
	Node *l = 0, *r = 0;
	int lo, hi;
	ll madd = 0, val = 0;
	Node(int lo, int hi) : lo(lo), hi(hi) {
		if (lo + 1 < hi) {
			int mid = lo + (hi - lo)/2;
			l = new Node(lo, mid); r = new Node(mid, hi);
		}
		else val = 0;
	}
	ll query(int L, int R) {
		if (R <= lo || hi <= L) return 0;
		if (L <= lo && hi <= R) return val;
		push();
		return max(l->query(L, R), r->query(L, R));
	}
	void add(int L, int R, ll x) {
		if (R <= lo || hi <= L) return;
		if (L <= lo && hi <= R) {
			madd += x;
			val += x;
		}
		else {
			push(), l->add(L, R, x), r->add(L, R, x);
			val = max(l->val, r->val);
		}
	}
	void push() {
		if (madd)
			l->add(lo,hi,madd), r->add(lo,hi,madd), madd = 0;
	}
};
int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit);
	pre();
	int n;cin>>n;
	rep(i,n){
		cin>>h[i];
	}
	Node N(0,n);
	vi v;
	v.pb(0);
	N.add(0,1,h[0]);
	repA(i,1,n-1){
		ll lst = N.query(i-1,i);
		bool fg=0;
		while(sz(v)>1){
			int j = v.back();
			int l = i-j;
			if(h[i]-l>=lst+1) {
				N.add(j,i,1);
				lst++;
				h[i]-=l;
				v.pop_back();
				continue;
			}
			else{
				fg=1;
				if(h[i]==lst){
					v.pb(i);
				}
				else if(h[i]==lst+1){

				}
				else{
					ll x = h[i]-lst-1;
					N.add(j,j+x,1);
					v.pop_back();
					v.pb(j+x);
					h[i]=lst+1;
				}
				N.add(i,i+1,h[i]);
				break;
			}
		}
		if(!fg){
			ll lo = 0,hi = h[i]-lst-1;
			while(lo<hi){
				ll mid = (lo+hi)/2;mid++;
				if(lst+mid/i<=h[i]-mid){
					lo=mid;
				}
				else hi=mid-1;
			}
			h[i]-=lo;
			lst+=lo/i;
			N.add(0,i,lo/i);
			if(lo%i!=0){
				N.add(0,lo%i,1);
				v.pb(lo%i);
			}
			N.add(i,i+1,h[i]);
			if(h[i]==lst) v.pb(i);
		}
	}
	rep(i,n) cout<<N.query(i,i+1)<<' ';
	return 0;
}


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

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a)  memset(a, 0, sizeof (a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

void pre(){

}

void solve(){

}
ll h[1000009];
ll ans[1000009];
const int inf = 1e9;
struct Node {
	Node *l = 0, *r = 0;
	int lo, hi;
	ll madd = 0, val = 0;
	Node(int lo, int hi) : lo(lo), hi(hi) {
		if (lo + 1 < hi) {
			int mid = lo + (hi - lo)/2;
			l = new Node(lo, mid); r = new Node(mid, hi);
		}
		else val = 0;
	}
	ll query(int L, int R) {
		if (R <= lo || hi <= L) return -inf;
		if (L <= lo && hi <= R) return val;
		push();
		return max(l->query(L, R), r->query(L, R));
	}
	void add(int L, int R, int x) {
		if (R <= lo || hi <= L) return;
		if (L <= lo && hi <= R) {
			madd += x;
			val += x;
		}
		else {
			push(), l->add(L, R, x), r->add(L, R, x);
			val = max(l->val, r->val);
		}
	}
	void push() {
		if (madd)
			l->add(lo,hi,madd), r->add(lo,hi,madd), madd = 0;
	}
};
int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit);
	pre();
	int n;cin>>n;
	rep(i,n){
		cin>>h[i];
	}
	Node N(0,n);
	vi v;
	v.pb(0);
	N.add(0,1,h[0]);
	repA(i,1,n-1){
		ll lst = N.query(i-1,i);
		bool fg=0;
		while(sz(v)>1){
			int j = v.back();
			int l = i-j;
			if(h[i]-l>=lst+1) {
				N.add(j,i,1);
				lst++;
				h[i]-=l;
				v.pop_back();
				continue;
			}
			else{
				fg=1;
				if(h[i]==lst){
					v.pb(i);
				}
				else if(h[i]==lst+1){

				}
				else{
					ll x = h[i]-lst-1;
					N.add(j,j+x,1);
					v.pop_back();
					v.pb(j+x);
					h[i]=lst+1;
				}
				N.add(i,i+1,h[i]);
				break;
			}
		}
		if(!fg){
			ll lo = 0,hi = h[i]-lst-1;
			while(lo<hi){
				ll mid = (lo+hi)/2;mid++;
				if(lst+mid/i<=h[i]-mid){
					lo=mid;
				}
				else hi=mid-1;
			}
			h[i]-=lo;
			lst+=lo/i;
			N.add(0,i,lo/i);
			if(lo%i!=0){
				N.add(0,lo%i,1);
				v.pb(lo%i);
			}
			N.add(i,i+1,h[i]);
			if(h[i]==lst) v.pb(i);
		}
	}
	rep(i,n) cout<<N.query(i,i+1)<<' ';
	return 0;
}


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

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a)  memset(a, 0, sizeof (a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

void pre(){

}

void solve(){

}
ll h[1000009];
ll ans[1000009];
struct Node {
	Node *l = 0, *r = 0;
	int lo, hi;
	ll madd = 0, val = 0;
	Node(int lo, int hi) : lo(lo), hi(hi) {
		if (lo + 1 < hi) {
			int mid = lo + (hi - lo)/2;
			l = new Node(lo, mid); r = new Node(mid, hi);
		}
		else val = 0;
	}
	ll query(int L, int R) {
		if (R <= lo || hi <= L) return 0;
		if (L <= lo && hi <= R) return val;
		push();
		return max(l->query(L, R), r->query(L, R));
	}
	void add(int L, int R, ll x) {
		if (R <= lo || hi <= L) return;
		if (L <= lo && hi <= R) {
			madd += x;
			val += x;
		}
		else {
			push(), l->add(L, R, x), r->add(L, R, x);
			val = max(l->val, r->val);
		}
	}
	void push() {
		if (madd)
			l->add(lo,hi,madd), r->add(lo,hi,madd), madd = 0;
	}
};
int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit);
	pre();
	int n;cin>>n;
	rep(i,n){
		cin>>h[i];
	}
	Node N(0,n);
	vi v;
	v.pb(0);
	N.add(0,1,h[0]);
	repA(i,1,n-1){
		ll lst = N.query(i-1,i);
		bool fg=0;
		while(sz(v)>1){
			int j = v.back();
			int l = i-j;
			if(h[i]-l>=lst+1) {
				N.add(j,i,1);
				lst++;
				h[i]-=l;
				v.pop_back();
				continue;
			}
			else{
				fg=1;
				if(h[i]==lst){
					v.pb(i);
				}
				else if(h[i]==lst+1){

				}
				else{
					ll x = h[i]-lst-1;
					N.add(j,j+x,1);
					v.pop_back();
					v.pb(j+x);
					h[i]=lst+1;
				}
				N.add(i,i+1,h[i]);
				break;
			}
		}
		if(!fg){
			ll lo = 0,hi = h[i]-lst-1;
			while(lo<hi){
				ll mid = (lo+hi)/2;mid++;
				if(mid%i!=0){
					if(lst+mid/i<h[i]-mid){
						lo=mid;
					}
					else hi=mid-1;
				}
				if(mid%i==0){
					if(lst+mid/i<=h[i]-mid){
						lo=mid;
					}
					else hi=mid-1;
				}
			}
			h[i]-=lo;
			lst+=lo/i;
			N.add(0,i,lo/i);
			if(lo%i!=0){
				N.add(0,lo%i,1);
				v.pb(lo%i);
			}
			N.add(i,i+1,h[i]);
			if(h[i]==lst) v.pb(i);
		}
		debug(i,h[i]);
	}
	rep(i,n) cout<<N.query(i,i+1)<<' ';
	return 0;
}


#include <bits/stdc++.h>
#define rf(x) (x)=0;while(*p<48)im=*p++=='-';while(47<*p)(x)=((x)<<3)+((x)<<1)+(*p++&15);if(im)(x)=-(x); //from yclock
using namespace std;
using ll = long long;
static bool im=false;
static unsigned char str[15000000], *p=str;
const ll INF = 1LL * 1e12, LIM = 2e9;

ll A[1000009], B[1000009], P[1000009];

int main() {
	fread(str, 1, 15000000, stdin);
	int N; rf(N);
	for(int i=1; i<=N; i++) {
		ll x; rf(x);
		A[i] = x;
		P[i] = P[i-1] + A[i];
	}
	B[N+1] = INF;
	ll up = 0;
	for(int i=N; i>=1; i--) {
		ll l = 0, r = min(A[i] + up, B[i+1]), f = -1;
		while(l <= r) {
			ll m = l+r >> 1;
			ll lst = max(m - i, 0LL);
			__int128 mn = (__int128)m*(m+1)/2 - (__int128)lst*(lst+1)/2;
			if(mn > P[i] + up) r = m-1;
			else l = m+1, f = m;
		}
		B[i] = f;
		up += A[i] - f;
	}
	assert(up == 0);
	for(int i=1; i<=N; i++) printf("%lld ", B[i]);
	return 0;
}


#include <bits/stdc++.h>
#define rf(x) (x)=0;while(*p<48)im=*p++=='-';while(47<*p)(x)=((x)<<3)+((x)<<1)+(*p++&15);if(im)(x)=-(x); //from yclock
using namespace std;
using ll = long long;
static bool im=false;
static unsigned char str[15000000], *p=str;
const ll INF = 1LL * 1e12, LIM = 2e9;

ll A[1000009], B[1000009], P[1000009];

int main() {
	fread(str, 1, 15000000, stdin);
	int N; rf(N);
	for(int i=1; i<=N; i++) {
		ll x; rf(x);
		A[i] = x;
		P[i] = P[i-1] + A[i];
	}
	B[N+1] = INF;
	ll up = 0;
	for(int i=N; i>=1; i--) {
		ll l = 0, r = min(A[i] + up, B[i+1]), f = -1;
		while(l <= r) {
			ll m = l+r >> 1;
			ll lst = max(m - i, 0LL);
			if((m+lst) > ((P[i] + up) * 2 - m + lst) / (m-lst)) r = m-1;
			else l = m+1, f = m;
		}
		B[i] = f;
		up += A[i] - f;
	}
	assert(up == 0);
	for(int i=1; i<=N; i++) printf("%lld ", B[i]);
	return 0;
}


#include <bits/stdc++.h>
#define rf(x) (x)=0;while(*p<48)im=*p++=='-';while(47<*p)(x)=((x)<<3)+((x)<<1)+(*p++&15);if(im)(x)=-(x); //from yclock
using namespace std;
using ll = long long;
static bool im=false;
static unsigned char str[15000000], *p=str;
const ll INF = 1LL * 1e12;

ll A[1000009], B[1000009], P[1000009];

int main() {
	fread(str, 1, 15000000, stdin);
	int N; rf(N);
	for(int i=1; i<=N; i++) {
		ll x; rf(x);
		A[i] = x;
		P[i] = P[i-1] + A[i];
	}
	B[N+1] = INF;
	ll up = 0;
	for(int i=N; i>=1; i--) {
		ll l = 0, r = min(A[i] + up, B[i+1]), f = -1;
		while(l <= r) {
			ll m = l+r >> 1;
			ll lst = max(m - i, 0LL);
			if(m > 0 && (m+lst) > ((P[i] + up) * 2 - m + lst) / (m-lst)) r = m-1;
			else l = m+1, f = m;
		}
		B[i] = f;
		up += A[i] - f;
	}
	assert(up == 0);
	for(int i=1; i<=N; i++) printf("%lld ", B[i]);
	return 0;
}


#include <bits/stdc++.h>
using std::cin;
using std::cout;

int main() {
	int i, n, q, r; long long s = 0;
	std::ios::sync_with_stdio(false), cin.tie(NULL);
	cin >> n;
	for (i = 0; i < n; ++i) cin >> r, s += r - i;
	q = s / n, r = s % n;
	for (i = 0; i < n; ++i) cout << q + i + (i < r) << (i == n - 1 ? '\n' : ' ');
	return 0;
}


#include <bits/stdc++.h>
using std::cin;
using std::cout;

int main() {
	int i, n, q, r; long long s = 0;
	std::ios::sync_with_stdio(false), cin.tie(NULL);
	cin >> n;
	for (i = 0; i < n; ++i) cin >> r, s += r - i;
	q = s / n, r = s - q * n;
	for (i = 0; i < n; ++i) cout << q + i + (i < r) << (i == n - 1 ? '\n' : ' ');
	return 0;
}


#include <bits/stdc++.h>
using std::cin;
using std::cout;

int main() {
	int i, n, r; long long q, s = 0;
	std::ios::sync_with_stdio(false), cin.tie(NULL);
	cin >> n;
	for (i = 0; i < n; ++i) cin >> q, s += q - i;
	q = s / n, r = s % n;
	for (i = 0; i < n; ++i) cout << q + i + (i < r) << (i == n - 1 ? '\n' : ' ');
	return 0;
}


//In the Name of God

#include<iostream>
#include<vector>

using namespace std;

const int M=130000;
int n,m,R,A,S,D,h[M];
bool f[M];
vector<int> g[M];

bool dfs(int v,int p=0)
{
  bool c=f[v];
  h[v]=h[p]+1;
  if(f[v] and h[v]>=D)
    R=v,D=h[v];
  for(int i=0;i<g[v].size();i++)
    if(g[v][i]!=p)
      c|=dfs(g[v][i],v);
  if(c)
    A++;
  return c;
}

void check()
{
  for(int i=1;i;i++)
    if(f[i] and (!h[i] or h[i]==D))
      S=i,i=-1;
}

int main()
{
  ios_base::sync_with_stdio(0);
  cin>>n>>m;
  for(int v,u,i=n-1;i--;)
    {
      cin>>v>>u;
      g[v].push_back(u);
      g[u].push_back(v);
    }
  for(h[0]=-1;m--;cin>>R,f[R]=true);
  if(n==9841)
    cout<<D<<endl;
  dfs(R);dfs(R);check();if(n==9841)cout<<S<<" "<<h[1]<<endl;dfs(R);check();if(n==9841)cout<<S<<" "<<h[1]<<endl;
  cout<<S<<endl<<(A-3)/3*2-D<<endl;
  return 0;
}


//In the Name of God

#include<iostream>
#include<vector>

using namespace std;

const int M=130000;
int n,m,R,A,S,S1,D,h[M];
bool f[M];
vector<int> g[M];

bool dfs(int v,int p=0)
{
  bool c=f[v];
  h[v]=h[p]+1;
  if(c and h[v]>=D) R=v,D=h[v];
  if(c and v<S and (!h[v] or h[v]==D)) S=v;
  for(int i=0;i<g[v].size();i++)
    if(g[v][i]!=p) c|=dfs(g[v][i],v);
  if(c) A++;
  return c;
}

int main()
{
  ios_base::sync_with_stdio(0);
  cin>>n>>m;
  for(int v,u,i=n-1;i--;)
    {
      cin>>v>>u;
      g[v].push_back(u);
      g[u].push_back(v);
    }
  for(h[0]=-1;m--;cin>>R,f[R]=true);
  dfs(R);S=M;dfs(R);S1=S,dfs(R);
  cout<<min(S,S1)<<endl<<(A-3)/3*2-D<<endl;
  return 0;
}


//In the Name of God

#include<iostream>
#include<vector>

using namespace std;

const int maxn=150000;
int n,m,R,ans,start,Dis,dis[maxn];
bool f[maxn];
vector<int> g[maxn];

bool dfs(int v,int par=0)
{
  bool ret=false;
  dis[v]=dis[par]+1;
  if(f[v] and dis[v]>Dis)
    R=v,Dis=dis[v];
  for(int i=0;i<g[v].size();i++)
    if(g[v][i]!=par)
      ret|=dfs(g[v][i],v);
  ret|=f[v];
  if(ret)
    ans++;
  return ret;
}

int main()
{
  ios_base::sync_with_stdio(0);
  cin>>n>>m;
  for(int v,u,i=1;i<n;i++)
    {
      cin>>v>>u;
      g[v].push_back(u);
      g[u].push_back(v);
    }
  for(int i=0;i<m;i++)
    {
      cin>>R;
      f[R]=true;
    }
  dis[0]=-1;
  dfs(R);
  dfs(R);
  for(int i=1;i<=n;i++)
    if(dis[i]==0 or dis[i]==Dis)
      {
	start=i;
	break;
      }
  cout<<start<<endl<<ans-2-Dis<<endl;
  return 0;
}


//In the Name of God

#include<iostream>
#include<vector>

using namespace std;

const int M=130000;
int n,m,R,A,S,D,h[M];
bool f[M];
vector<int> g[M];

bool dfs(int v,int p=0)
{
  bool c=f[v];
  h[v]=h[p]+1;
  if(f[v] and h[v]>=D)
    R=v,D=h[v];
  for(int i=0;i<g[v].size();i++)
    if(g[v][i]!=p)
      c|=dfs(g[v][i],v);
  if(c)
    A++;
  return c;
}

void check()
{
  for(int i=1;i;i++)
    if(f[i] and (!h[i] or h[i]==D))
      S=i,i=-1;
}

int main()
{
  ios_base::sync_with_stdio(0);
  cin>>n>>m;
  for(int v,u,i=n-1;i--;)
    {
      cin>>v>>u;
      g[v].push_back(u);
      g[u].push_back(v);
    }
  for(h[0]=-1;m--;cin>>R,f[R]=true);
  dfs(R);dfs(R);check();if(n==9841)cout<<S<<endl;dfs(R);check();if(n==9841)cout<<S<<endl;
  cout<<S<<endl<<(A-3)/3*2-D<<endl;
  return 0;
}


//In the Name of God

#include<iostream>
#include<vector>

using namespace std;

const int M=130000;
int n,m,R,A,S,D,h[M];
bool f[M];
vector<int> g[M];

bool dfs(int v,int p=0)
{
  bool c=f[v];
  h[v]=h[p]+1;
  if(c and h[v]>=D) R=v,D=h[v];
  if(c and v<S and (!h[v] or h[v]==D)) S=v;
  for(int i=0;i<g[v].size();i++)
    if(g[v][i]!=p) c|=dfs(g[v][i],v);
  if(c) A++;
  return c;
}

int main()
{
  ios_base::sync_with_stdio(0);
  cin>>n>>m;
  for(int v,u,i=n-1;i--;)
    {
      cin>>v>>u;
      g[v].push_back(u);
      g[u].push_back(v);
    }
  for(h[0]=-1;m--;cin>>R,f[R]=true);
  dfs(R);dfs(R);S=M,dfs(R);dfs(R);
  cout<<S<<endl<<(A-4)/2-D<<endl;
  return 0;
}


/* AKSHIT CHOPRA , BITS Pilani*/
#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define spc ' '
#define pi 2*acos(0.0)
#define sqr(a) (((a) * (a)))
#define mpr make_pair
#define fi first
#define sc second
#define pb push_back
#define ffor(i,a,b) for( __typeof(b) i = a; i<=b ; ++i )
#define rfor(i,a,b) for( __typeof(b) i = a; i>=b ; --i )
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define count_one(a)    __builtin_popcountll(a)
#define isPower_2(a)      (a)&(a-1)==0
#define sz(a)           (int)(a.size())
#define all(c)          (c).begin(),(c).end()
#define allr(c)         (c).rbegin(),(c).rend()
#define loop(c,i)       for(__typeof(c.begin()) i = c.begin(); i != c.end(); i++)
#define loopr(c,i)      for(__typeof(c.rbegin()) i = c.rbegin(); i != c.rend(); i++)
#define UNIQUE(a)       sort(all(a)), (a).erase(unique(all(a)),(a).end())
#define present(c,x)    ((c).find(x) != (c).end())
#define cpresent(c,x)   (find(all(c),x) != (c).end())

const int inf = 111111111;

typedef long long LL;
typedef vector<int> vi;
typedef vector<pair<int,int> >vpii;
typedef vector <LL> vll;
typedef vector <pair<LL,LL> > vpll;
typedef pair <int,int> pii;
typedef pair <LL,LL> pll;

void io()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(15);
}

//Fast Reader
// template<class T>inline bool read(T &x){int c=getchar_unlocked();int sgn=1;while(~c&&c<'0'||c>'9'){if(c=='-')sgn=-1;c=getchar_unlocked();}for(x=0;~c&&'0'<=c&&c<='9';c=getchar_unlocked())x=x*10+c-'0'; x*=sgn; return ~c;}

LL mulmod(LL a,LL b, LL m){LL q=(LL)(((long double)a*(long double)b)/(long double)m);LL r=a*b-q*m;if(r>m)r%=m;if(r<0)r+=m;return r;}/* for TOO LARGE mod of the order 10^18 etc */

template<typename T>T mod(T a,T b){while(a < 0)a+=b ;return a%b ;}
template <typename T>T power(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mod(x*p, m);p=mod(p*p, m);n>>=1;}return x;}
template <typename T>T power(T e,T n){T x=1,p=e;while(n){if(n&1)x=x*p;p=p*p;n>>=1;}return x;}
template <typename T> T InverseEuler(T a, T m){return (a==1? 1 : power(a, m-2, m));}/*use IFF m is a prime number */
template <typename T> T gcd(T a, T b){return __gcd(a,b);}
template <typename T> T lcm(T a, T b){return (a*(b/gcd(a,b)));}

int exEuclid(int a,int b,int &x,int &y)
{
    if(a == 0)
    {
        x = 0 ;
        y = 1 ;
        return b ;
    }
    if(b == 0)
    {
        x = 1 ;
        y = 0 ;
        return a ;
    }
    int x1,y1 ;
    int g = exEuclid(b%a , a , x1,y1) ;
    x = y1 - (b/a)*x1 ;
    y = x1 ;
    return g ; // return gcd of a,b ;
}

// #define MAX 50005
// #define mod 1000000009
// bool sv[MAX] ;
// //vector<LL> primes ;
// void sieve()
// {
//     sv[1] = 1 ;
//     sv[2] = 0 ;
//     for(LL i=3;i<MAX;i+=2)
//     {
//         if(sv[i] == 0)
//         {
//             for(LL j=i*i;j<MAX;j += 2*i)
//             {
//                 if(sv[j] == 0)
//                  sv[j] = 1 ;
//             }
//         }
//     }
//     primes.pb(2) ;
//     for(LL i=3;i<MAX;i+=2)
//     {
//         if(sv[i] == 0)
//             primes.pb(i) ;
//     }
// }
#define MAX 123458
vi g[MAX] ;
vi t[MAX] ;
bool vis[MAX] ;
bool mark[MAX] ;
int dis[MAX] ;
bool dfs_build(int u)
{
    vis[u] = 1 ;
    bool res = mark[u] , f ;
    loop(g[u] , it)
    {
        if(vis[*it] == 0)
        {
            f = dfs_build(*it) ;
            if(f)
                t[u].pb(*it) , t[*it].pb(u) ;
            res |= f ;
        }
    }
    return res ;
}
void dfs_dis(int u,int d = 0)
{
    vis[u] = 1 ;
    dis[u] = d ;
    // cout << "@ " << u << endl ;
    loop(t[u] , it)
    {
        if(!vis[*it])
        {
            dfs_dis(*it , d + 1) ;
        }
    }
}
int main(int argc,char* argv[])
{
    io() ;
    #ifndef ONLINE_JUDGE
        freopen("inp.txt", "r", stdin) ;
        // freopen("out.txt", "w", stdout);
    #endif
    int  u , v , n , m ;
    cin >> n >> m ;
    ffor(i,1,n-1)
    {
        cin >> u >> v ;
        g[u].pb(v) ;
        g[v].pb(u) ;
    }
    int a ;
    ffor(i,1,m)
    {
        cin >> a ;
        mark[a] = 1 ;
    }
    int root = 1 ;
    while(!mark[root])
        root++ ;
    assert(mark[root]) ;
    dfs_build(root) ;
    v = MAX ;
    memset(vis, 0 ,sizeof(vis)) ;
    cerr << root << endl ;
    dfs_dis(root) ;
    int mx_d = -1 ;
    int nxt_root = 0 ;
    // cout << "sz = " << t[7].size() << endl ;
    ffor(i,1,n)
    {
        if(mark[i] and dis[i] > mx_d)
        {
            mx_d = dis[i] ;
            nxt_root = i ;
        }
    }
    // cout << "## nxt_root = " << nxt_root << endl ;
    memset(vis, 0 ,sizeof(vis)) ;
    memset(dis, 0 ,sizeof(dis)) ;
    dfs_dis(nxt_root) ;
    int vv = MAX ;
    mx_d = -1 ;
    ffor(i,1,n)
    {
        if(mark[i] and dis[i] > mx_d)
        {
            mx_d = dis[i] ;
            vv = i ;
        }
    }
    // cout << "$$ " << vv << endl ;
    assert(mark[vv]) ;
    v = min(v , vv) ;
    cout << v << endl ;
    int e = 0 ;
    ffor(i,1,n)
    {
        // cout << "$$ i = " << i << " , sz = " << sz(t[i]) << endl;
        e += sz(t[i]) ;
    }
    cout << (e - mx_d) << endl; // 2e - mx_d
    return 0 ;
}


/* AKSHIT CHOPRA , BITS Pilani*/
#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define spc ' '
#define pi 2*acos(0.0)
#define sqr(a) (((a) * (a)))
#define mpr make_pair
#define fi first
#define sc second
#define pb push_back
#define ffor(i,a,b) for( __typeof(b) i = a; i<=b ; ++i )
#define rfor(i,a,b) for( __typeof(b) i = a; i>=b ; --i )
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define count_one(a)    __builtin_popcountll(a)
#define isPower_2(a)      (a)&(a-1)==0
#define sz(a)           (int)(a.size())
#define all(c)          (c).begin(),(c).end()
#define allr(c)         (c).rbegin(),(c).rend()
#define loop(c,i)       for(__typeof(c.begin()) i = c.begin(); i != c.end(); i++)
#define loopr(c,i)      for(__typeof(c.rbegin()) i = c.rbegin(); i != c.rend(); i++)
#define UNIQUE(a)       sort(all(a)), (a).erase(unique(all(a)),(a).end())
#define present(c,x)    ((c).find(x) != (c).end())
#define cpresent(c,x)   (find(all(c),x) != (c).end())

const int inf = 111111111;

typedef long long LL;
typedef vector<int> vi;
typedef vector<pair<int,int> >vpii;
typedef vector <LL> vll;
typedef vector <pair<LL,LL> > vpll;
typedef pair <int,int> pii;
typedef pair <LL,LL> pll;

void io()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(15);
}

//Fast Reader
// template<class T>inline bool read(T &x){int c=getchar_unlocked();int sgn=1;while(~c&&c<'0'||c>'9'){if(c=='-')sgn=-1;c=getchar_unlocked();}for(x=0;~c&&'0'<=c&&c<='9';c=getchar_unlocked())x=x*10+c-'0'; x*=sgn; return ~c;}

LL mulmod(LL a,LL b, LL m){LL q=(LL)(((long double)a*(long double)b)/(long double)m);LL r=a*b-q*m;if(r>m)r%=m;if(r<0)r+=m;return r;}/* for TOO LARGE mod of the order 10^18 etc */

template<typename T>T mod(T a,T b){while(a < 0)a+=b ;return a%b ;}
template <typename T>T power(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mod(x*p, m);p=mod(p*p, m);n>>=1;}return x;}
template <typename T>T power(T e,T n){T x=1,p=e;while(n){if(n&1)x=x*p;p=p*p;n>>=1;}return x;}
template <typename T> T InverseEuler(T a, T m){return (a==1? 1 : power(a, m-2, m));}/*use IFF m is a prime number */
template <typename T> T gcd(T a, T b){return __gcd(a,b);}
template <typename T> T lcm(T a, T b){return (a*(b/gcd(a,b)));}

int exEuclid(int a,int b,int &x,int &y)
{
    if(a == 0)
    {
        x = 0 ;
        y = 1 ;
        return b ;
    }
    if(b == 0)
    {
        x = 1 ;
        y = 0 ;
        return a ;
    }
    int x1,y1 ;
    int g = exEuclid(b%a , a , x1,y1) ;
    x = y1 - (b/a)*x1 ;
    y = x1 ;
    return g ; // return gcd of a,b ;
}

// #define MAX 50005
// #define mod 1000000009
// bool sv[MAX] ;
// //vector<LL> primes ;
// void sieve()
// {
//     sv[1] = 1 ;
//     sv[2] = 0 ;
//     for(LL i=3;i<MAX;i+=2)
//     {
//         if(sv[i] == 0)
//         {
//             for(LL j=i*i;j<MAX;j += 2*i)
//             {
//                 if(sv[j] == 0)
//                  sv[j] = 1 ;
//             }
//         }
//     }
//     primes.pb(2) ;
//     for(LL i=3;i<MAX;i+=2)
//     {
//         if(sv[i] == 0)
//             primes.pb(i) ;
//     }
// }
#define MAX 123458
vi g[MAX] ;
vi t[MAX] ;
bool vis[MAX] ;
bool mark[MAX] ;
int dis[MAX] ;
bool dfs_build(int u)
{
    vis[u] = 1 ;
    bool res = mark[u] , f ;
    loop(g[u] , it)
    {
        if(vis[*it] == 0)
        {
            f = dfs_build(*it) ;
            if(f)
                t[u].pb(*it) , t[*it].pb(u) ;
            res |= f ;
        }
    }
    return res ;
}
void dfs_dis(int u,int d = 0)
{
    vis[u] = 1 ;
    dis[u] = d ;
    // cout << "@ " << u << endl ;
    loop(t[u] , it)
    {
        if(!vis[*it])
        {
            dfs_dis(*it , d + 1) ;
        }
    }
}
int main(int argc,char* argv[])
{
    io() ;
    #ifndef ONLINE_JUDGE
        freopen("inp.txt", "r", stdin) ;
        // freopen("out.txt", "w", stdout);
    #endif
    int  u , v , n , m ;
    cin >> n >> m ;
    ffor(i,1,n-1)
    {
        cin >> u >> v ;
        g[u].pb(v) ;
        g[v].pb(u) ;
    }
    int a ;
    ffor(i,1,m)
    {
        cin >> a ;
        mark[a] = 1 ;
    }
    int root = 1 ;
    while(!mark[root])
        root++ ;
    assert(mark[root]) ;
    dfs_build(root) ;
    v = MAX ;
    memset(vis, 0 ,sizeof(vis)) ;
    cerr << root << endl ;
    dfs_dis(root) ;
    int mx_d = -1 ;
    int nxt_root = 0 ;
    // cout << "sz = " << t[7].size() << endl ;
    ffor(i,1,n)
    {
        if(dis[i] > mx_d)
        {
            mx_d = dis[i] ;
            nxt_root = i ;
        }
    }
    // cout << "## nxt_root = " << nxt_root << endl ;
    memset(vis, 0 ,sizeof(vis)) ;
    memset(dis, 0 ,sizeof(dis)) ;
    dfs_dis(nxt_root) ;
    int vv = MAX ;
    mx_d = -1 ;
    ffor(i,1,n)
    {
        if(dis[i] > mx_d)
        {
            mx_d = dis[i] ;
            vv = i ;
        }
    }
    // cout << "$$ " << vv << endl ;
    assert(mark[vv]) ;
    v = min(v , vv) ;
    cout << v << endl ;
    int e = 0 ;
    ffor(i,1,n)
    {
        // cout << "$$ i = " << i << " , sz = " << sz(t[i]) << endl;
        e += sz(t[i]) ;
    }
    cout << (e - mx_d) << endl; // 2e - mx_d
    return 0 ;
}


/* AKSHIT CHOPRA , BITS Pilani*/
#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define spc ' '
#define pi 2*acos(0.0)
#define sqr(a) (((a) * (a)))
#define mpr make_pair
#define fi first
#define sc second
#define pb push_back
#define ffor(i,a,b) for( __typeof(b) i = a; i<=b ; ++i )
#define rfor(i,a,b) for( __typeof(b) i = a; i>=b ; --i )
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define count_one(a)    __builtin_popcountll(a)
#define isPower_2(a)      (a)&(a-1)==0
#define sz(a)           (int)(a.size())
#define all(c)          (c).begin(),(c).end()
#define allr(c)         (c).rbegin(),(c).rend()
#define loop(c,i)       for(__typeof(c.begin()) i = c.begin(); i != c.end(); i++)
#define loopr(c,i)      for(__typeof(c.rbegin()) i = c.rbegin(); i != c.rend(); i++)
#define UNIQUE(a)       sort(all(a)), (a).erase(unique(all(a)),(a).end())
#define present(c,x)    ((c).find(x) != (c).end())
#define cpresent(c,x)   (find(all(c),x) != (c).end())

const int inf = 111111111;

typedef long long LL;
typedef vector<int> vi;
typedef vector<pair<int,int> >vpii;
typedef vector <LL> vll;
typedef vector <pair<LL,LL> > vpll;
typedef pair <int,int> pii;
typedef pair <LL,LL> pll;

void io()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(15);
}

//Fast Reader
// template<class T>inline bool read(T &x){int c=getchar_unlocked();int sgn=1;while(~c&&c<'0'||c>'9'){if(c=='-')sgn=-1;c=getchar_unlocked();}for(x=0;~c&&'0'<=c&&c<='9';c=getchar_unlocked())x=x*10+c-'0'; x*=sgn; return ~c;}

LL mulmod(LL a,LL b, LL m){LL q=(LL)(((long double)a*(long double)b)/(long double)m);LL r=a*b-q*m;if(r>m)r%=m;if(r<0)r+=m;return r;}/* for TOO LARGE mod of the order 10^18 etc */

template<typename T>T mod(T a,T b){while(a < 0)a+=b ;return a%b ;}
template <typename T>T power(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mod(x*p, m);p=mod(p*p, m);n>>=1;}return x;}
template <typename T>T power(T e,T n){T x=1,p=e;while(n){if(n&1)x=x*p;p=p*p;n>>=1;}return x;}
template <typename T> T InverseEuler(T a, T m){return (a==1? 1 : power(a, m-2, m));}/*use IFF m is a prime number */
template <typename T> T gcd(T a, T b){return __gcd(a,b);}
template <typename T> T lcm(T a, T b){return (a*(b/gcd(a,b)));}

int exEuclid(int a,int b,int &x,int &y)
{
    if(a == 0)
    {
        x = 0 ;
        y = 1 ;
        return b ;
    }
    if(b == 0)
    {
        x = 1 ;
        y = 0 ;
        return a ;
    }
    int x1,y1 ;
    int g = exEuclid(b%a , a , x1,y1) ;
    x = y1 - (b/a)*x1 ;
    y = x1 ;
    return g ; // return gcd of a,b ;
}

// #define MAX 50005
// #define mod 1000000009
// bool sv[MAX] ;
// //vector<LL> primes ;
// void sieve()
// {
//     sv[1] = 1 ;
//     sv[2] = 0 ;
//     for(LL i=3;i<MAX;i+=2)
//     {
//         if(sv[i] == 0)
//         {
//             for(LL j=i*i;j<MAX;j += 2*i)
//             {
//                 if(sv[j] == 0)
//                  sv[j] = 1 ;
//             }
//         }
//     }
//     primes.pb(2) ;
//     for(LL i=3;i<MAX;i+=2)
//     {
//         if(sv[i] == 0)
//             primes.pb(i) ;
//     }
// }
#define MAX 123458
vi g[MAX] ;
vi t[MAX] ;
bool vis[MAX] ;
bool mark[MAX] ;
int dis[MAX] ;
bool dfs_build(int u)
{
    vis[u] = 1 ;
    bool res = mark[u] , f ;
    loop(g[u] , it)
    {
        if(vis[*it] == 0)
        {
            f = dfs_build(*it) ;
            if(f)
                t[u].pb(*it) , t[*it].pb(u) ;
            res |= f ;
        }
    }
    return res ;
}
void dfs_dis(int u,int d = 0)
{
    vis[u] = 1 ;
    dis[u] = d ;
    // cout << "@ " << u << endl ;
    loop(t[u] , it)
    {
        if(!vis[*it])
        {
            dfs_dis(*it , d + 1) ;
        }
    }
}
int main(int argc,char* argv[])
{
    io() ;
    #ifndef ONLINE_JUDGE
        freopen("inp.txt", "r", stdin) ;
        // freopen("out.txt", "w", stdout);
    #endif
    int  u , v , n , m ;
    cin >> n >> m ;
    ffor(i,1,n-1)
    {
        cin >> u >> v ;
        g[u].pb(v) ;
        g[v].pb(u) ;
    }
    int a ;
    ffor(i,1,m)
    {
        cin >> a ;
        mark[a] = 1 ;
    }
    int root = 1 ;
    while(!mark[root])
        root++ ;
    assert(mark[root]) ;
    dfs_build(root) ;
    v = MAX ;
    memset(vis, 0 ,sizeof(vis)) ;
    memset(dis, 0 ,sizeof(dis)) ;
    dfs_dis(root) ;
    int mx_d = -1 ;
    int nxt_root = 0 ;
    // return 0 ;
    // cout << "sz = " << t[7].size() << endl ;
    ffor(i,1,n)
    {
        if(dis[i] > mx_d)
        {
            mx_d = dis[i] ;
            nxt_root = i ;
        }
    }
    // cout << "## nxt_root = " << nxt_root << endl ;
    memset(vis, 0 ,sizeof(vis)) ;
    memset(dis, 0 ,sizeof(dis)) ;
    dfs_dis(nxt_root) ;
    int vv = MAX ;
    mx_d = -1 ;
    ffor(i,1,n)
    {

        if(dis[i] > mx_d)
        {
            mx_d = dis[i] ;
            vv = i ;
        }
    }
    // cout << "$$ " << vv << endl ;
    assert(mark[vv]) ;
    v = min(v , vv) ;
    cout << v << endl ;
    int e = 0 ;
    ffor(i,1,n)
    {
        // cout << "$$ i = " << i << " , sz = " << sz(t[i]) << endl;
        e += sz(t[i]) ;
    }
    cout << (e - mx_d) << endl;
    return 0 ;
}


/* AKSHIT CHOPRA , BITS Pilani*/
#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define spc ' '
#define pi 2*acos(0.0)
#define sqr(a) (((a) * (a)))
#define mpr make_pair
#define fi first
#define sc second
#define pb push_back
#define ffor(i,a,b) for( __typeof(b) i = a; i<=b ; ++i )
#define rfor(i,a,b) for( __typeof(b) i = a; i>=b ; --i )
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define count_one(a)    __builtin_popcountll(a)
#define isPower_2(a)      (a)&(a-1)==0
#define sz(a)           (int)(a.size())
#define all(c)          (c).begin(),(c).end()
#define allr(c)         (c).rbegin(),(c).rend()
#define loop(c,i)       for(__typeof(c.begin()) i = c.begin(); i != c.end(); i++)
#define loopr(c,i)      for(__typeof(c.rbegin()) i = c.rbegin(); i != c.rend(); i++)
#define UNIQUE(a)       sort(all(a)), (a).erase(unique(all(a)),(a).end())
#define present(c,x)    ((c).find(x) != (c).end())
#define cpresent(c,x)   (find(all(c),x) != (c).end())

const int inf = 111111111;

typedef long long LL;
typedef vector<int> vi;
typedef vector<pair<int,int> >vpii;
typedef vector <LL> vll;
typedef vector <pair<LL,LL> > vpll;
typedef pair <int,int> pii;
typedef pair <LL,LL> pll;

void io()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(15);
}

//Fast Reader
// template<class T>inline bool read(T &x){int c=getchar_unlocked();int sgn=1;while(~c&&c<'0'||c>'9'){if(c=='-')sgn=-1;c=getchar_unlocked();}for(x=0;~c&&'0'<=c&&c<='9';c=getchar_unlocked())x=x*10+c-'0'; x*=sgn; return ~c;}

LL mulmod(LL a,LL b, LL m){LL q=(LL)(((long double)a*(long double)b)/(long double)m);LL r=a*b-q*m;if(r>m)r%=m;if(r<0)r+=m;return r;}/* for TOO LARGE mod of the order 10^18 etc */

template<typename T>T mod(T a,T b){while(a < 0)a+=b ;return a%b ;}
template <typename T>T power(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mod(x*p, m);p=mod(p*p, m);n>>=1;}return x;}
template <typename T>T power(T e,T n){T x=1,p=e;while(n){if(n&1)x=x*p;p=p*p;n>>=1;}return x;}
template <typename T> T InverseEuler(T a, T m){return (a==1? 1 : power(a, m-2, m));}/*use IFF m is a prime number */
template <typename T> T gcd(T a, T b){return __gcd(a,b);}
template <typename T> T lcm(T a, T b){return (a*(b/gcd(a,b)));}

int exEuclid(int a,int b,int &x,int &y)
{
    if(a == 0)
    {
        x = 0 ;
        y = 1 ;
        return b ;
    }
    if(b == 0)
    {
        x = 1 ;
        y = 0 ;
        return a ;
    }
    int x1,y1 ;
    int g = exEuclid(b%a , a , x1,y1) ;
    x = y1 - (b/a)*x1 ;
    y = x1 ;
    return g ; // return gcd of a,b ;
}

// #define MAX 50005
// #define mod 1000000009
// bool sv[MAX] ;
// //vector<LL> primes ;
// void sieve()
// {
//     sv[1] = 1 ;
//     sv[2] = 0 ;
//     for(LL i=3;i<MAX;i+=2)
//     {
//         if(sv[i] == 0)
//         {
//             for(LL j=i*i;j<MAX;j += 2*i)
//             {
//                 if(sv[j] == 0)
//                  sv[j] = 1 ;
//             }
//         }
//     }
//     primes.pb(2) ;
//     for(LL i=3;i<MAX;i+=2)
//     {
//         if(sv[i] == 0)
//             primes.pb(i) ;
//     }
// }
#define MAX 123458
vi g[MAX] ;
vi t[MAX] ;
bool vis[MAX] ;
bool mark[MAX] ;
int dis[MAX] ;
bool dfs_build(int u)
{
    vis[u] = 1 ;
    bool res = mark[u] , f ;
    loop(g[u] , it)
    {
        if(vis[*it] == 0)
        {
            f = dfs_build(*it) ;
            if(f)
                t[u].pb(*it) , t[*it].pb(u) ;
            res |= f ;
        }
    }
    return res ;
}
void dfs_dis(int u,int d = 0)
{
    vis[u] = 1 ;
    dis[u] = d ;
    // cout << "@ " << u << endl ;
    loop(t[u] , it)
    {
        if(!vis[*it])
        {
            dfs_dis(*it , d + 1) ;
        }
    }
}
int main(int argc,char* argv[])
{
    io() ;
    #ifndef ONLINE_JUDGE
        freopen("inp.txt", "r", stdin) ;
        // freopen("out.txt", "w", stdout);
    #endif
    int  u , v , n , m ;
    cin >> n >> m ;
    ffor(i,1,n-1)
    {
        cin >> u >> v ;
        g[u].pb(v) ;
        g[v].pb(u) ;
    }
    int a ;
    ffor(i,1,m)
    {
        cin >> a ;
        mark[a] = 1 ;
    }
    int root = 1 ;
    while(!mark[root])
        root++ ;
    assert(mark[root]) ;

    dfs_build(root) ;
    v = root ;
    memset(vis, 0 ,sizeof(vis)) ;

    dfs_dis(root) ;
    int mx_d = -1 ;
    int nxt_root = 0 ;
    // cout << "sz = " << t[7].size() << endl ;
    ffor(i,1,n)
    {
        if(dis[i] > mx_d)
        {
            mx_d = dis[i] ;
            nxt_root = i ;
        }
    }
    // cout << "## nxt_root = " << nxt_root << endl ;
    memset(vis, 0 ,sizeof(vis)) ;
    memset(dis, 0 ,sizeof(dis)) ;
    dfs_dis(nxt_root) ;
    int vv = MAX ;
    mx_d = -1 ;
    ffor(i,1,n)
    {
        if(dis[i] > mx_d)
        {
            mx_d = dis[i] ;
            vv = i ;
        }
    }
    // cout << "$$ " << vv << endl ;
    assert(mark[vv]) ;
    v = min(v , vv) ;
    cout << v << endl ;
    int e = 0 ;
    ffor(i,1,n)
    {
        // cout << "$$ i = " << i << " , sz = " << sz(t[i]) << endl;
        e += sz(t[i]) ;
    }
    cout << (e - mx_d) << endl; // 2e - mx_d
    return 0 ;
}


/* AKSHIT CHOPRA , BITS Pilani*/
#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define spc ' '
#define pi 2*acos(0.0)
#define sqr(a) (((a) * (a)))
#define mpr make_pair
#define fi first
#define sc second
#define pb push_back
#define ffor(i,a,b) for( __typeof(b) i = a; i<=b ; ++i )
#define rfor(i,a,b) for( __typeof(b) i = a; i>=b ; --i )
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define count_one(a)    __builtin_popcountll(a)
#define isPower_2(a)      (a)&(a-1)==0
#define sz(a)           (int)(a.size())
#define all(c)          (c).begin(),(c).end()
#define allr(c)         (c).rbegin(),(c).rend()
#define loop(c,i)       for(__typeof(c.begin()) i = c.begin(); i != c.end(); i++)
#define loopr(c,i)      for(__typeof(c.rbegin()) i = c.rbegin(); i != c.rend(); i++)
#define UNIQUE(a)       sort(all(a)), (a).erase(unique(all(a)),(a).end())
#define present(c,x)    ((c).find(x) != (c).end())
#define cpresent(c,x)   (find(all(c),x) != (c).end())

const int inf = 111111111;

typedef long long LL;
typedef vector<int> vi;
typedef vector<pair<int,int> >vpii;
typedef vector <LL> vll;
typedef vector <pair<LL,LL> > vpll;
typedef pair <int,int> pii;
typedef pair <LL,LL> pll;

void io()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(15);
}

//Fast Reader
// template<class T>inline bool read(T &x){int c=getchar_unlocked();int sgn=1;while(~c&&c<'0'||c>'9'){if(c=='-')sgn=-1;c=getchar_unlocked();}for(x=0;~c&&'0'<=c&&c<='9';c=getchar_unlocked())x=x*10+c-'0'; x*=sgn; return ~c;}

LL mulmod(LL a,LL b, LL m){LL q=(LL)(((long double)a*(long double)b)/(long double)m);LL r=a*b-q*m;if(r>m)r%=m;if(r<0)r+=m;return r;}/* for TOO LARGE mod of the order 10^18 etc */

template<typename T>T mod(T a,T b){while(a < 0)a+=b ;return a%b ;}
template <typename T>T power(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mod(x*p, m);p=mod(p*p, m);n>>=1;}return x;}
template <typename T>T power(T e,T n){T x=1,p=e;while(n){if(n&1)x=x*p;p=p*p;n>>=1;}return x;}
template <typename T> T InverseEuler(T a, T m){return (a==1? 1 : power(a, m-2, m));}/*use IFF m is a prime number */
template <typename T> T gcd(T a, T b){return __gcd(a,b);}
template <typename T> T lcm(T a, T b){return (a*(b/gcd(a,b)));}

int exEuclid(int a,int b,int &x,int &y)
{
    if(a == 0)
    {
        x = 0 ;
        y = 1 ;
        return b ;
    }
    if(b == 0)
    {
        x = 1 ;
        y = 0 ;
        return a ;
    }
    int x1,y1 ;
    int g = exEuclid(b%a , a , x1,y1) ;
    x = y1 - (b/a)*x1 ;
    y = x1 ;
    return g ; // return gcd of a,b ;
}

// #define MAX 50005
// #define mod 1000000009
// bool sv[MAX] ;
// //vector<LL> primes ;
// void sieve()
// {
//     sv[1] = 1 ;
//     sv[2] = 0 ;
//     for(LL i=3;i<MAX;i+=2)
//     {
//         if(sv[i] == 0)
//         {
//             for(LL j=i*i;j<MAX;j += 2*i)
//             {
//                 if(sv[j] == 0)
//                  sv[j] = 1 ;
//             }
//         }
//     }
//     primes.pb(2) ;
//     for(LL i=3;i<MAX;i+=2)
//     {
//         if(sv[i] == 0)
//             primes.pb(i) ;
//     }
// }
#define MAX 123458
vi g[MAX] ;
vi t[MAX] ;
bool vis[MAX] ;
bool mark[MAX] ;
int dis[MAX] ;
int mx_d ;
int v ;
bool dfs_build(int u)
{
    vis[u] = 1 ;
    bool res = mark[u] , f ;
    loop(g[u] , it)
    {
        if(vis[*it] == 0)
        {
            f = dfs_build(*it) ;
            if(f)
                t[u].pb(*it) , t[*it].pb(u) ;
            res |= f ;
        }
    }
    return res ;
}
void dfs_dis(int u,int d = 0)
{
    if(d > mx_d)
    {
        mx_d = d ;
        v = u ;
    }
    else if(d == mx_d)
    {
        v = min(v , u) ;
    }
    vis[u] = 1 ;
    dis[u] = d ;
    // cout << "@ " << u << endl ;
    loop(t[u] , it)
    {
        if(!vis[*it])
        {
            dfs_dis(*it , d + 1) ;
        }
    }
}
int main(int argc,char* argv[])
{
    io() ;
    #ifndef ONLINE_JUDGE
        freopen("inp.txt", "r", stdin) ;
        // freopen("out.txt", "w", stdout);
    #endif
    int  u , n , m ;
    cin >> n >> m ;
    ffor(i,1,n-1)
    {
        cin >> u >> v ;
        g[u].pb(v) ;
        g[v].pb(u) ;
    }
    int a ;
    ffor(i,1,m)
    {
        cin >> a ;
        mark[a] = 1 ;
    }
    int root = 1 ;
    while(!mark[root])
        root++ ;
    assert(mark[root]) ;
    dfs_build(root) ;
    v = MAX ;
    memset(vis, 0 ,sizeof(vis)) ;
    // cerr << root << endl ;
    v = MAX ;
    dfs_dis(root) ;
    mx_d = 0 ;
    // cout << "## nxt_root = " << nxt_root << endl ;
    memset(vis, 0 ,sizeof(vis)) ;
    memset(dis, 0 ,sizeof(dis)) ;
    int vv = v ;
    v = MAX ;
    dfs_dis(vv) ;

    v = min(v , vv) ;
    cout << v << endl ;
    int e = 0 ;
    ffor(i,1,n)
    {
        // cout << "$$ i = " << i << " , sz = " << sz(t[i]) << endl;
        e += sz(t[i]) ;
    }
    cout << (e - mx_d) << endl; // 2e - mx_d
    return 0 ;
}


/* AKSHIT CHOPRA , BITS Pilani*/
#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define spc ' '
#define pi 2*acos(0.0)
#define sqr(a) (((a) * (a)))
#define mpr make_pair
#define fi first
#define sc second
#define pb push_back
#define ffor(i,a,b) for( __typeof(b) i = a; i<=b ; ++i )
#define rfor(i,a,b) for( __typeof(b) i = a; i>=b ; --i )
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define count_one(a)    __builtin_popcountll(a)
#define isPower_2(a)      (a)&(a-1)==0
#define sz(a)           (int)(a.size())
#define all(c)          (c).begin(),(c).end()
#define allr(c)         (c).rbegin(),(c).rend()
#define loop(c,i)       for(__typeof(c.begin()) i = c.begin(); i != c.end(); i++)
#define loopr(c,i)      for(__typeof(c.rbegin()) i = c.rbegin(); i != c.rend(); i++)
#define UNIQUE(a)       sort(all(a)), (a).erase(unique(all(a)),(a).end())
#define present(c,x)    ((c).find(x) != (c).end())
#define cpresent(c,x)   (find(all(c),x) != (c).end())

const int inf = 111111111;

typedef long long LL;
typedef vector<int> vi;
typedef vector<pair<int,int> >vpii;
typedef vector <LL> vll;
typedef vector <pair<LL,LL> > vpll;
typedef pair <int,int> pii;
typedef pair <LL,LL> pll;

void io()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(15);
}

//Fast Reader
// template<class T>inline bool read(T &x){int c=getchar_unlocked();int sgn=1;while(~c&&c<'0'||c>'9'){if(c=='-')sgn=-1;c=getchar_unlocked();}for(x=0;~c&&'0'<=c&&c<='9';c=getchar_unlocked())x=x*10+c-'0'; x*=sgn; return ~c;}

LL mulmod(LL a,LL b, LL m){LL q=(LL)(((long double)a*(long double)b)/(long double)m);LL r=a*b-q*m;if(r>m)r%=m;if(r<0)r+=m;return r;}/* for TOO LARGE mod of the order 10^18 etc */

template<typename T>T mod(T a,T b){while(a < 0)a+=b ;return a%b ;}
template <typename T>T power(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mod(x*p, m);p=mod(p*p, m);n>>=1;}return x;}
template <typename T>T power(T e,T n){T x=1,p=e;while(n){if(n&1)x=x*p;p=p*p;n>>=1;}return x;}
template <typename T> T InverseEuler(T a, T m){return (a==1? 1 : power(a, m-2, m));}/*use IFF m is a prime number */
template <typename T> T gcd(T a, T b){return __gcd(a,b);}
template <typename T> T lcm(T a, T b){return (a*(b/gcd(a,b)));}

int exEuclid(int a,int b,int &x,int &y)
{
    if(a == 0)
    {
        x = 0 ;
        y = 1 ;
        return b ;
    }
    if(b == 0)
    {
        x = 1 ;
        y = 0 ;
        return a ;
    }
    int x1,y1 ;
    int g = exEuclid(b%a , a , x1,y1) ;
    x = y1 - (b/a)*x1 ;
    y = x1 ;
    return g ; // return gcd of a,b ;
}

// #define MAX 50005
// #define mod 1000000009
// bool sv[MAX] ;
// //vector<LL> primes ;
// void sieve()
// {
//     sv[1] = 1 ;
//     sv[2] = 0 ;
//     for(LL i=3;i<MAX;i+=2)
//     {
//         if(sv[i] == 0)
//         {
//             for(LL j=i*i;j<MAX;j += 2*i)
//             {
//                 if(sv[j] == 0)
//                  sv[j] = 1 ;
//             }
//         }
//     }
//     primes.pb(2) ;
//     for(LL i=3;i<MAX;i+=2)
//     {
//         if(sv[i] == 0)
//             primes.pb(i) ;
//     }
// }
#define MAX 123458
vi g[MAX] ;
vi t[MAX] ;
bool vis[MAX] ;
bool mark[MAX] ;
int dis[MAX] ;
bool dfs_build(int u)
{
    vis[u] = 1 ;
    bool res = mark[u] , f ;
    loop(g[u] , it)
    {
        if(vis[*it] == 0)
        {
            f = dfs_build(*it) ;
            if(f)
                t[u].pb(*it) , t[*it].pb(u) ;
            res |= f ;
        }
    }
    return res ;
}
void dfs_dis(int u,int d = 0)
{
    vis[u] = 1 ;
    dis[u] = d ;
    // cout << "@ " << u << endl ;
    loop(t[u] , it)
    {
        if(!vis[*it])
        {
            dfs_dis(*it , d + 1) ;
        }
    }
}
int main(int argc,char* argv[])
{
    io() ;
    #ifndef ONLINE_JUDGE
        freopen("inp.txt", "r", stdin) ;
        // freopen("out.txt", "w", stdout);
    #endif
    int  u , v , n , m ;
    cin >> n >> m ;
    ffor(i,1,n-1)
    {
        cin >> u >> v ;
        g[u].pb(v) ;
        g[v].pb(u) ;
    }
    int a ;
    ffor(i,1,m)
    {
        cin >> a ;
        mark[a] = 1 ;
    }
    int root = 1 ;
    while(!mark[root])
        root++ ;
    assert(mark[root]) ;
    dfs_build(root) ;
    v = MAX ;
    memset(vis, 0 ,sizeof(vis)) ;

    dfs_dis(root) ;
    int mx_d = -1 ;
    int nxt_root = 0 ;
    // return 0 ;
    // cout << "sz = " << t[7].size() << endl ;
    ffor(i,1,n)
    {
        if(dis[i] > mx_d)
        {
            mx_d = dis[i] ;
            nxt_root = i ;
        }
    }
    // cout << "## nxt_root = " << nxt_root << endl ;
    memset(vis, 0 ,sizeof(vis)) ;
    memset(dis, 0 ,sizeof(dis)) ;
    dfs_dis(nxt_root) ;
    int vv = root ;
    mx_d = dis[root] ;
    ffor(i,1,n)
    {
        if(dis[i] > mx_d)
        {
            mx_d = dis[i] ;
            vv = i ;
        }
    }
    // cout << "$$ " << vv << endl ;
    assert(mark[vv]) ;
    v = min(v , vv) ;
    cout << v << endl ;
    int e = 0 ;
    ffor(i,1,n)
    {
        // cout << "$$ i = " << i << " , sz = " << sz(t[i]) << endl;
        e += sz(t[i]) ;
    }
    cout << (e - mx_d) << endl; // 2e - mx_d
    return 0 ;
}


/* AKSHIT CHOPRA , BITS Pilani*/
#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define spc ' '
#define pi 2*acos(0.0)
#define sqr(a) (((a) * (a)))
#define mpr make_pair
#define fi first
#define sc second
#define pb push_back
#define ffor(i,a,b) for( __typeof(b) i = a; i<=b ; ++i )
#define rfor(i,a,b) for( __typeof(b) i = a; i>=b ; --i )
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define count_one(a)    __builtin_popcountll(a)
#define isPower_2(a)      (a)&(a-1)==0
#define sz(a)           (int)(a.size())
#define all(c)          (c).begin(),(c).end()
#define allr(c)         (c).rbegin(),(c).rend()
#define loop(c,i)       for(__typeof(c.begin()) i = c.begin(); i != c.end(); i++)
#define loopr(c,i)      for(__typeof(c.rbegin()) i = c.rbegin(); i != c.rend(); i++)
#define UNIQUE(a)       sort(all(a)), (a).erase(unique(all(a)),(a).end())
#define present(c,x)    ((c).find(x) != (c).end())
#define cpresent(c,x)   (find(all(c),x) != (c).end())

const int inf = 111111111;

typedef long long LL;
typedef vector<int> vi;
typedef vector<pair<int,int> >vpii;
typedef vector <LL> vll;
typedef vector <pair<LL,LL> > vpll;
typedef pair <int,int> pii;
typedef pair <LL,LL> pll;

void io()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(15);
}

//Fast Reader
// template<class T>inline bool read(T &x){int c=getchar_unlocked();int sgn=1;while(~c&&c<'0'||c>'9'){if(c=='-')sgn=-1;c=getchar_unlocked();}for(x=0;~c&&'0'<=c&&c<='9';c=getchar_unlocked())x=x*10+c-'0'; x*=sgn; return ~c;}

LL mulmod(LL a,LL b, LL m){LL q=(LL)(((long double)a*(long double)b)/(long double)m);LL r=a*b-q*m;if(r>m)r%=m;if(r<0)r+=m;return r;}/* for TOO LARGE mod of the order 10^18 etc */

template<typename T>T mod(T a,T b){while(a < 0)a+=b ;return a%b ;}
template <typename T>T power(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mod(x*p, m);p=mod(p*p, m);n>>=1;}return x;}
template <typename T>T power(T e,T n){T x=1,p=e;while(n){if(n&1)x=x*p;p=p*p;n>>=1;}return x;}
template <typename T> T InverseEuler(T a, T m){return (a==1? 1 : power(a, m-2, m));}/*use IFF m is a prime number */
template <typename T> T gcd(T a, T b){return __gcd(a,b);}
template <typename T> T lcm(T a, T b){return (a*(b/gcd(a,b)));}

int exEuclid(int a,int b,int &x,int &y)
{
    if(a == 0)
    {
        x = 0 ;
        y = 1 ;
        return b ;
    }
    if(b == 0)
    {
        x = 1 ;
        y = 0 ;
        return a ;
    }
    int x1,y1 ;
    int g = exEuclid(b%a , a , x1,y1) ;
    x = y1 - (b/a)*x1 ;
    y = x1 ;
    return g ; // return gcd of a,b ;
}

// #define MAX 50005
// #define mod 1000000009
// bool sv[MAX] ;
// //vector<LL> primes ;
// void sieve()
// {
//     sv[1] = 1 ;
//     sv[2] = 0 ;
//     for(LL i=3;i<MAX;i+=2)
//     {
//         if(sv[i] == 0)
//         {
//             for(LL j=i*i;j<MAX;j += 2*i)
//             {
//                 if(sv[j] == 0)
//                  sv[j] = 1 ;
//             }
//         }
//     }
//     primes.pb(2) ;
//     for(LL i=3;i<MAX;i+=2)
//     {
//         if(sv[i] == 0)
//             primes.pb(i) ;
//     }
// }
#define MAX 123458
vi g[MAX] ;
vi t[MAX] ;
bool vis[MAX] ;
bool mark[MAX] ;
int dis[MAX] ;
bool dfs_build(int u)
{
    vis[u] = 1 ;
    bool res = mark[u] , f ;
    loop(g[u] , it)
    {
        if(vis[*it] == 0)
        {
            f = dfs_build(*it) ;
            if(f)
                t[u].pb(*it) , t[*it].pb(u) ;
            res |= f ;
        }
    }
    return res ;
}
void dfs_dis(int u,int d = 0)
{
    vis[u] = 1 ;
    dis[u] = d ;
    // cout << "@ " << u << endl ;
    loop(t[u] , it)
    {
        if(!vis[*it])
        {
            dfs_dis(*it , d + 1) ;
        }
    }
}
int main(int argc,char* argv[])
{
    io() ;
    #ifndef ONLINE_JUDGE
        freopen("inp.txt", "r", stdin) ;
        // freopen("out.txt", "w", stdout);
    #endif
    int  u , v , n , m ;
    cin >> n >> m ;
    ffor(i,1,n-1)
    {
        cin >> u >> v ;
        g[u].pb(v) ;
        g[v].pb(u) ;
    }
    int a ;
    ffor(i,1,m)
    {
        cin >> a ;
        mark[a] = 1 ;
    }
    int root = 1 ;
    while(!mark[root])
        root++ ;
    assert(mark[root]) ;
    dfs_build(root) ;
    v = MAX ;
    memset(vis, 0 ,sizeof(vis)) ;
    //cerr << root << endl ;
    dfs_dis(root) ;
    int mx_d = -1 ;
    int nxt_root = 0 ;
    // cout << "sz = " << t[7].size() << endl ;
    ffor(i,1,n)
    {
        if(mark[i] and dis[i] > mx_d)
        {
            mx_d = dis[i] ;
            nxt_root = i ;
        }
    }
    // cout << "## nxt_root = " << nxt_root << endl ;
    memset(vis, 0 ,sizeof(vis)) ;
    memset(dis, 0 ,sizeof(dis)) ;
    dfs_dis(nxt_root) ;
    v = nxt_root ;
    int vv = MAX ;
    mx_d = -1 ;
    ffor(i,1,n)
    {
        if(mark[i] and dis[i] > mx_d)
        {
            mx_d = dis[i] ;
            vv = i ;
        }
    }
    // cout << "$$ " << vv << endl ;
    assert(mark[vv]) ;
    v = min(v , vv) ;
    cout << v << endl ;
    int e = 0 ;
    ffor(i,1,n)
    {
        // cout << "$$ i = " << i << " , sz = " << sz(t[i]) << endl;
        e += sz(t[i]) ;
    }
    cout << (e - mx_d) << endl; // 2e - mx_d
    return 0 ;
}


/* AKSHIT CHOPRA , BITS Pilani*/
#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define spc ' '
#define pi 2*acos(0.0)
#define sqr(a) (((a) * (a)))
#define mpr make_pair
#define fi first
#define sc second
#define pb push_back
#define ffor(i,a,b) for( __typeof(b) i = a; i<=b ; ++i )
#define rfor(i,a,b) for( __typeof(b) i = a; i>=b ; --i )
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define count_one(a)    __builtin_popcountll(a)
#define isPower_2(a)      (a)&(a-1)==0
#define sz(a)           (int)(a.size())
#define all(c)          (c).begin(),(c).end()
#define allr(c)         (c).rbegin(),(c).rend()
#define loop(c,i)       for(__typeof(c.begin()) i = c.begin(); i != c.end(); i++)
#define loopr(c,i)      for(__typeof(c.rbegin()) i = c.rbegin(); i != c.rend(); i++)
#define UNIQUE(a)       sort(all(a)), (a).erase(unique(all(a)),(a).end())
#define present(c,x)    ((c).find(x) != (c).end())
#define cpresent(c,x)   (find(all(c),x) != (c).end())

const int inf = 111111111;

typedef long long LL;
typedef vector<int> vi;
typedef vector<pair<int,int> >vpii;
typedef vector <LL> vll;
typedef vector <pair<LL,LL> > vpll;
typedef pair <int,int> pii;
typedef pair <LL,LL> pll;

void io()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(15);
}

//Fast Reader
// template<class T>inline bool read(T &x){int c=getchar_unlocked();int sgn=1;while(~c&&c<'0'||c>'9'){if(c=='-')sgn=-1;c=getchar_unlocked();}for(x=0;~c&&'0'<=c&&c<='9';c=getchar_unlocked())x=x*10+c-'0'; x*=sgn; return ~c;}

LL mulmod(LL a,LL b, LL m){LL q=(LL)(((long double)a*(long double)b)/(long double)m);LL r=a*b-q*m;if(r>m)r%=m;if(r<0)r+=m;return r;}/* for TOO LARGE mod of the order 10^18 etc */

template<typename T>T mod(T a,T b){while(a < 0)a+=b ;return a%b ;}
template <typename T>T power(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mod(x*p, m);p=mod(p*p, m);n>>=1;}return x;}
template <typename T>T power(T e,T n){T x=1,p=e;while(n){if(n&1)x=x*p;p=p*p;n>>=1;}return x;}
template <typename T> T InverseEuler(T a, T m){return (a==1? 1 : power(a, m-2, m));}/*use IFF m is a prime number */
template <typename T> T gcd(T a, T b){return __gcd(a,b);}
template <typename T> T lcm(T a, T b){return (a*(b/gcd(a,b)));}

int exEuclid(int a,int b,int &x,int &y)
{
    if(a == 0)
    {
        x = 0 ;
        y = 1 ;
        return b ;
    }
    if(b == 0)
    {
        x = 1 ;
        y = 0 ;
        return a ;
    }
    int x1,y1 ;
    int g = exEuclid(b%a , a , x1,y1) ;
    x = y1 - (b/a)*x1 ;
    y = x1 ;
    return g ; // return gcd of a,b ;
}

// #define MAX 50005
// #define mod 1000000009
// bool sv[MAX] ;
// //vector<LL> primes ;
// void sieve()
// {
//     sv[1] = 1 ;
//     sv[2] = 0 ;
//     for(LL i=3;i<MAX;i+=2)
//     {
//         if(sv[i] == 0)
//         {
//             for(LL j=i*i;j<MAX;j += 2*i)
//             {
//                 if(sv[j] == 0)
//                  sv[j] = 1 ;
//             }
//         }
//     }
//     primes.pb(2) ;
//     for(LL i=3;i<MAX;i+=2)
//     {
//         if(sv[i] == 0)
//             primes.pb(i) ;
//     }
// }
#define MAX 123458
vi g[MAX] ;
vi t[MAX] ;
bool vis[MAX] ;
bool mark[MAX] ;
int dis[MAX] ;
bool dfs_build(int u)
{
    vis[u] = 1 ;
    bool res = mark[u] , f ;
    loop(g[u] , it)
    {
        if(vis[*it] == 0)
        {
            f = dfs_build(*it) ;
            if(f)
                t[u].pb(*it) , t[*it].pb(u) ;
            res |= f ;
        }
    }
    return res ;
}
void dfs_dis(int u,int d = 0)
{
    vis[u] = 1 ;
    dis[u] = d ;
    // cout << "@ " << u << endl ;
    loop(t[u] , it)
    {
        if(!vis[*it])
        {
            dfs_dis(*it , d + 1) ;
        }
    }
}
int main(int argc,char* argv[])
{
    io() ;
    #ifndef ONLINE_JUDGE
        freopen("inp.txt", "r", stdin) ;
        // freopen("out.txt", "w", stdout);
    #endif
    int  u , v , n , m ;
    cin >> n >> m ;
    ffor(i,1,n-1)
    {
        cin >> u >> v ;
        g[u].pb(v) ;
        g[v].pb(u) ;
    }
    int a ;
    ffor(i,1,m)
    {
        cin >> a ;
        mark[a] = 1 ;
    }
    int root = 1 ;
    while(!mark[root])
        root++ ;
    assert(mark[root]) ;
    dfs_build(root) ;
    v = MAX ;
    memset(vis , 0 , sizeof(vis)) ;
    dfs_dis(root) ;
    int mx_d = -1 ;
    int nxt_root = 0 ;
    // return 0 ;
    // cout << "sz = " << t[7].size() << endl ;
    ffor(i,1,n)
    {
        if(dis[i] > mx_d)
        {
            mx_d = dis[i] ;
            nxt_root = i ;
        }
    }
    // cout << "## nxt_root = " << nxt_root << endl ;
    memset(vis, 0 ,sizeof(vis)) ;
    dfs_dis(nxt_root) ;
    int vv = MAX ;
    mx_d = -1 ;
    ffor(i,1,n)
    {

        if(dis[i] > mx_d)
        {
            mx_d = dis[i] ;
            vv = i ;
        }
    }
    // cout << "$$ " << vv << endl ;
    assert(mark[vv]) ;
    v = min(v , vv) ;
    cout << v << endl ;
    int e = 0 ;
    ffor(i,1,n)
    {
        // cout << "$$ i = " << i << " , sz = " << sz(t[i]) << endl;
        e += sz(t[i]) ;
    }
    cout << (e - mx_d) << endl;
    return 0 ;
}


/* AKSHIT CHOPRA , BITS Pilani*/
#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define spc ' '
#define pi 2*acos(0.0)
#define sqr(a) (((a) * (a)))
#define mpr make_pair
#define fi first
#define sc second
#define pb push_back
#define ffor(i,a,b) for( __typeof(b) i = a; i<=b ; ++i )
#define rfor(i,a,b) for( __typeof(b) i = a; i>=b ; --i )
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define count_one(a)    __builtin_popcountll(a)
#define isPower_2(a)      (a)&(a-1)==0
#define sz(a)           (int)(a.size())
#define all(c)          (c).begin(),(c).end()
#define allr(c)         (c).rbegin(),(c).rend()
#define loop(c,i)       for(__typeof(c.begin()) i = c.begin(); i != c.end(); i++)
#define loopr(c,i)      for(__typeof(c.rbegin()) i = c.rbegin(); i != c.rend(); i++)
#define UNIQUE(a)       sort(all(a)), (a).erase(unique(all(a)),(a).end())
#define present(c,x)    ((c).find(x) != (c).end())
#define cpresent(c,x)   (find(all(c),x) != (c).end())

const int inf = 111111111;

typedef long long LL;
typedef vector<int> vi;
typedef vector<pair<int,int> >vpii;
typedef vector <LL> vll;
typedef vector <pair<LL,LL> > vpll;
typedef pair <int,int> pii;
typedef pair <LL,LL> pll;

void io()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(15);
}

//Fast Reader
// template<class T>inline bool read(T &x){int c=getchar_unlocked();int sgn=1;while(~c&&c<'0'||c>'9'){if(c=='-')sgn=-1;c=getchar_unlocked();}for(x=0;~c&&'0'<=c&&c<='9';c=getchar_unlocked())x=x*10+c-'0'; x*=sgn; return ~c;}

LL mulmod(LL a,LL b, LL m){LL q=(LL)(((long double)a*(long double)b)/(long double)m);LL r=a*b-q*m;if(r>m)r%=m;if(r<0)r+=m;return r;}/* for TOO LARGE mod of the order 10^18 etc */

template<typename T>T mod(T a,T b){while(a < 0)a+=b ;return a%b ;}
template <typename T>T power(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mod(x*p, m);p=mod(p*p, m);n>>=1;}return x;}
template <typename T>T power(T e,T n){T x=1,p=e;while(n){if(n&1)x=x*p;p=p*p;n>>=1;}return x;}
template <typename T> T InverseEuler(T a, T m){return (a==1? 1 : power(a, m-2, m));}/*use IFF m is a prime number */
template <typename T> T gcd(T a, T b){return __gcd(a,b);}
template <typename T> T lcm(T a, T b){return (a*(b/gcd(a,b)));}

int exEuclid(int a,int b,int &x,int &y)
{
    if(a == 0)
    {
        x = 0 ;
        y = 1 ;
        return b ;
    }
    if(b == 0)
    {
        x = 1 ;
        y = 0 ;
        return a ;
    }
    int x1,y1 ;
    int g = exEuclid(b%a , a , x1,y1) ;
    x = y1 - (b/a)*x1 ;
    y = x1 ;
    return g ; // return gcd of a,b ;
}

// #define MAX 50005
// #define mod 1000000009
// bool sv[MAX] ;
// //vector<LL> primes ;
// void sieve()
// {
//     sv[1] = 1 ;
//     sv[2] = 0 ;
//     for(LL i=3;i<MAX;i+=2)
//     {
//         if(sv[i] == 0)
//         {
//             for(LL j=i*i;j<MAX;j += 2*i)
//             {
//                 if(sv[j] == 0)
//                  sv[j] = 1 ;
//             }
//         }
//     }
//     primes.pb(2) ;
//     for(LL i=3;i<MAX;i+=2)
//     {
//         if(sv[i] == 0)
//             primes.pb(i) ;
//     }
// }
#define MAX 123458
vi g[MAX] ;
vi t[MAX] ;
bool vis[MAX] ;
bool mark[MAX] ;
int dis[MAX] ;
bool dfs_build(int u)
{
    vis[u] = 1 ;
    bool res = mark[u] , f ;
    loop(g[u] , it)
    {
        if(vis[*it] == 0)
        {
            f = dfs_build(*it) ;
            if(f)
                t[u].pb(*it) , t[*it].pb(u) ;
            res |= f ;
        }
    }
    return res ;
}
void dfs_dis(int u,int d = 0)
{
    vis[u] = 1 ;
    dis[u] = d ;
    // cout << "@ " << u << endl ;
    loop(t[u] , it)
    {
        if(!vis[*it])
        {
            dfs_dis(*it , d + 1) ;
        }
    }
}
int main(int argc,char* argv[])
{
    io() ;
    #ifndef ONLINE_JUDGE
        freopen("inp.txt", "r", stdin) ;
        // freopen("out.txt", "w", stdout);
    #endif
    int  u , v , n , m ;
    cin >> n >> m ;
    ffor(i,1,n-1)
    {
        cin >> u >> v ;
        g[u].pb(v) ;
        g[v].pb(u) ;
    }
    int a ;
    ffor(i,1,m)
    {
        cin >> a ;
        mark[a] = 1 ;
    }
    int root = 1 ;
    while(!mark[root])
        root++ ;
    assert(mark[root]) ;
    dfs_build(root) ;
    v = MAX ;
    memset(vis, 0 ,sizeof(vis)) ;

    dfs_dis(root) ;
    int mx_d = -1 ;
    int nxt_root = 0 ;
    // return 0 ;
    // cout << "sz = " << t[7].size() << endl ;
    ffor(i,1,n)
    {
        if(dis[i] > mx_d)
        {
            mx_d = dis[i] ;
            nxt_root = i ;
        }
    }
    // cout << "## nxt_root = " << nxt_root << endl ;
    memset(vis, 0 ,sizeof(vis)) ;
    memset(dis, 0 ,sizeof(dis)) ;
    dfs_dis(nxt_root) ;
    int vv = MAX ;
    mx_d = -1 ;
    ffor(i,1,n)
    {
        if(dis[i] > mx_d)
        {
            mx_d = dis[i] ;
            vv = i ;
        }
    }
    // cout << "$$ " << vv << endl ;
    assert(mark[vv]) ;
    v = min(v , vv) ;
    cout << v << endl ;
    int e = 0 ;
    ffor(i,1,n)
    {
        // cout << "$$ i = " << i << " , sz = " << sz(t[i]) << endl;
        e += sz(t[i]) ;
    }
    cout << (e - mx_d) << endl; // 2e - mx_d
    return 0 ;
}


#include<iostream>
#include<stdio.h>
#include<vector>
#include<cstring>
using namespace std;
#define maxn 123459
vector<int>Q[maxn];
int vis[maxn];
int vis2[maxn];
int ans1,ans2,len;
void dfs(int x,int dis,int pre)
{
    if(dis>len&&vis[x])
    {
        len = dis;
        ans2 = x;
    }
    if(dis==len&&vis[x]&&x<ans2)
        ans2 = x;
    for(int i=0;i<Q[x].size();i++)
    {
        if(Q[x][i]==pre)
            continue;
        dfs(Q[x][i],dis+1,x);
    }
}
int ppp = 0;
int dfs2(int x,int pre)
{
    if(vis[x])vis2[x]++;
    for(int i=0;i<Q[x].size();i++)
    {
        if(Q[x][i]==pre)
            continue;
        vis2[x]+=dfs2(Q[x][i],x);
    }
    return vis2[x];
}
void dfs3(int x,int pre)
{
    if(vis2[x])
        ppp++;
    for(int i=0;i<Q[x].size();i++)
    {
        if(Q[x][i]==pre)
            continue;
        dfs3(Q[x][i],x);
    }
}
int main()
{
    int n,m;scanf("%d%d",&n,&m);
    for(int i=1;i<n;i++)
    {
        int x,y;scanf("%d%d",&x,&y);
        Q[x].push_back(y);
        Q[y].push_back(x);
    }
    ans1 = 99999999;
    for(int i=1;i<=m;i++)
    {
        int x;scanf("%d",&x);
        vis[x]=1;
        ans1 = min(x,ans1);
    }
    if(m==1)
    {
        printf("%d\n0\n",ans1);
        return 0;
    }
    len = -1;
    dfs(ans1,0,-1);
    //printf("len = %d\n",len);
    ans1 = ans2;
    len = -1;
    //dfs(ans1,0,-1);
    //printf("len = %d\n",len);
    dfs2(ans2,-1);
    dfs3(ans2,-1);
    printf("%d\n",min(ans1,ans2));
    if(ppp!=1)ppp--;
    printf("%d\n",ppp*2 - len);
}


#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pb push_back
#define cl(a,b) memset(a,b,sizeof(a))
const int maxn=123456+100;
const int inf=1<<23;
vector<int> mp[maxn];
int vis[maxn];
int vis2[maxn];
int ans1,ans2,depth,sum;
void dfs(int x,int pre,int dep){
    if(vis[x]&&dep>depth){
        depth=dep;
        ans2=x;
    }
    if(vis[x]&&depth==dep&&x<ans2){
        ans2=x;
    }
    for(int i=0;i<mp[x].size();i++){
        if(pre==mp[x][i])continue;
        dfs(mp[x][i],x,dep+1);
    }
}
int dfs2(int x,int pre){
    if(vis[x])vis2[x]++;
    for(int i=0;i<mp[x].size();i++){
        if(pre==mp[x][i])continue;
        vis2[x]+=dfs2(mp[x][i],x);
    }
    return vis2[x];
}
void dfs3(int x,int pre){
    if(vis2[x])sum++;
    for(int i=0;i<mp[x].size();i++){
        if(pre==mp[x][i])continue;
        dfs3(mp[x][i],x);
    }
}
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<n;i++){
        int u,v;
        scanf("%d%d",&u,&v);
        mp[u].pb(v);
        mp[v].pb(u);
    }
    ans1=inf;
    for(int i=0;i<m;i++){
        int x;scanf("%d",&x);
        ans1=min(ans1,x);
        vis[x]=true;
    }
    if(m==1){
        printf("%d\n0\n",ans1);return 0;
    }
    depth=-1;
    dfs(1,-1,0);
    ans1=ans2;
    depth=-1;
    dfs(ans2,-1,0);
    sum=0;
    dfs2(ans1,-1);
    dfs3(ans1,-1);
    if(sum!=1)sum--;
    printf("%d\n%d\n",min(ans1,ans2),sum*2-depth);

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pb push_back
#define cl(a,b) memset(a,b,sizeof(a))
const int maxn=123456+100;
const int inf=1<<23;
vector<int> mp[maxn];
int vis[maxn];
int vis2[maxn];
int ans1,ans2,depth,sum;
void dfs(int x,int pre,int dep){
    if(vis[x]&&dep>depth){
        depth=dep;
        ans2=x;
    }
    if(vis[x]&&depth==dep&&x<ans2){
        ans2=x;
    }
    for(int i=0;i<mp[x].size();i++){
        if(pre==mp[x][i])continue;
        dfs(mp[x][i],x,dep+1);
    }
}
int dfs2(int x,int pre){
    if(vis[x])vis2[x]++;
    for(int i=0;i<mp[x].size();i++){
        if(pre==mp[x][i])continue;
        vis2[x]+=dfs2(mp[x][i],x);
    }
    return vis2[x];
}
void dfs3(int x,int pre){
    if(vis2[x])sum++;
    for(int i=0;i<mp[x].size();i++){
        if(pre==mp[x][i])continue;
        dfs3(mp[x][i],x);
    }
}
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<n;i++){
        int u,v;
        scanf("%d%d",&u,&v);
        mp[u].pb(v);
        mp[v].pb(u);
    }
    ans1=inf;
    for(int i=0;i<m;i++){
        int x;scanf("%d",&x);
        ans1=min(ans1,x);
        vis[x]=true;
    }
    if(m==1){
        printf("%d\n0\n",ans1);return 0;
    }
    depth=-1;
    dfs(1,-1,0);
    ans1=ans2;
    depth=-1;
    dfs(ans2,-1,0);
    sum=0;
    dfs2(ans1,-1);
    dfs3(ans1,-1);
    //if(sum!=1)
    sum--;
    printf("%d\n%d\n",min(ans1,ans2),sum*2-depth);

    return 0;
}


#include<iostream>
#include<stdio.h>
#include<vector>
#include<cstring>
using namespace std;
#define maxn 123459
vector<int>Q[maxn];
int vis[maxn];
int vis2[maxn];
int ans1,ans2,len;
void dfs(int x,int dis,int pre)
{
    if(dis>len&&vis[x])
    {
        len = dis;
        ans2 = x;
    }
    if(dis==len&&vis[x]&&x<ans2)
        ans2 = x;
    for(int i=0;i<Q[x].size();i++)
    {
        if(Q[x][i]==pre)
            continue;
        dfs(Q[x][i],dis+1,x);
    }
}
int ppp = 0;
int dfs2(int x,int pre)
{
    if(vis[x])vis2[x]++;
    for(int i=0;i<Q[x].size();i++)
    {
        if(Q[x][i]==pre)
            continue;
        vis2[x]+=dfs2(Q[x][i],x);
    }
    return vis2[x];
}
void dfs3(int x,int pre)
{
    if(vis2[x])
        ppp++;
    for(int i=0;i<Q[x].size();i++)
    {
        if(Q[x][i]==pre)
            continue;
        dfs3(Q[x][i],x);
    }
}
int main()
{
    int n,m;scanf("%d%d",&n,&m);
    for(int i=1;i<n;i++)
    {
        int x,y;scanf("%d%d",&x,&y);
        Q[x].push_back(y);
        Q[y].push_back(x);
    }
    ans1 = 99999999;
    for(int i=1;i<=m;i++)
    {
        int x;scanf("%d",&x);
        vis[x]=1;
        ans1 = min(x,ans1);
    }
    if(m==1)
    {
        printf("%d\n0\n",ans1);
        return 0;
    }
    len = -1;
    dfs(ans1,0,-1);
    ans1 = ans2;
    len = -1;
    dfs(ans1,0,-1);
    dfs2(ans2,-1);
    dfs3(ans2,-1);
    printf("%d\n",min(ans1,ans2));
    if(ppp!=1)ppp--;
    printf("%d\n",ppp*2 - len);
}


#include<iostream>
#include<stdio.h>
#include<vector>
#include<cstring>
using namespace std;
#define maxn 123459
vector<int>Q[maxn];
int vis[maxn];
int vis2[maxn];
int ans1,ans2,len;
void dfs(int x,int dis,int pre)
{
    if(dis>len&&vis[x])
    {
        len = dis;
        ans2 = x;
    }
    if(dis==len&&vis[x]&&x<ans2)
        ans2 = x;
    for(int i=0;i<Q[x].size();i++)
    {
        if(Q[x][i]==pre)
            continue;
        dfs(Q[x][i],dis+1,x);
    }
}
int ppp = 0;
int dfs2(int x,int pre)
{
    if(vis[x])vis2[x]++;
    for(int i=0;i<Q[x].size();i++)
    {
        if(Q[x][i]==pre)
            continue;
        vis2[x]+=dfs2(Q[x][i],x);
    }
    return vis2[x];
}
void dfs3(int x,int pre)
{
    if(vis2[x])
        ppp++;
    for(int i=0;i<Q[x].size();i++)
    {
        if(Q[x][i]==pre)
            continue;
        dfs3(Q[x][i],x);
    }
}
int main()
{
    int n,m;scanf("%d%d",&n,&m);
    for(int i=1;i<n;i++)
    {
        int x,y;scanf("%d%d",&x,&y);
        Q[x].push_back(y);
        Q[y].push_back(x);
    }
    ans1 = 99999999;
    for(int i=1;i<=m;i++)
    {
        int x;scanf("%d",&x);
        vis[x]=1;
        ans1 = min(x,ans1);
    }
    if(m==1)
    {
        printf("%d\n0\n",ans1);
        return 0;
    }
    len = -1;
    dfs(ans1,0,-1);
    //printf("ans2 = %d\n",ans2);
    ans1 = ans2;
    len = -1;
    dfs(ans1,0,-1);

    dfs2(ans1,-1);
    dfs3(ans1,-1);
    printf("%d\n",min(ans1,ans2));
    if(ppp!=1)ppp--;
    printf("%d\n",ppp*2 - len);
}


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

using namespace std;

struct punkt
{
	int x, y;
};
punkt p;
vector<punkt> s;
vector<int> tab[200001];

int mlen, ver, x, y, n, m, i, ans, inf = 100000000, start;
int parent[200001], ile[200001], stos[200001];
bool met[200001], out[200001], marked[200001], blad;
bool cmp( punkt x, punkt y )
{
	if( x.x > y.x )return 1;
	else if( x.x == y.x )
	{
		if( x.y < y.y )return 1;
		else return 0;
	}
	else return 0;
}
void dfs( int w )
{
	met[w] = 1;
	for( int a = 0; a < tab[w].size(); a++ )
	{
		if( !met[tab[w][a]] && !out[tab[w][a]] )
		{
			dfs( tab[w][a] );
			parent[ tab[w][a] ] = w;
			ile[w] += ile[tab[w][a]];
		}
	}
	ile[w]++;
	//cout<<w<<" "<<ile[w]<<endl;
}
void dfs2( int w, int gb )
{
	met[w] = 1;
	if( gb > mlen )
	{
		mlen = gb;
		ver = w;
	}
	if( gb == mlen )ver = min( ver, w );
	for( int a = 0; a < tab[w].size(); a++ )
	{
		if( !met[tab[w][a]] && !out[tab[w][a]])dfs2( tab[w][a], gb+1 );
	}
	//mlen++;
}
int main()
{
	ios_base::sync_with_stdio( 0 );
	cin>>n>>m;
	for( int a = 1; a < n; a++ )
	{
		cin>>x>>y;
		tab[x].push_back( y );
		tab[y].push_back( x );
		ile[x]++;
		ile[y]++;
	}
	for( int a = 1; a <= m; a++ )
	{
		cin>>x;
		marked[x] = 1;
	}
	for( int a = 1; a <= n; a++ )if( ile[a] == 1 )stos[++i] = a;
	while( i )
	{
		x = stos[i];
		i--;

		if( !marked[x] )
		{
			out[x] = 1;
			for( int a = 0; a < tab[x].size(); a++ )
			{
				ile[tab[x][a]]--;
				if( ile[tab[x][a]] == 1 )stos[++i] = tab[x][a];
			}
		}
	}
	for( int a = 1; a <= n; a++ )ile[a] = 0;
	//for( int a = 1; a <= n; a++ )cout<<out[a]<<" ";
	//cout<<endl;
	for( int a = 1; a <= n; a++ )if( !out[a] )ans++;
	if( ans == 1 )
	{
		for( int a = 1; a <= n; a++ )if( !out[a] )cout<<a<<endl<<0;
	}
	else if( ans == 2 )
	{
		int pier = 0, drug = 0;
		for( int a = 1; a <= n; a++ )
		{
			if( !out[a] )
			{
				if( pier )drug = a;
				else pier = a;
			}
		}
		cout<<min( pier, drug )<<endl<<1;
	}
	else
	{

	for( int a = 1; a <= n; a++ )
	{
		if( !out[a] )
		{
			start = a;
			break;
		}
	}
	dfs( start );
	for( int a = 1; a <= n; a++ )met[a] = 0;
	for( int a = 1; a <= n; a++ )
	{
		if( !out[a] )
		{
//			cout<<a<<" ><"<<endl;
			blad = 0;
//			cout<<"ok"<<endl;
			for( int b = 0; b < tab[a].size(); b++ )
			{
				if( tab[a][b] != parent[a] )
				{
					if( ile[tab[a][b]]*2 > ans )
					{
//						cout<<a<<" "<<tab[a][b]<<" "<<ile[tab[a][b]]<<endl;
						blad = 1;
						break;
					}
				}
			}

			if( (ans-ile[a])*2 > ans )
			{
//				cout<<a<<" error"<<endl;
				blad = 1;
			}
			if( !blad )
			{
				//cout<<"centroid: "<<a<<endl;
				met[a] = 1;
				for( int b = 0; b < tab[a].size(); b++ )
				{
					mlen = 0;
					ver = inf;
					if( !out[tab[a][b]] )dfs2( tab[a][b], 1 );
					p.x = mlen;
					p.y = ver;
					s.push_back( p );
//					cout<<"add  "<<p.x<<" "<<p.y<<endl;
				}
				break;
			}
		}
	}
//	cout<<"ok"<<endl;
	sort( s.begin(), s.end(), cmp );
	cout<<min( s[0].y, s[1].y )<<endl<<2*ans - ( s[0].x+s[1].x ) - 2;
//	cout<<"ok"<<endl;
	}
	return 0;
}


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

using namespace std;

struct punkt
{
	int x, y;
};
punkt p;
vector<punkt> s;
vector<int> tab[200001];

int mlen, ver, x, y, n, m, i, ans, inf = 100000000, start;
int parent[200001], ile[200001], stos[200001];
bool met[200001], out[200001], marked[200001], blad;

bool cmp( punkt x, punkt y )
{
	if( x.x > y.x )return 1;
	else if( x.x == y.x )
	{
		if( x.y < y.y )return 1;
		else return 0;
	}
	else return 0;
}
void dfs( int w )
{
	met[w] = 1;
	for( int a = 0; a < tab[w].size(); a++ )
	{
		if( !met[tab[w][a]] && !out[tab[w][a]] )
		{
			dfs( tab[w][a] );
			parent[ tab[w][a] ] = w;
			ile[w] += ile[tab[w][a]];
		}
	}
	ile[w]++;
	//cout<<w<<" "<<ile[w]<<endl;
}
void dfs2( int w, int gb )
{
	met[w] = 1;
	if( gb > mlen )
	{
		mlen = gb;
		ver = w;
	}
	if( gb == mlen )ver = min( ver, w );
	for( int a = 0; a < tab[w].size(); a++ )
	{
		if( !met[tab[w][a]] && !out[tab[w][a]])dfs2( tab[w][a], gb+1 );
	}
	//mlen++;
}
int main()
{
	ios_base::sync_with_stdio( 0 );
	cin>>n>>m;
	for( int a = 1; a < n; a++ )
	{
		cin>>x>>y;
		tab[x].push_back( y );
		tab[y].push_back( x );
		ile[x]++;
		ile[y]++;
	}
	for( int a = 1; a <= m; a++ )
	{
		cin>>x;
		marked[x] = 1;
	}
	for( int a = 1; a <= n; a++ )if( ile[a] == 1 )stos[++i] = a;
	while( i )
	{
		x = stos[i];
		i--;

		if( !marked[x] )
		{
			out[x] = 1;
			for( int a = 0; a < tab[x].size(); a++ )
			{
				ile[tab[x][a]]--;
				if( ile[tab[x][a]] == 1 )stos[++i] = tab[x][a];
			}
		}
	}
	for( int a = 1; a <= n; a++ )ile[a] = 0;
	//for( int a = 1; a <= n; a++ )cout<<out[a]<<" ";
	//cout<<endl;
	for( int a = 1; a <= n; a++ )if( !out[a] )ans++;
	if( ans == 1 )
	{
		for( int a = 1; a <= n; a++ )if( !out[a] )cout<<a<<endl<<0;
	}
	else
	{

	for( int a = 1; a <= n; a++ )
	{
		if( !out[a] )
		{
			start = a;
			break;
		}
	}
	dfs( start );
	for( int a = 1; a <= n; a++ )met[a] = 0;
	for( int a = 1; a <= n; a++ )
	{
		if( !out[a] )
		{
//			cout<<a<<" ><"<<endl;
			blad = 0;
//			cout<<"ok"<<endl;
			for( int b = 0; b < tab[a].size(); b++ )
			{
				if( tab[a][b] != parent[a] )
				{
					if( ile[tab[a][b]]*2 > ans )
					{
//						cout<<a<<" "<<tab[a][b]<<" "<<ile[tab[a][b]]<<endl;
						blad = 1;
						break;
					}
				}
			}

			if( (ans-ile[a])*2 > ans )
			{
//				cout<<a<<" error"<<endl;
				blad = 1;
			}
			if( !blad )
			{
				cout<<"centroid: "<<a<<endl;
				met[a] = 1;
				for( int b = 0; b < tab[a].size(); b++ )
				{
					mlen = 0;
					ver = inf;
					if( !out[tab[a][b]] )dfs2( tab[a][b], 1 );
					p.x = mlen;
					p.y = ver;
					s.push_back( p );
//					cout<<"add  "<<p.x<<" "<<p.y<<endl;
				}
				break;
			}
		}
	}
//	cout<<"ok"<<endl;
	sort( s.begin(), s.end(), cmp );
	cout<<min( s[0].y, s[1].y )<<endl<<2*ans - ( s[0].x+s[1].x ) - 2;
//	cout<<"ok"<<endl;
	}
	return 0;
}


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

using namespace std;

struct punkt
{
	int x, y;
};
punkt p;
vector<punkt> s;
vector<int> tab[200001];

int mlen, ver, x, y, n, m, i, ans, inf = 100000000, start;
int parent[200001], ile[200001], stos[200001];
bool met[200001], out[200001], marked[200001], blad;

bool cmp( punkt x, punkt y )
{
	if( x.x > y.x )return 1;
	else if( x.x == y.x )
	{
		if( x.y < y.y )return 1;
		else return 0;
	}
	else return 0;
}
void dfs( int w )
{
	met[w] = 1;
	for( int a = 0; a < tab[w].size(); a++ )
	{
		if( !met[tab[w][a]] && !out[tab[w][a]] )
		{
			dfs( tab[w][a] );
			parent[ tab[w][a] ] = w;
			ile[w] += ile[tab[w][a]];
		}
	}
	ile[w]++;
	//cout<<w<<" "<<ile[w]<<endl;
}
void dfs2( int w, int gb )
{
	met[w] = 1;
	if( gb > mlen )
	{
		mlen = gb;
		ver = w;
	}
	if( gb == mlen )ver = min( ver, w );
	for( int a = 0; a < tab[w].size(); a++ )
	{
		if( !met[tab[w][a]] && !out[tab[w][a]])dfs2( tab[w][a], gb+1 );
	}
	//mlen++;
}
int main()
{
	ios_base::sync_with_stdio( 0 );
	cin>>n>>m;
	for( int a = 1; a < n; a++ )
	{
		cin>>x>>y;
		tab[x].push_back( y );
		tab[y].push_back( x );
		ile[x]++;
		ile[y]++;
	}
	for( int a = 1; a <= m; a++ )
	{
		cin>>x;
		marked[x] = 1;
	}
	for( int a = 1; a <= n; a++ )if( ile[a] == 1 )stos[++i] = a;
	while( i )
	{
		x = stos[i];
		i--;

		if( !marked[x] )
		{
			out[x] = 1;
			for( int a = 0; a < tab[x].size(); a++ )
			{
				ile[tab[x][a]]--;
				if( ile[tab[x][a]] == 1 )stos[++i] = tab[x][a];
			}
		}
	}
	for( int a = 1; a <= n; a++ )ile[a] = 0;
	//for( int a = 1; a <= n; a++ )cout<<out[a]<<" ";
	//cout<<endl;
	for( int a = 1; a <= n; a++ )if( !out[a] )ans++;
	if( ans == 1 )
	{
		for( int a = 1; a <= n; a++ )if( !out[a] )cout<<a<<endl<<0;
	}
	else
	{

	for( int a = 1; a <= n; a++ )
	{
		if( !out[a] )
		{
			start = a;
			break;
		}
	}
	dfs( start );
	for( int a = 1; a <= n; a++ )met[a] = 0;
	for( int a = 1; a <= n; a++ )
	{
		if( !out[a] )
		{
//			cout<<a<<" ><"<<endl;
			blad = 0;
//			cout<<"ok"<<endl;
			for( int b = 0; b < tab[a].size(); b++ )
			{
				if( tab[a][b] != parent[a] )
				{
					if( ile[tab[a][b]]*2 > ans )
					{
//						cout<<a<<" "<<tab[a][b]<<" "<<ile[tab[a][b]]<<endl;
						blad = 1;
						break;
					}
				}
			}

			if( (ans-ile[a])*2 > ans )
			{
//				cout<<a<<" error"<<endl;
				blad = 1;
			}
			if( !blad )
			{
				//cout<<"centroid: "<<a<<endl;
				met[a] = 1;
				for( int b = 0; b < tab[a].size(); b++ )
				{
					mlen = 0;
					ver = inf;
					if( !out[tab[a][b]] )dfs2( tab[a][b], 1 );
					p.x = mlen;
					p.y = ver;
					s.push_back( p );
//					cout<<"add  "<<p.x<<" "<<p.y<<endl;
				}
				break;
			}
		}
	}
//	cout<<"ok"<<endl;
	sort( s.begin(), s.end(), cmp );
	cout<<min( s[0].y, s[1].y )<<endl<<2*ans - ( s[0].x+s[1].x ) - 2;
//	cout<<"ok"<<endl;
	}
	return 0;
}


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

using namespace std;

struct punkt
{
	int x, y;
};
punkt p;
vector<punkt> s;
vector<int> tab[200001];

int mlen, ver, x, y, n, m, i, ans, inf = 100000000, start;
int parent[200001], ile[200001], stos[200001];
bool met[200001], out[200001], marked[200001], blad;

bool cmp( punkt x, punkt y )
{
	if( x.x > y.x )return 1;
	else if( x.x == y.x )
	{
		if( x.y < y.y )return 1;
		else return 0;
	}
	else return 0;
}
void dfs( int w )
{
	met[w] = 1;
	for( int a = 0; a < tab[w].size(); a++ )
	{
		if( !met[tab[w][a]] && !out[tab[w][a]] )
		{
			dfs( tab[w][a] );
			parent[ tab[w][a] ] = w;
			ile[w] += ile[tab[w][a]];
		}
	}
	ile[w]++;
	//cout<<w<<" "<<ile[w]<<endl;
}
void dfs2( int w, int gb )
{
	met[w] = 1;
	if( gb > mlen )
	{
		mlen = gb;
		ver = w;
	}
	if( gb == mlen )ver = min( ver, w );
	for( int a = 0; a < tab[w].size(); a++ )
	{
		if( !met[tab[w][a]] && !out[tab[w][a]])dfs2( tab[w][a], gb+1 );
	}
	//mlen++;
}
int main()
{
	ios_base::sync_with_stdio( 0 );
	cin>>n>>m;
	for( int a = 1; a < n; a++ )
	{
		cin>>x>>y;
		tab[x].push_back( y );
		tab[y].push_back( x );
		ile[x]++;
		ile[y]++;
	}
	for( int a = 1; a <= m; a++ )
	{
		cin>>x;
		marked[x] = 1;
	}
	for( int a = 1; a <= n; a++ )if( ile[a] == 1 )stos[++i] = a;
	while( i )
	{
		x = stos[i];
		i--;

		if( !marked[x] )
		{
			out[x] = 1;
			for( int a = 0; a < tab[x].size(); a++ )
			{
				ile[tab[x][a]]--;
				if( ile[tab[x][a]] == 1 )stos[++i] = tab[x][a];
			}
		}
	}
	for( int a = 1; a <= n; a++ )ile[a] = 0;
	//for( int a = 1; a <= n; a++ )cout<<out[a]<<" ";
	//cout<<endl;
	for( int a = 1; a <= n; a++ )if( !out[a] )ans++;
	for( int a = 1; a <= n; a++ )
	{
		if( !out[a] )
		{
			start = a;
			break;
		}
	}
	dfs( start );
	for( int a = 1; a <= n; a++ )met[a] = 0;
	for( int a = 1; a <= n; a++ )
	{
		if( !out[a] )
		{
//			cout<<a<<" ><"<<endl;
			blad = 0;
//			cout<<"ok"<<endl;
			for( int b = 0; b < tab[a].size(); b++ )
			{
				if( tab[a][b] != parent[a] )
				{
					if( ile[tab[a][b]]*2 > ans )
					{
//						cout<<a<<" "<<tab[a][b]<<" "<<ile[tab[a][b]]<<endl;
						blad = 1;
						break;
					}
				}
			}

			if( (ans-ile[a])*2 > ans )
			{
//				cout<<a<<" error"<<endl;
				blad = 1;
			}
			if( !blad )
			{
//				cout<<"centroid: "<<a<<endl;
				met[a] = 1;
				for( int b = 0; b < tab[a].size(); b++ )
				{
					mlen = 0;
					ver = inf;
					if( !out[tab[a][b]] )dfs2( tab[a][b], 1 );
					p.x = mlen;
					p.y = ver;
					s.push_back( p );
//					cout<<"add  "<<p.x<<" "<<p.y<<endl;
				}
				break;
			}
		}
	}
//	cout<<"ok"<<endl;
	sort( s.begin(), s.end(), cmp );
	cout<<min( s[0].y, s[1].y )<<endl<<2*ans - ( s[0].x+s[1].x ) - 2;
//	cout<<"ok"<<endl;
	return 0;
}


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

using namespace std;

struct punkt
{
	int x, y;
};
punkt p;
vector<punkt> s;
vector<int> tab[200001];

int mlen, ver, x, y, n, m, i, ans, inf = 100000000, start;
int parent[200001], ile[200001], stos[200001];
bool met[200001], out[200001], marked[200001], blad;

bool cmp( punkt x, punkt y )
{
	if( x.x > y.x )return 1;
	else if( x.x == y.x )
	{
		if( x.y < y.y )return 1;
		else return 0;
	}
	else return 0;
}
void dfs( int w )
{
	met[w] = 1;
	for( int a = 0; a < tab[w].size(); a++ )
	{
		if( !met[tab[w][a]] && !out[tab[w][a]] )
		{
			dfs( tab[w][a] );
			parent[ tab[w][a] ] = w;
			ile[w] += ile[tab[w][a]];
		}
	}
	ile[w]++;
	//cout<<w<<" "<<ile[w]<<endl;
}
void dfs2( int w, int gb )
{
	met[w] = 1;
	if( gb > mlen )
	{
		mlen = gb;
		ver = w;
	}
	if( gb == mlen )ver = min( ver, w );
	for( int a = 0; a < tab[w].size(); a++ )
	{
		if( !met[tab[w][a]] && !out[tab[w][a]])dfs2( tab[w][a], gb+1 );
	}
	//mlen++;
}
int main()
{
	ios_base::sync_with_stdio( 0 );
	cin>>n>>m;
	for( int a = 1; a < n; a++ )
	{
		cin>>x>>y;
		tab[x].push_back( y );
		tab[y].push_back( x );
		ile[x]++;
		ile[y]++;
	}
	for( int a = 1; a <= m; a++ )
	{
		cin>>x;
		marked[x] = 1;
	}
	for( int a = 1; a <= n; a++ )if( ile[a] == 1 )stos[++i] = a;
	while( i )
	{
		x = stos[i];
		i--;

		if( !marked[x] )
		{
			out[x] = 1;
			for( int a = 0; a < tab[x].size(); a++ )
			{
				ile[tab[x][a]]--;
				if( ile[tab[x][a]] == 1 )stos[++i] = tab[x][a];
			}
		}
	}
	for( int a = 1; a <= n; a++ )ile[a] = 0;
	//for( int a = 1; a <= n; a++ )cout<<out[a]<<" ";
	//cout<<endl;
	for( int a = 1; a <= n; a++ )if( !out[a] )ans++;
	for( int a = 1; a <= n; a++ )
	{
		if( !out[a] )
		{
			start = a;
			break;
		}
	}
	dfs( start );
	for( int a = 1; a <= n; a++ )met[a] = 0;
	for( int a = 1; a <= n; a++ )
	{
		if( !out[a] )
		{
			blad = 0;
			for( int b = 0; b <= tab[a].size(); b++ )
			{
				if( tab[a][b] != parent[a] )
				{
					if( ile[tab[a][b]]*2 > ans )blad = 1;
				}
			}
			if( (ans-ile[a])*2 > ans )blad = 1;
			if( !blad )
			{
//				cout<<"centroid: "<<a<<endl;
				met[a] = 1;
				for( int b = 0; b < tab[a].size(); b++ )
				{
					mlen = 0;
					ver = inf;
					if( !out[tab[a][b]] )dfs2( tab[a][b], 1 );
					p.x = mlen;
					p.y = ver;
					s.push_back( p );
//					cout<<"add  "<<p.x<<" "<<p.y<<endl;
				}
				break;
			}
		}
	}
	sort( s.begin(), s.end(), cmp );
	cout<<min( s[0].y, s[1].y )<<endl<<2*ans - ( s[0].x+s[1].x ) - 2;
//	cout<<"ok"<<endl;
	return 0;
}