# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
206071 | 2020-03-02T07:17:35 Z | PeppaPig | Designated Cities (JOI19_designated_cities) | C++14 | 531 ms | 48776 KB |
#include <bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<LL, int> pii; int N, Q; vector<pii> G[202020], RG[202020]; int deg[202020]; bool chk[202020]; LL ans[202020], sum; priority_queue<pii> PQ; LL d(int u, int p){ LL ret = 0; for (pii v : RG[u]) if (v.second != p) ret += d(v.second, u) + v.first; return ret; } void f(int u, int p){ ans[1] = min(ans[1], sum); for (int i=0; i<(int)G[u].size(); i++){ if (G[u][i].second == p) continue; sum -= RG[u][i].first; sum += G[u][i].first; f(G[u][i].second, u); sum += RG[u][i].first; sum -= G[u][i].first; } } int main(){ int u, v; LL x, y; scanf("%d", &N); for (int i=1; i<N; i++){ scanf("%d %d %lld %lld", &u, &v, &x, &y); G[u].push_back(pii(y, v)); G[v].push_back(pii(x, u)); RG[v].push_back(pii(y, u)); RG[u].push_back(pii(x, v)); deg[u]++, deg[v]++; } for (int i=1; i<=N; i++) if (deg[i] == 1) PQ.push(pii(-G[i][0].first, i)); ans[1] = 1234567890123456ll; sum = d(1, 0); f(1, 0); scanf("%d", &Q); while (Q--){ scanf("%d", &u); printf("%lld\n", ans[u]); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 9848 KB | Output is correct |
2 | Incorrect | 11 ms | 9848 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 9848 KB | Output is correct |
2 | Correct | 457 ms | 39528 KB | Output is correct |
3 | Correct | 519 ms | 48160 KB | Output is correct |
4 | Correct | 445 ms | 38248 KB | Output is correct |
5 | Correct | 439 ms | 39712 KB | Output is correct |
6 | Correct | 466 ms | 40676 KB | Output is correct |
7 | Correct | 371 ms | 39380 KB | Output is correct |
8 | Correct | 531 ms | 48776 KB | Output is correct |
9 | Correct | 304 ms | 42040 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 9848 KB | Output is correct |
2 | Incorrect | 453 ms | 33132 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 9848 KB | Output is correct |
2 | Incorrect | 11 ms | 9848 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 9848 KB | Output is correct |
2 | Correct | 457 ms | 39528 KB | Output is correct |
3 | Correct | 519 ms | 48160 KB | Output is correct |
4 | Correct | 445 ms | 38248 KB | Output is correct |
5 | Correct | 439 ms | 39712 KB | Output is correct |
6 | Correct | 466 ms | 40676 KB | Output is correct |
7 | Correct | 371 ms | 39380 KB | Output is correct |
8 | Correct | 531 ms | 48776 KB | Output is correct |
9 | Correct | 304 ms | 42040 KB | Output is correct |
10 | Correct | 11 ms | 9848 KB | Output is correct |
11 | Incorrect | 453 ms | 33132 KB | Output isn't correct |
12 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 9848 KB | Output is correct |
2 | Incorrect | 11 ms | 9848 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |