# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
137521 |
2019-07-28T06:04:18 Z |
abacaba |
Mag (COCI16_mag) |
C++14 |
|
517 ms |
115560 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];
vector <int> g[N];
pair <int, int> ans = {inf, 1};
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], 2LL + dp[to]};
if(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;
}
if(a[to] == 1)
dp[v] = max(dp[v], dp[to] + 1);
}
}
pair <int, int> x = {a[v], 1LL + dp[v]};
if(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;
}
}
#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(a[i] < ans.first)
ans = x;
}
dfs(1);
cout << ans.first << '/' << ans.second << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
23800 KB |
Output is correct |
2 |
Correct |
24 ms |
23804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
24 ms |
23928 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
418 ms |
80324 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
27 ms |
23796 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
517 ms |
115560 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
461 ms |
70472 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
484 ms |
72976 KB |
Output is correct |
2 |
Incorrect |
102 ms |
29176 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
97 ms |
29056 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
431 ms |
67660 KB |
Output is correct |
2 |
Incorrect |
461 ms |
70116 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
487 ms |
71184 KB |
Output is correct |
2 |
Incorrect |
398 ms |
50396 KB |
Output isn't correct |