# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
56541 | 2018-07-11T15:12:25 Z | admin | Islands (IOI08_islands) | C++14 | 702 ms | 131908 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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 564 KB | Output is correct |
3 | Correct | 1 ms | 564 KB | Output is correct |
4 | Correct | 2 ms | 564 KB | Output is correct |
5 | Correct | 2 ms | 644 KB | Output is correct |
6 | Correct | 3 ms | 644 KB | Output is correct |
7 | Correct | 3 ms | 644 KB | Output is correct |
8 | Correct | 2 ms | 644 KB | Output is correct |
9 | Correct | 3 ms | 644 KB | Output is correct |
10 | Correct | 2 ms | 644 KB | Output is correct |
11 | Correct | 2 ms | 644 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 644 KB | Output is correct |
2 | Correct | 4 ms | 644 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 780 KB | Output is correct |
2 | Correct | 4 ms | 980 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 1676 KB | Output is correct |
2 | Correct | 15 ms | 3152 KB | Output is correct |
3 | Correct | 17 ms | 3152 KB | Output is correct |
4 | Correct | 9 ms | 3152 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 26 ms | 5092 KB | Output is correct |
2 | Correct | 42 ms | 8224 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 69 ms | 15980 KB | Output is correct |
2 | Correct | 86 ms | 17752 KB | Output is correct |
3 | Correct | 83 ms | 25304 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 167 ms | 35432 KB | Output is correct |
2 | Correct | 218 ms | 48736 KB | Output is correct |
3 | Correct | 186 ms | 48736 KB | Output is correct |
4 | Correct | 205 ms | 56300 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 310 ms | 56300 KB | Output is correct |
2 | Correct | 536 ms | 62776 KB | Output is correct |
3 | Correct | 254 ms | 62776 KB | Output is correct |
4 | Correct | 484 ms | 73532 KB | Output is correct |
5 | Correct | 337 ms | 86824 KB | Output is correct |
6 | Correct | 702 ms | 97160 KB | Output is correct |
7 | Correct | 432 ms | 118356 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 309 ms | 118356 KB | Output is correct |
2 | Correct | 395 ms | 127972 KB | Output is correct |
3 | Runtime error | 390 ms | 131908 KB | Memory limit exceeded 131908 {'time-wall': '0.444', 'max-rss': '36760', 'csw-forced': '205', 'cg-mem': '131908', 'time': '0.390', 'csw-voluntary': '5'} 131072 |
4 | Halted | 0 ms | 0 KB | - |