# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
242275 | 2020-06-27T08:02:48 Z | shenxy | Magic Tree (CEOI19_magictree) | C++11 | 2000 ms | 795592 KB |
#include <cstdio> #include <algorithm> #include <vector> #include <cstring> #include <map> using namespace std; typedef pair<int, int> ii; int n, m, k, d[100000]; long long dpt1[100000][22], w[100000]; vector<int> adjlist[100000]; long long dp1(int v, int x) { if (dpt1[v][x] != -1) return dpt1[v][x]; if (x == 0) return dpt1[v][x] = 0; dpt1[v][x] = (d[v] == x ? w[v] : 0); for (int i: adjlist[v]) dpt1[v][x] += dp1(i, x); return dpt1[v][x] = max(dpt1[v][x], dp1(v, x - 1)); } int cnt = 1; map<int, ii> mp; vector<int> adjlist2[1001]; void dfs(int v, int p) { d[0] = w[0] = 0; if (mp.find(v) != mp.end()) { d[cnt] = mp[v].first; w[cnt] = mp[v].second; adjlist2[p].push_back(cnt); p = cnt; ++cnt; } for (int i: adjlist[v]) dfs(i, p); } long long dpt2[1001][100002]; long long dp2(int v, int x) { if (dpt2[v][x] != -1) return dpt2[v][x]; if (x == 0) return dpt2[v][x] = 0; dpt2[v][x] = (d[v] == x ? w[v] : 0); for (int i: adjlist2[v]) dpt2[v][x] += dp2(i, x); return dpt2[v][x] = max(dpt2[v][x], dp2(v, x - 1)); } int main() { scanf("%d %d %d", &n, &m, &k); if (k <= 20) { int p, v, D, W; for (int i = 1; i < n; ++i) { scanf("%d", &p); adjlist[p - 1].push_back(i); } fill_n(d, 100000, 0); fill_n(w, 100000, 0); for (int i = 0; i < m; ++i) { scanf("%d %d %d", &v, &D, &W); d[v - 1] = D; w[v - 1] = W; } memset(dpt1, -1, sizeof dpt1); printf("%lld", dp1(0, k + 1)); } else if (m <= 1000) { int p, v, d, w; for (int i = 1; i < n; ++i) { scanf("%d", &p); adjlist[p - 1].push_back(i); } for (int i = 0; i < m; ++i) { scanf("%d %d %d", &v, &d, &w); mp[v - 1] = ii(d, w); } memset(dpt2, -1, sizeof dpt2); dfs(0, 0); printf("%lld", dp2(0, k + 1)); } else { for (int i = 1; i < n; ++i) scanf("%d", &k); int v, d, w; long long ans = 0; for (int i = 0; i < m; ++i) { scanf("%d %d %d", &v, &d, &w); ans += w; } printf("%lld", ans); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 18 ms | 21120 KB | Output is correct |
2 | Correct | 15 ms | 21120 KB | Output is correct |
3 | Correct | 15 ms | 21120 KB | Output is correct |
4 | Correct | 15 ms | 21120 KB | Output is correct |
5 | Correct | 17 ms | 21120 KB | Output is correct |
6 | Correct | 15 ms | 21120 KB | Output is correct |
7 | Correct | 17 ms | 21120 KB | Output is correct |
8 | Correct | 17 ms | 21120 KB | Output is correct |
9 | Correct | 15 ms | 21120 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 30 ms | 3832 KB | Output is correct |
2 | Correct | 27 ms | 2688 KB | Output is correct |
3 | Correct | 54 ms | 2688 KB | Output is correct |
4 | Correct | 50 ms | 2688 KB | Output is correct |
5 | Correct | 54 ms | 2688 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 376 ms | 786552 KB | Output is correct |
2 | Correct | 383 ms | 786712 KB | Output is correct |
3 | Correct | 378 ms | 786500 KB | Output is correct |
4 | Incorrect | 48 ms | 4472 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 93 ms | 24824 KB | Output is correct |
2 | Correct | 91 ms | 24700 KB | Output is correct |
3 | Correct | 87 ms | 28536 KB | Output is correct |
4 | Correct | 66 ms | 23408 KB | Output is correct |
5 | Correct | 81 ms | 33832 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 18 ms | 21120 KB | Output is correct |
2 | Correct | 15 ms | 21120 KB | Output is correct |
3 | Correct | 15 ms | 21120 KB | Output is correct |
4 | Correct | 15 ms | 21120 KB | Output is correct |
5 | Correct | 17 ms | 21120 KB | Output is correct |
6 | Correct | 15 ms | 21120 KB | Output is correct |
7 | Correct | 17 ms | 21120 KB | Output is correct |
8 | Correct | 17 ms | 21120 KB | Output is correct |
9 | Correct | 15 ms | 21120 KB | Output is correct |
10 | Correct | 124 ms | 24312 KB | Output is correct |
11 | Correct | 119 ms | 24184 KB | Output is correct |
12 | Correct | 106 ms | 28152 KB | Output is correct |
13 | Correct | 93 ms | 22640 KB | Output is correct |
14 | Correct | 95 ms | 33528 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1195 ms | 791504 KB | Output is correct |
2 | Correct | 1221 ms | 793312 KB | Output is correct |
3 | Execution timed out | 2088 ms | 795592 KB | Time limit exceeded |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 18 ms | 21120 KB | Output is correct |
2 | Correct | 15 ms | 21120 KB | Output is correct |
3 | Correct | 15 ms | 21120 KB | Output is correct |
4 | Correct | 15 ms | 21120 KB | Output is correct |
5 | Correct | 17 ms | 21120 KB | Output is correct |
6 | Correct | 15 ms | 21120 KB | Output is correct |
7 | Correct | 17 ms | 21120 KB | Output is correct |
8 | Correct | 17 ms | 21120 KB | Output is correct |
9 | Correct | 15 ms | 21120 KB | Output is correct |
10 | Correct | 376 ms | 786552 KB | Output is correct |
11 | Correct | 383 ms | 786712 KB | Output is correct |
12 | Correct | 378 ms | 786500 KB | Output is correct |
13 | Incorrect | 48 ms | 4472 KB | Output isn't correct |
14 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 18 ms | 21120 KB | Output is correct |
2 | Correct | 15 ms | 21120 KB | Output is correct |
3 | Correct | 15 ms | 21120 KB | Output is correct |
4 | Correct | 15 ms | 21120 KB | Output is correct |
5 | Correct | 17 ms | 21120 KB | Output is correct |
6 | Correct | 15 ms | 21120 KB | Output is correct |
7 | Correct | 17 ms | 21120 KB | Output is correct |
8 | Correct | 17 ms | 21120 KB | Output is correct |
9 | Correct | 15 ms | 21120 KB | Output is correct |
10 | Correct | 30 ms | 3832 KB | Output is correct |
11 | Correct | 27 ms | 2688 KB | Output is correct |
12 | Correct | 54 ms | 2688 KB | Output is correct |
13 | Correct | 50 ms | 2688 KB | Output is correct |
14 | Correct | 54 ms | 2688 KB | Output is correct |
15 | Correct | 376 ms | 786552 KB | Output is correct |
16 | Correct | 383 ms | 786712 KB | Output is correct |
17 | Correct | 378 ms | 786500 KB | Output is correct |
18 | Incorrect | 48 ms | 4472 KB | Output isn't correct |
19 | Halted | 0 ms | 0 KB | - |