# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
384802 | 2021-04-02T10:01:02 Z | kostia244 | Designated Cities (JOI19_designated_cities) | C++17 | 6 ms | 5228 KB |
#include<bits/stdc++.h> using namespace std; using ll = long long; const int maxn = 1e5 + 12; int n, cst[maxn]; ll edgesum = 0; vector<array<int, 2>> g[maxn]; ll sub[maxn]; void sub_cost(int v, int p) { for(auto [i, id] : g[v]) if(i != p) { sub_cost(i, v); sub[v] += sub[i] + cst[id]; } } ll arb[maxn]; void reroot_cost(int v, int p, ll sum) { arb[v] = sum; for(auto [i, id] : g[v]) if(i!=p) { reroot_cost(i, v, sum-cst[id]+cst[id^1]); } } int main() { cin.tie(0)->sync_with_stdio(0); cin >> n; for(int f, t, x, y, i = 1; i < n; i++) { cin >> f >> t >> cst[2*i-1] >> cst[2*i-2]; edgesum += cst[2*i-1]; edgesum += cst[2*i-2]; g[f].push_back({t, 2*i-2}); g[t].push_back({f, 2*i-1}); } sub_cost(1, 0); reroot_cost(1, 0, sub[1]); int q; cin >> q; for(int t; q--;) { cin >> t; if(t == 1) { cout << edgesum-*max_element(arb+1, arb+n+1) << '\n'; } } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 2668 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2668 KB | Output is correct |
2 | Runtime error | 6 ms | 5228 KB | Execution killed with signal 11 |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 2668 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 2668 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2668 KB | Output is correct |
2 | Runtime error | 6 ms | 5228 KB | Execution killed with signal 11 |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 2668 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |