# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
660914 |
2022-11-23T14:20:24 Z |
Trisanu_Das |
Mag (COCI16_mag) |
C++17 |
|
1178 ms |
262144 KB |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
vector<int> adj[maxn], len[maxn];
int a[maxn], dp[maxn];
int n;
void add(int x, int t) {
if (len[x][0] <= t) swap(len[x][0], t);
len[x][1] = max(len[x][1], t);
}
int get(int x, int t=0) {return (a[x] == 1) * (len[x][t] + 1);}
int dfs(int x, int p = 0) {
len[x] = {0, 0};
for (int v : adj[x]) {
if (v == p) continue;
add(x, dfs(v, x));
}
return get(x);
}
int dfs_root(int x, int p = 0) {
if (p) {
int l = (a[p] == 1) * get(p, len[p][0] == get(x));
add(x, l);
}
dp[x] = len[x][0] + len[x][1];
for (int v : adj[x]) {
if (v == p) continue;
dfs_root(v, x);
}
}
int main() {
cin >> n;
for (int i = 1; i < n; i++) {
int a, b; cin >> a >> b;
adj[a].emplace_back(b);
adj[b].emplace_back(a);
}
for (int i = 1; i <= n; ++i) cin >> a[i];
dfs(1);
dfs_root(1);
int x = -1, y = -1;
for (int i = 1; i <= n; ++i) {
if (x == -1 or x *1ll* (dp[i] + 1) > a[i] *1ll* y) {
x = a[i];
y = dp[i] + 1;
}
}
int g = __gcd(x, y);
cout << x/g << '/' << y/g << '\n';
return 0;
}
Compilation message
mag.cpp: In function 'int dfs_root(int, int)':
mag.cpp:34:1: warning: no return statement in function returning non-void [-Wreturn-type]
34 | }
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
63 ms |
95820 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
59 ms |
95728 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
840 ms |
262144 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
70 ms |
95556 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1178 ms |
262144 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
880 ms |
244984 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
933 ms |
249144 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
166 ms |
110736 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
850 ms |
236940 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
887 ms |
247012 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |