# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
532148 | Yazan_Alattar | Magic Tree (CEOI19_magictree) | C++14 | 133 ms | 37272 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x) x.begin(), x.end()
const int M = 100007;
const ll inf = 1e18;
const ll mod = 998244353;
const double pi = acos(-1);
const int dx[] = {0, -1, 0, 1}, dy[] = {1, 0, -1, 0};
const int block = 320;
vector <int> adj[M];
map <ll,ll> dp[M];
int n, m, k, ripe[M], w[M];
void dfs(int node){
for(auto i : adj[node]){
dfs(i);
if(dp[i].size() > dp[node].size()) swap(dp[i], dp[node]);
for(auto j : dp[i]) dp[node][j.F] += j.S;
}
dp[node][ripe[node]] += w[node];
ll rem = w[node];
while(1){
auto i = dp[node].lower_bound(ripe[node] + 1);
if(i == dp[node].end()) break;
if(i->S > rem){
i->S -= rem;
break;
}
else{
rem -= i->S;
dp[node].erase(i);
}
}
return;
}
int main(){
scanf("%d%d%d", &n, &m, &k);
for(int i = 2; i <= n; ++i){
int p; scanf("%d", &p);
adj[p].pb(i);
}
for(int i = 1; i <= m; ++i){
int x;
scanf("%d", &x);
scanf("%d%d", &ripe[x], &w[x]);
}
dfs(1);
ll ans = 0;
for(auto i : dp[1]) ans += i.S;
printf("%lld\n", ans);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |