#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int nx=1e5+5;
ll n, m, k, t[nx], w[nx], tmp[nx], x, p, sm, ans;
vector<int> d[nx];
struct value
{
ll time;
mutable ll val, idx;
bool operator< (const value &o) const
{
return time<o.time;
}
};
multiset<value> ms[nx];
void dfs(int u)
{
for (auto v:d[u]) dfs(v);
for (auto v:d[u]) for (auto tmp:ms[v]) ms[u].insert(tmp);
for (auto v:d[u]) ms[v].clear();
sm=0;
for (auto itr=ms[u].begin(); itr!=ms[u].end(); itr++)
{
sm+=itr->val-tmp[itr->idx];
tmp[itr->idx]=itr->val;
itr->val=sm;
itr->idx=u;
//cout<<"here"<<' '<<vl.time<<' '<<vl.val<<' '<<vl.idx<<'\n';
}
if (!t[u]) {
for (auto vl:ms[u]) ans=max(ans, vl.val);
//cout<<"current: "<<u<<'\n';
//for (auto vl:ms[u]) cout<<vl.time<<' '<<vl.val<<' '<<vl.idx<<'\n';
return;
}
//cout<<"current1: "<<u<<'\n';
//for (auto vl:ms[u]) cout<<vl.time<<' '<<vl.val<<' '<<vl.idx<<'\n';
value nw;
nw.time=t[u]; nw.val=LLONG_MAX; nw.idx=LLONG_MAX;
auto itr=ms[u].upper_bound(nw);
if (itr==ms[u].begin()) nw.val=w[u], nw.idx=u;
else nw.val=w[u]+prev(itr)->val, nw.idx=u;
itr=ms[u].insert(nw);
while (next(itr)!=ms[u].end()&&next(itr)->val<=itr->val) ms[u].erase(next(itr));
for (auto vl:ms[u]) ans=max(ans, vl.val);
//cout<<"current2: "<<u<<'\n';
//for (auto vl:ms[u]) cout<<vl.time<<' '<<vl.val<<' '<<vl.idx<<'\n';
}
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>m>>k;
for (int i=2; i<=n; i++) cin>>p, d[p].push_back(i);
for (int i=1; i<=m; i++) cin>>x>>t[x]>>w[x];
dfs(1);
cout<<ans<<'\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8796 KB |
Output is correct |
2 |
Correct |
2 ms |
8796 KB |
Output is correct |
3 |
Correct |
2 ms |
8796 KB |
Output is correct |
4 |
Correct |
2 ms |
8848 KB |
Output is correct |
5 |
Correct |
2 ms |
8796 KB |
Output is correct |
6 |
Correct |
2 ms |
8796 KB |
Output is correct |
7 |
Correct |
2 ms |
8796 KB |
Output is correct |
8 |
Correct |
2 ms |
8796 KB |
Output is correct |
9 |
Correct |
2 ms |
8792 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
14356 KB |
Output is correct |
2 |
Execution timed out |
2039 ms |
17852 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8792 KB |
Output is correct |
2 |
Correct |
3 ms |
9048 KB |
Output is correct |
3 |
Correct |
16 ms |
9032 KB |
Output is correct |
4 |
Correct |
62 ms |
27472 KB |
Output is correct |
5 |
Execution timed out |
2043 ms |
28188 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
160 ms |
21328 KB |
Output is correct |
2 |
Correct |
153 ms |
24656 KB |
Output is correct |
3 |
Execution timed out |
2025 ms |
20400 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8796 KB |
Output is correct |
2 |
Correct |
2 ms |
8796 KB |
Output is correct |
3 |
Correct |
2 ms |
8796 KB |
Output is correct |
4 |
Correct |
2 ms |
8848 KB |
Output is correct |
5 |
Correct |
2 ms |
8796 KB |
Output is correct |
6 |
Correct |
2 ms |
8796 KB |
Output is correct |
7 |
Correct |
2 ms |
8796 KB |
Output is correct |
8 |
Correct |
2 ms |
8796 KB |
Output is correct |
9 |
Correct |
2 ms |
8792 KB |
Output is correct |
10 |
Correct |
139 ms |
20560 KB |
Output is correct |
11 |
Correct |
123 ms |
20820 KB |
Output is correct |
12 |
Execution timed out |
2021 ms |
19412 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9304 KB |
Output is correct |
2 |
Correct |
21 ms |
12056 KB |
Output is correct |
3 |
Correct |
23 ms |
11864 KB |
Output is correct |
4 |
Correct |
19 ms |
12024 KB |
Output is correct |
5 |
Correct |
7 ms |
10460 KB |
Output is correct |
6 |
Correct |
229 ms |
14296 KB |
Output is correct |
7 |
Correct |
220 ms |
18000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8796 KB |
Output is correct |
2 |
Correct |
2 ms |
8796 KB |
Output is correct |
3 |
Correct |
2 ms |
8796 KB |
Output is correct |
4 |
Correct |
2 ms |
8848 KB |
Output is correct |
5 |
Correct |
2 ms |
8796 KB |
Output is correct |
6 |
Correct |
2 ms |
8796 KB |
Output is correct |
7 |
Correct |
2 ms |
8796 KB |
Output is correct |
8 |
Correct |
2 ms |
8796 KB |
Output is correct |
9 |
Correct |
2 ms |
8792 KB |
Output is correct |
10 |
Correct |
2 ms |
8792 KB |
Output is correct |
11 |
Correct |
3 ms |
9048 KB |
Output is correct |
12 |
Correct |
16 ms |
9032 KB |
Output is correct |
13 |
Correct |
62 ms |
27472 KB |
Output is correct |
14 |
Execution timed out |
2043 ms |
28188 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8796 KB |
Output is correct |
2 |
Correct |
2 ms |
8796 KB |
Output is correct |
3 |
Correct |
2 ms |
8796 KB |
Output is correct |
4 |
Correct |
2 ms |
8848 KB |
Output is correct |
5 |
Correct |
2 ms |
8796 KB |
Output is correct |
6 |
Correct |
2 ms |
8796 KB |
Output is correct |
7 |
Correct |
2 ms |
8796 KB |
Output is correct |
8 |
Correct |
2 ms |
8796 KB |
Output is correct |
9 |
Correct |
2 ms |
8792 KB |
Output is correct |
10 |
Correct |
59 ms |
14356 KB |
Output is correct |
11 |
Execution timed out |
2039 ms |
17852 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |