# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
331685 | BeanZ | Mag (COCI16_mag) | C++14 | 488 ms | 141824 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// I_Love_LPL
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
const int N = 1e6 + 5;
const int mod = 1e9 + 7;
const int lim = 100;
ll dp1[N], dp2[N], a[N];
vector<ll> node[N];
void upd(ll u, ll c){
dp2[u] = max(dp2[u], c);
if (dp2[u] > dp1[u]) swap(dp2[u], dp1[u]);
}
void init(ll u, ll p){
for (auto j : node[u]){
if (j == p) continue;
init(j, u);
if (a[j] == 1) upd(u, dp1[j] + 1);
}
}
void dfs(ll u, ll p){
for (auto j : node[u]){
if (j == p) continue;
if (a[u] == 1){
if ((dp1[j] + 1) == dp1[u]) upd(j, dp2[u]);
else upd(j, dp1[u]);
}
dfs(j, u);
}
}
void red(pair<ll, ll> &u, pair<ll, ll> v){
if (u.first * v.second > u.second * v.first){
u = v;
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
if (fopen("A.inp", "r")){
freopen("test.inp", "r", stdin);
freopen("test.out", "w", stdout);
}
ll n;
cin >> n;
for (int i = 1; i < n; i++){
ll u, v;
cin >> u >> v;
node[u].push_back(v);
node[v].push_back(u);
}
for (int i = 1; i <= n; i++) cin >> a[i];
init(1, 1);
dfs(1, 1);
pair<ll, ll> ans = {1e9, 1};
for (int i = 1; i <= n; i++){
red(ans, {a[i], dp1[i] + dp2[i] + 1});
}
ll gcd = __gcd(ans.first, ans.second);
ans.first /= gcd;
ans.second /= gcd;
cout << ans.first << "/" << ans.second;
}
/*
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |