# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
242336 | 2020-06-27T08:58:08 Z | dantoh000 | Magic Tree (CEOI19_magictree) | C++14 | 87 ms | 13560 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; int n,m,k; int p[100005]; vector<int> G[100005]; int a[100005]; int L[100005]; int V[100005][2]; ll dp[100005][2]; bool isline = 1; ll LEAFANS = 0; void dfs(int u){ dp[u][0] = dp[u][1] = 0; for (auto v: G[u]){ dfs(v); dp[u][0] += dp[v][0]; dp[u][1] += dp[v][1]; } dp[u][0] += V[u][0]; dp[u][1] += V[u][1]; dp[u][0] = max(dp[u][0],dp[u][1]); } int main(){ scanf("%d%d%d",&n,&m,&k); for (int i = 2; i <= n; i++){ scanf("%d",&p[i]); G[p[i]].push_back(i); if (p[i] != i-1) isline = false; } for (int i = 0; i < m; i++){ int v,d,w; scanf("%d%d%d",&v,&d,&w); a[v] = d; LEAFANS += w; V[v][2-d] += w; } if (k <= 2){ dfs(1); printf("%lld\n",dp[1][0]); } else if (isline){ int ans = 0; for (int i = 0; i <= n; i++) L[i] = 1000000005; for (int i = n; i >= 1; i--){ if (a[i] == 0) continue; int pos = upper_bound(L,L+ans,a[i])-L; //printf("%d goes %d\n",a[i],pos); L[pos] = a[i]; ans = max(ans,pos+1); } printf("%d\n",ans); } else printf("%lld\n",LEAFANS); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 6 ms | 2688 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 45 ms | 6008 KB | Output is correct |
2 | Correct | 35 ms | 6136 KB | Output is correct |
3 | Correct | 67 ms | 5368 KB | Output is correct |
4 | Correct | 55 ms | 5232 KB | Output is correct |
5 | Correct | 62 ms | 5368 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 2752 KB | Output is correct |
2 | Correct | 6 ms | 2688 KB | Output is correct |
3 | Correct | 7 ms | 2688 KB | Output is correct |
4 | Correct | 57 ms | 7416 KB | Output is correct |
5 | Correct | 58 ms | 8184 KB | Output is correct |
6 | Correct | 63 ms | 8184 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 87 ms | 7468 KB | Output is correct |
2 | Correct | 87 ms | 7672 KB | Output is correct |
3 | Correct | 72 ms | 10232 KB | Output is correct |
4 | Correct | 57 ms | 6256 KB | Output is correct |
5 | Correct | 68 ms | 13560 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 6 ms | 2688 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 11 ms | 3584 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 6 ms | 2688 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 6 ms | 2688 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |