#include <bits/stdc++.h>
#define pb push_back
#define f first
#define s second
#define dbg(x) cout << "reached here " << x << endl;
#define ll long long
using namespace std;
typedef pair<int, int> pii;
const int maxn = 1e5+5;
int a[maxn];
vector<int> adj[maxn];
map<int, int> sack[maxn];
void merge(int v, int u)
{
for (auto e: sack[u])
sack[v][e.f] += e.s;
}
void dfs(int v)
{
for(auto u: adj[v])
{
dfs(u);
if(sack[u].size() > sack[v].size())
sack[v].swap(sack[u]);
}
for (auto u: adj[v])
merge(v, u);
if(a[v])
{
int h = 0;
if(sack[v].size() > 1)
{
auto it = sack[v].rbegin();
if((*it).f > a[v])
h += (*it).s;
it--;
if((*it).f > a[v])
h += (*it).s;
}
else if(sack[v].size() == 1)
{
auto it = sack[v].rbegin();
if((*it).f > a[v])
h += (*it).s;
}
if(h <= 1)
{
sack[v][a[v]]++;
auto it = sack[v].rbegin();
while((*it).f > a[v] and it != sack[v].rend())
{
auto del = sack[v].find((*it).f);
sack[v].erase(del);
it--;
}
}
}
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m, k;
cin >> n >> m >> k;
for (int i = 2; i <= n; ++i)
{
int p;
cin >> p;
adj[p].pb(i);
}
for (int i = 1; i <= m; ++i)
{
int v, d, w;
cin >> v >> d >> w;
a[v] = d;
}
dfs(1);
int ans = 0;
for (auto u: sack[1])
ans += u.s;
cout << ans << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
7256 KB |
Output is correct |
2 |
Correct |
2 ms |
7260 KB |
Output is correct |
3 |
Correct |
2 ms |
7260 KB |
Output is correct |
4 |
Correct |
2 ms |
7512 KB |
Output is correct |
5 |
Correct |
2 ms |
7260 KB |
Output is correct |
6 |
Correct |
2 ms |
7468 KB |
Output is correct |
7 |
Correct |
2 ms |
7516 KB |
Output is correct |
8 |
Correct |
2 ms |
7512 KB |
Output is correct |
9 |
Correct |
2 ms |
7260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
38 ms |
14940 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
7524 KB |
Output is correct |
2 |
Incorrect |
2 ms |
7516 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
37 ms |
12124 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
7256 KB |
Output is correct |
2 |
Correct |
2 ms |
7260 KB |
Output is correct |
3 |
Correct |
2 ms |
7260 KB |
Output is correct |
4 |
Correct |
2 ms |
7512 KB |
Output is correct |
5 |
Correct |
2 ms |
7260 KB |
Output is correct |
6 |
Correct |
2 ms |
7468 KB |
Output is correct |
7 |
Correct |
2 ms |
7516 KB |
Output is correct |
8 |
Correct |
2 ms |
7512 KB |
Output is correct |
9 |
Correct |
2 ms |
7260 KB |
Output is correct |
10 |
Incorrect |
44 ms |
15188 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
8028 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
7256 KB |
Output is correct |
2 |
Correct |
2 ms |
7260 KB |
Output is correct |
3 |
Correct |
2 ms |
7260 KB |
Output is correct |
4 |
Correct |
2 ms |
7512 KB |
Output is correct |
5 |
Correct |
2 ms |
7260 KB |
Output is correct |
6 |
Correct |
2 ms |
7468 KB |
Output is correct |
7 |
Correct |
2 ms |
7516 KB |
Output is correct |
8 |
Correct |
2 ms |
7512 KB |
Output is correct |
9 |
Correct |
2 ms |
7260 KB |
Output is correct |
10 |
Correct |
3 ms |
7524 KB |
Output is correct |
11 |
Incorrect |
2 ms |
7516 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
7256 KB |
Output is correct |
2 |
Correct |
2 ms |
7260 KB |
Output is correct |
3 |
Correct |
2 ms |
7260 KB |
Output is correct |
4 |
Correct |
2 ms |
7512 KB |
Output is correct |
5 |
Correct |
2 ms |
7260 KB |
Output is correct |
6 |
Correct |
2 ms |
7468 KB |
Output is correct |
7 |
Correct |
2 ms |
7516 KB |
Output is correct |
8 |
Correct |
2 ms |
7512 KB |
Output is correct |
9 |
Correct |
2 ms |
7260 KB |
Output is correct |
10 |
Incorrect |
38 ms |
14940 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |