# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
241472 |
2020-06-24T08:35:17 Z |
Vimmer |
Mag (COCI16_mag) |
C++14 |
|
627 ms |
227436 KB |
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-O3")
#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("no-stack-protector")
#define F first
#define S second
#define sz(x) int(x.size())
#define pb push_back
#define N 1000501
#define M ll(1e9 + 7)
#define inf 1e9 + 1e9
using namespace std;
//using namespace __gnu_pbds;
typedef long double ld;
typedef long long ll;
typedef short int si;
typedef array <int, 3> a3;
//typedef tree <int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ll a[N];
ll f[N];
ld ans = -1;
ll l, r;
vector <ll> g[N];
void dfs(ll v, ll p)
{
if (ans == -1 || ans - ld(a[v]) > 0) {ans = a[v]; l = a[v]; r = 1;}
if (a[v] == 1) f[v] = 1;
for (auto it : g[v])
{
if (it == p) continue;
dfs(it, v);
if (a[v] != 1) continue;
f[v] = max(f[v], 1 + f[it]);
}
}
void rec(ll v, ll p, ll koler)
{
vector <ll> pr; pr.clear();
for (auto it : g[v])
{
if (it == p) continue;
pr.pb(f[it]);
}
sort(pr.begin(), pr.end());
reverse(pr.begin(), pr.end());
if (sz(pr) > 1)
{
ll sum = a[v], kol = pr[0] + pr[1] + 1;
ld val = ld(sum) / ld(kol);
if (ans == -1 || ans - val > 0) {ans = val; l = sum; r = kol;}
}
if (sz(pr) > 0)
{
ll sum = a[v], kol = koler + pr[0] + 1;
ld val = ld(sum) / ld(kol);
if (ans == -1 || ans - val > 0) {ans = val; l = sum; r = kol;}
}
for (auto it : g[v])
{
if (it == p) continue;
rec(it, v, (a[v] == 1 ? koler + 1 : 0));
}
}
int main()
{
//freopen("input.txt", "r", stdin); //freopen("output4.txt", "w", stdout);
ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll n;
cin >> n;
for (ll i = 1; i < n; i++)
{
ll x, y;
cin >> x >> y;
g[x].pb(y);
g[y].pb(x);
}
for (ll i = 1; i <= n; i++) cin >> a[i];
dfs(1, -1);
rec(1, -1, 0);
ll gcd = __gcd(l, r);
l /= gcd;
r /= gcd;
cout << l << "/" << r << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
23936 KB |
Output is correct |
2 |
Correct |
19 ms |
23860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
23936 KB |
Output is correct |
2 |
Correct |
19 ms |
23936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
501 ms |
124172 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
23808 KB |
Output is correct |
2 |
Correct |
627 ms |
225828 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
583 ms |
222328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
484 ms |
70736 KB |
Output is correct |
2 |
Correct |
344 ms |
58592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
463 ms |
79284 KB |
Output is correct |
2 |
Correct |
101 ms |
29176 KB |
Output is correct |
3 |
Correct |
619 ms |
227436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
96 ms |
29176 KB |
Output is correct |
2 |
Correct |
479 ms |
72056 KB |
Output is correct |
3 |
Correct |
419 ms |
50552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
451 ms |
70244 KB |
Output is correct |
2 |
Correct |
481 ms |
70288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
512 ms |
71928 KB |
Output is correct |
2 |
Correct |
385 ms |
50424 KB |
Output is correct |