# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
56536 | 2018-07-11T15:11:12 Z | aquablitz11 | Islands (IOI08_islands) | C++14 | 582 ms | 132096 KB |
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 1000010; const ll INF = 1e18; ll par[N], len[N], deg[N], h1[N], h2[N], dp[N]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; ++i) { int v, w; scanf("%d%d", &v, &w); par[i] = v; len[i] = w; ++deg[v]; } queue<int> Q; for (int i = 1; i <= n; ++i) { if (deg[i] == 0) Q.push(i); } while (!Q.empty()) { int u = Q.front(); Q.pop(); int v = par[u]; ll w = len[u]; if (h1[u]+w > h1[v]) { h2[v] = h1[v]; h1[v] = h1[u]+w; } else if (h1[u]+w > h2[v]) { h2[v] = h1[u]+w; } dp[u] = max(dp[u], h1[u]+h2[u]); dp[v] = max(dp[v], dp[u]); if (--deg[v] == 0) Q.push(v); } ll ttans = 0; for (int i = 1; i <= n; ++i) { if (deg[i] == 1) { int u = i; vector<int> cyc; ll ttd = 0; do { cyc.push_back(u); deg[u] = 0; ttd += len[u]; u = par[u]; } while (u != i); ll mxm = -INF, mxp = -INF, d = 0, ans = -INF; for (auto u : cyc) { dp[u] = max(dp[u], h1[u]+h2[u]); ans = max(ans, dp[u]); ans = max(ans, h1[u]+d+mxm); ans = max(ans, h1[u]-d+ttd+mxp); mxm = max(mxm, h1[u]-d); mxp = max(mxp, h1[u]+d); d += len[u]; } ttans += ans; } } printf("%lld\n", ttans); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 488 KB | Output is correct |
3 | Correct | 3 ms | 488 KB | Output is correct |
4 | Correct | 2 ms | 656 KB | Output is correct |
5 | Correct | 2 ms | 660 KB | Output is correct |
6 | Correct | 2 ms | 724 KB | Output is correct |
7 | Correct | 2 ms | 792 KB | Output is correct |
8 | Correct | 2 ms | 792 KB | Output is correct |
9 | Correct | 2 ms | 792 KB | Output is correct |
10 | Correct | 2 ms | 796 KB | Output is correct |
11 | Correct | 2 ms | 796 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 796 KB | Output is correct |
2 | Correct | 4 ms | 796 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 940 KB | Output is correct |
2 | Correct | 4 ms | 1096 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 1796 KB | Output is correct |
2 | Correct | 18 ms | 3288 KB | Output is correct |
3 | Correct | 12 ms | 3288 KB | Output is correct |
4 | Correct | 9 ms | 3288 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 5160 KB | Output is correct |
2 | Correct | 39 ms | 8348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 100 ms | 16036 KB | Output is correct |
2 | Correct | 76 ms | 17952 KB | Output is correct |
3 | Correct | 96 ms | 25464 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 188 ms | 35552 KB | Output is correct |
2 | Correct | 192 ms | 48788 KB | Output is correct |
3 | Correct | 163 ms | 50960 KB | Output is correct |
4 | Correct | 238 ms | 71060 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 362 ms | 81340 KB | Output is correct |
2 | Correct | 582 ms | 108380 KB | Output is correct |
3 | Correct | 324 ms | 117484 KB | Output is correct |
4 | Runtime error | 405 ms | 132096 KB | Memory limit exceeded 132096 {'time-wall': '0.472', 'max-rss': '51268', 'csw-forced': '107', 'cg-mem': '132096', 'time': '0.405', 'csw-voluntary': '8'} 131072 |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 398 ms | 132096 KB | Memory limit exceeded 132096 {'time-wall': '0.445', 'max-rss': '48512', 'csw-forced': '181', 'cg-mem': '132096', 'time': '0.398', 'csw-voluntary': '5'} 131072 |
2 | Halted | 0 ms | 0 KB | - |