# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
519687 | 2022-01-27T04:22:28 Z | Killer2501 | Mag (COCI16_mag) | C++14 | 5 ms | 876 KB |
#include <bits/stdc++.h> #define ll long long #define ld double #define ull unsigned long long #define pb push_back #define pll pair<ll, ll> #define pii pair<int, int> #define fi first #define se second using namespace std; const int N = 1e3+5; const int M = 1e2+2; const ll base = 1e4; const ll mod = 998244353; const int inf = 1e9; const double ex = 1e-9; int k, t, n; int a[N], b[N], tong, m, ans; pii mx[N]; vector<int> vi, adj[N]; mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count()); double p[N][N], res[N], q[N]; void upd(int u, int x) { if(x > mx[u].fi)mx[u].fi = x; else if(x > mx[u].se)mx[u].se = x; } void dfs(int u, int p = 0) { for(int v: adj[u]) { if(v == p)continue; dfs(v, u); if(a[v] == 1)upd(u, mx[v].fi+1); } } void dfs1(int u, int p = 0) { for(int v: adj[u]) { if(v == p)continue; if(a[u] == 1) { if(mx[u].fi != mx[v].fi+1)upd(v, mx[u].fi+1); else upd(v, mx[u].se+1); } dfs1(v, u); } } void sol(int icase) { cin >> n; for(int i = 1; i < n; i ++) { int x, y; cin >> x >> y; adj[x].pb(y); adj[y].pb(x); } for(int i = 1; i <= n; i ++)cin >> a[i]; dfs(1); dfs1(1); pii res; res.fi = inf; res.se = 1; for(int u = 1; u <= n; u ++) { //cout << a[u] <<" "<<mx[u].fi<<" "<<mx[u].se<<'\n'; if(1ll * res.fi * (mx[u].fi+mx[u].se+1) > 1ll * a[u] * res.se) { res.fi = a[u]; res.se = mx[u].se+mx[u].fi+1; } } k = __gcd(res.fi, res.se); res.fi /= k; res.se /= k; cout << res.fi <<"/"<<res.se; } int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); #define task "test" if(fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } int test = 1; //cin >> test; for(int i = 1; i <= test; i ++)sol(i); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 KB | Output is correct |
2 | Correct | 1 ms | 336 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 KB | Output is correct |
2 | Correct | 1 ms | 336 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 1 ms | 456 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 336 KB | Output is correct |
2 | Runtime error | 3 ms | 852 KB | Execution killed with signal 6 |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 3 ms | 876 KB | Execution killed with signal 6 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 1 ms | 540 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 1 ms | 492 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 1 ms | 484 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 1 ms | 464 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 5 ms | 876 KB | Execution killed with signal 6 |
2 | Halted | 0 ms | 0 KB | - |