# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
660930 | 2022-11-23T14:39:09 Z | Trisanu_Das | Mag (COCI16_mag) | C++14 | 720 ms | 262144 KB |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; vector<int> g[maxn], len[maxn]; int a[maxn]; int memo[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 : g[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); } memo[x] = len[x][0] + len[x][1]; for (int v : g[x]) { if (v == p) continue; dfs_root(v, x); } } int main() { scanf("%d", &n); for (int i = 1; i <= n-1; ++i) { int a, b; scanf("%d %d", &a, &b); g[a].emplace_back(b); g[b].emplace_back(a); } for (int i = 1; i <= n; ++i) { scanf("%d", 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* (memo[i] + 1) > a[i] *1ll* y) { x = a[i]; y = memo[i] + 1; } } int g = __gcd(x, y); printf("%d/%d\n", x/g, y/g); return 0; } ///hhhh
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 61 ms | 95712 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 59 ms | 95764 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 489 ms | 262144 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 59 ms | 95560 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 720 ms | 262144 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 492 ms | 229876 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 484 ms | 231848 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 114 ms | 109300 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 454 ms | 221272 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 488 ms | 231592 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |