# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
46345 | 2018-04-19T14:12:49 Z | RezwanArefin01 | Chase (CEOI17_chase) | C++17 | 693 ms | 24828 KB |
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> ii; const int maxn = 1e5 + 10; vector<int> adj[maxn]; ll p[maxn], s[maxn], mx; multiset<ll> st; int n, v; void solve(int u, int par) { st.insert(s[u] - p[par]); ll tot = 0; int tk = v; for(auto it = --st.end(); it != st.begin() && tk; it--, tk--) tot += *it; mx = max(mx, tot); for(int v : adj[u]) if(v - par) solve(v, u); auto it = st.find(s[u] - p[par]); if(it != st.end()) st.erase(it); } int main(int argc, char const *argv[]) { #ifdef LOCAL_TESTING freopen("in", "r", stdin); #endif scanf("%d %d", &n, &v); for(int i = 1; i <= n; i++) scanf("%lld", &p[i]); for(int i = 1; i < n; i++) { int u, v; scanf("%d %d", &u, &v); adj[u].push_back(v); adj[v].push_back(u); } for(int i = 1; i <= n; i++) { for(int v : adj[i]) s[i] += p[v]; } if(n > 1000) solve(1, 0); else for(int i = 1; i <= n; i++) { st.clear(); solve(i, 0); } printf("%lld\n", mx); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 2680 KB | Output is correct |
2 | Correct | 4 ms | 2680 KB | Output is correct |
3 | Correct | 4 ms | 2876 KB | Output is correct |
4 | Correct | 4 ms | 2916 KB | Output is correct |
5 | Correct | 4 ms | 3028 KB | Output is correct |
6 | Correct | 4 ms | 3028 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 2680 KB | Output is correct |
2 | Correct | 4 ms | 2680 KB | Output is correct |
3 | Correct | 4 ms | 2876 KB | Output is correct |
4 | Correct | 4 ms | 2916 KB | Output is correct |
5 | Correct | 4 ms | 3028 KB | Output is correct |
6 | Correct | 4 ms | 3028 KB | Output is correct |
7 | Correct | 693 ms | 3164 KB | Output is correct |
8 | Correct | 233 ms | 3276 KB | Output is correct |
9 | Correct | 75 ms | 3312 KB | Output is correct |
10 | Correct | 204 ms | 3312 KB | Output is correct |
11 | Correct | 203 ms | 3380 KB | Output is correct |
12 | Correct | 193 ms | 3380 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 235 ms | 16220 KB | Output is correct |
2 | Correct | 255 ms | 18288 KB | Output is correct |
3 | Correct | 84 ms | 18288 KB | Output is correct |
4 | Correct | 114 ms | 18288 KB | Output is correct |
5 | Correct | 135 ms | 18556 KB | Output is correct |
6 | Correct | 154 ms | 20776 KB | Output is correct |
7 | Correct | 137 ms | 22848 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 2680 KB | Output is correct |
2 | Correct | 4 ms | 2680 KB | Output is correct |
3 | Correct | 4 ms | 2876 KB | Output is correct |
4 | Correct | 4 ms | 2916 KB | Output is correct |
5 | Correct | 4 ms | 3028 KB | Output is correct |
6 | Correct | 4 ms | 3028 KB | Output is correct |
7 | Correct | 693 ms | 3164 KB | Output is correct |
8 | Correct | 233 ms | 3276 KB | Output is correct |
9 | Correct | 75 ms | 3312 KB | Output is correct |
10 | Correct | 204 ms | 3312 KB | Output is correct |
11 | Correct | 203 ms | 3380 KB | Output is correct |
12 | Correct | 193 ms | 3380 KB | Output is correct |
13 | Correct | 235 ms | 16220 KB | Output is correct |
14 | Correct | 255 ms | 18288 KB | Output is correct |
15 | Correct | 84 ms | 18288 KB | Output is correct |
16 | Correct | 114 ms | 18288 KB | Output is correct |
17 | Correct | 135 ms | 18556 KB | Output is correct |
18 | Correct | 154 ms | 20776 KB | Output is correct |
19 | Correct | 137 ms | 22848 KB | Output is correct |
20 | Incorrect | 115 ms | 24828 KB | Output isn't correct |
21 | Halted | 0 ms | 0 KB | - |