# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
877165 |
2023-11-23T01:31:40 Z |
noiaint |
Mag (COCI16_mag) |
C++17 |
|
365 ms |
174152 KB |
#include <bits/stdc++.h>
#define int long long
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
#define file ""
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define bit(x) (1LL << (x))
#define getbit(x, i) (((x) >> (i)) & 1)
#define popcount __builtin_popcountll
mt19937_64 rd(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r) {
return l + rd() % (r - l + 1);
}
const int N = 1e6 + 5;
const int mod = (int)1e9 + 7; // 998244353;
const int lg = 25; // lg + 1
const int oo = 1e9;
const long long ooo = 1e18;
template<class X, class Y> bool mini(X &a, Y b) {
return a > b ? (a = b, true) : false;
}
template<class X, class Y> bool maxi(X &a, Y b) {
return a < b ? (a = b, true) : false;
}
void add(int &a, int b) {
a += b;
if (a >= mod) a -= mod;
if (a < 0) a += mod;
}
int n;
int a[N];
vector<int> adj[N];
int f[N], f2[N];
void update(int u, int c) {
if (f[u] < c) f2[u] = f[u], f[u] = c;
else maxi(f2[u], c);
}
void dfsF(int u, int p) {
for (int v : adj[u]) if (v != p) {
dfsF(v, u);
if (a[v] == 1) update(u, f[v] + 1);
}
}
void dfsG(int u, int p) {
for (int v : adj[u]) if (v != p) {
if (a[u] == 1) {
if (f[u] == f[v] + 1) update(v, f2[u] + 1);
else update(v, f[u] + 1);
}
dfsG(v, u);
}
}
void process() {
cin >> n;
for (int i = 1; i < n; ++i) {
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
for (int i = 1; i <= n; ++i) cin >> a[i];
dfsF(1, 0);
dfsG(1, 0);
pair<int, int> ans = mp(1e18, 1);
for (int i = 1; i <= n; ++i) {
if (a[i] * ans.se < ans.fi * (f[i] + f2[i] + 1)) ans = mp(a[i], f[i] + f2[i] + 1);
}
int x = __gcd(ans.fi, ans.se);
ans.fi /= x;
ans.se /= x;
cout << ans.fi << '/' << ans.se;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
// freopen(file".inp", "r", stdin);
// freopen(file".out", "w", stdout);
int tc = 1;
// cin >> tc;
while (tc--) {
process();
}
return 0;
}
/*
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
24924 KB |
Output is correct |
2 |
Correct |
5 ms |
24924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
24920 KB |
Output is correct |
2 |
Correct |
6 ms |
24924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
248 ms |
113920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
24920 KB |
Output is correct |
2 |
Correct |
345 ms |
171080 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
365 ms |
170844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
253 ms |
93736 KB |
Output is correct |
2 |
Correct |
191 ms |
77392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
258 ms |
98036 KB |
Output is correct |
2 |
Correct |
40 ms |
35272 KB |
Output is correct |
3 |
Correct |
352 ms |
174152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
35156 KB |
Output is correct |
2 |
Correct |
260 ms |
94320 KB |
Output is correct |
3 |
Correct |
212 ms |
63696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
236 ms |
92436 KB |
Output is correct |
2 |
Correct |
259 ms |
94848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
284 ms |
94616 KB |
Output is correct |
2 |
Correct |
206 ms |
63692 KB |
Output is correct |