inlineintread(){ int s = 0, x = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') x = -x; ch = getchar(); } while (isdigit(ch)) { s = s * 10 + ch - '0'; ch = getchar(); } return s * x; }
constint MAXN = 200000 + 10;
std::vector<int> G[MAXN];
int n; int val[MAXN]; longlongint ans, mxans;
intmain(){ n = read(); for (int i = 1; i <= n - 1; ++i) { int u = read(); int v = read(); G[u].push_back(v); G[v].push_back(u); } for (int i = 1; i <= n; ++i) { val[i] = read(); } for (int mid = 1; mid <= n; ++mid) { if (G[mid].size() < 2) continue; longlongint mans = 0, fmans = 0; int maxx = 0, tmax = -1; for (auto v : G[mid]) { mans += val[v]; fmans += 1ll * val[v] * val[v]; if (val[v] > maxx) { tmax = maxx; maxx = val[v]; } elseif (val[v] > tmax) { tmax = val[v]; } } (ans += ((mans * mans - fmans))) %= 10007; mxans = std::max(mxans, 1ll * maxx * tmax); } printf("%lld %lld\n", mxans, ans); return0; }