# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
137552 |
2019-07-28T06:26:53 Z |
abacaba |
Mag (COCI16_mag) |
C++14 |
|
541 ms |
140152 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int inf = 2e18;
const int N = 1e6 + 15;
int n, m, a[N], dp[N], dpup[N];
vector <int> g[N];
pair <int, int> ans = make_pair(0LL, 0LL);
void dfs(int v, int p = -1) {
for(int to : g[v]) {
if(p != to) {
dfs(to, v);
pair <int, int> x = {a[v] * a[to], dpup[v] + 2LL + dp[to]};
if(ans == make_pair(0LL, 0LL) || x.first * ans.second < ans.first * x.second) {
ans = x;
int c = __gcd(x.first, x.second);
if(c)
ans.first /= c, ans.second /= c;
}
}
}
pair <int, int> x = {a[v], dpup[v] + 1LL + dp[v]};
if(ans == make_pair(0LL, 0LL) || x.first * ans.second < ans.first * x.second) {
ans = x;
int c = __gcd(x.first, x.second);
if(c)
ans.first /= c, ans.second /= c;
}
}
void calc(int v, int p = -1) {
if(p != -1 && a[p] == 1)
dpup[v] = dpup[p] + 1;
for(int to : g[v])
if(to != p) {
calc(to, v);
if(a[to] == 1)
dp[v] = max(dp[v], dp[to] + 1);
}
}
#undef int
int main() {
#define int long long
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n;
for(int i = 1; i < n; ++i) {
int u, v;
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
for(int i = 1; i <= n; ++i) {
cin >> a[i];
pair <int, int> x = {a[i], 1LL};
if(ans == make_pair(0LL, 0LL) || a[i] < ans.first)
ans = x;
}
calc(1);
dfs(1);
cout << ans.first << '/' << ans.second << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
23928 KB |
Output is correct |
2 |
Correct |
24 ms |
23928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
23928 KB |
Output is correct |
2 |
Correct |
24 ms |
24056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
423 ms |
87652 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
23800 KB |
Output is correct |
2 |
Correct |
541 ms |
140152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
537 ms |
123248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
486 ms |
79828 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
462 ms |
80988 KB |
Output is correct |
2 |
Incorrect |
141 ms |
31480 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
100 ms |
31324 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
432 ms |
76128 KB |
Output is correct |
2 |
Incorrect |
474 ms |
77828 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
492 ms |
80396 KB |
Output is correct |
2 |
Incorrect |
441 ms |
56648 KB |
Output isn't correct |