# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
110518 | 2019-05-11T05:31:56 Z | AngusRitossa | Designated Cities (JOI19_designated_cities) | C++14 | 500 ms | 42516 KB |
#include <bits/stdc++.h> using namespace std; #define int long long vector<pair<int, pair<int, int> > > adj[200010]; int n; int dgoingup[200010], dgoingdown[200010], done[200010]; int goingup(int a) { if (dgoingup[a]) return dgoingup[a]-1; dgoingup[a] = 1; for (auto b : adj[a]) { if (!dgoingup[b.first]) dgoingup[a] += goingup(b.first), dgoingup[a] += b.second.second; } return dgoingup[a]-1; } int goingdown(int a) { if (dgoingdown[a]) return dgoingdown[a]-1; dgoingdown[a] = 1; for (auto b : adj[a]) { if (!dgoingdown[b.first]) dgoingdown[a] += goingdown(b.first), dgoingdown[a] += b.second.first; } return dgoingdown[a]-1; } int oneans = 1e15; void findoneans(int a, int above) { done[a] = 1; int am = 0; for (auto b : adj[a]) { if (done[b.first]) continue; am += goingup(b.first)+b.second.second; } oneans = min(oneans, am+above); for (auto b : adj[a]) { if (done[b.first]) continue; findoneans(b.first, above+am-goingup(b.first)-b.second.second + b.second.first); } } #undef int int main() { #define int long long scanf("%lld", &n); for (int i = 1; i < n; i++) { int a, b, c, d; scanf("%lld%lld%lld%lld", &a, &b, &c, &d); a--; b--; adj[a].push_back({ b, { d, c }}); adj[b].push_back({ a, { c, d }}); } goingup(0), goingdown(0), findoneans(0, 0); printf("%lld\n", oneans); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 7 ms | 5120 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 5120 KB | Output is correct |
2 | Correct | 438 ms | 23100 KB | Output is correct |
3 | Correct | 500 ms | 42060 KB | Output is correct |
4 | Correct | 416 ms | 27840 KB | Output is correct |
5 | Correct | 476 ms | 29020 KB | Output is correct |
6 | Correct | 469 ms | 31184 KB | Output is correct |
7 | Correct | 344 ms | 28084 KB | Output is correct |
8 | Correct | 495 ms | 42516 KB | Output is correct |
9 | Correct | 254 ms | 27252 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 7 ms | 4992 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 7 ms | 5120 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 5120 KB | Output is correct |
2 | Correct | 438 ms | 23100 KB | Output is correct |
3 | Correct | 500 ms | 42060 KB | Output is correct |
4 | Correct | 416 ms | 27840 KB | Output is correct |
5 | Correct | 476 ms | 29020 KB | Output is correct |
6 | Correct | 469 ms | 31184 KB | Output is correct |
7 | Correct | 344 ms | 28084 KB | Output is correct |
8 | Correct | 495 ms | 42516 KB | Output is correct |
9 | Correct | 254 ms | 27252 KB | Output is correct |
10 | Incorrect | 7 ms | 4992 KB | Output isn't correct |
11 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 7 ms | 5120 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |