#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define ss second
#define ff first
#define piii pair<int,pii>
#define debu(x) (cerr << #x << " = "<< x << "\n")
#define debu2(x,y) (cerr << #x << " = "<< x << " " << #y << " = " << y << "\n")
#define debu3(x,y,z) (cerr << #x << " = "<< x << " " << #y << " = " << y << " " << #z << " = " << z<< "\n")
#define bitout(x,y) {\
cerr << #x << " : ";\
for (int justforbits = y; justforbits >=0; justforbits--)cout << (((1 << justforbits) & x)>=1);\
cout << "\n";\
}
#define rangeout(j,rangestart,rangeend) {\
cerr << "outputting" << #j<< ":\n";\
for (int forrang = rangestart; forrang <= rangeend; forrang++)cerr << j[forrang] << " ";\
cerr<<"\n";\
}
#define c1 {cerr << "Checkpoint 1! \n\n";cerr.flush();}
#define c2 {cerr << "Checkpoint 2! \n\n";cerr.flush();}
#define c3 {cerr << "Checkpoint 3! \n\n";cerr.flush();}
#define c4 {cerr << "Checkpoint 4! \n\n";cerr.flush();}
#define defN 100001
vector<multiset<int>>thesets(defN);
vector<vector<int>>childlist(defN);
vector<int>myval(defN);
int dfs(int cn)
{
int retno=cn;
for(int child:childlist[cn])
{
int x=dfs(child);
if(thesets[x].size()<=thesets[retno].size())
{
for(auto num=thesets[x].begin();num!=thesets[x].end();x++)
{
thesets[retno].insert(*num);
}
}
else
{
for(auto num=thesets[retno].begin();num!=thesets[retno].end();x++)
{
thesets[x].insert(*num);
}
retno=x;
}
}
int curr=myval[cn];
if(thesets[retno].empty()||*prev(thesets[retno].end())<=curr)
{
thesets[retno].insert(curr);
}
else
{
thesets[retno].erase(thesets[retno].upper_bound(curr));
thesets[retno].insert(curr);
}
return retno;
}
signed main()
{
int t1,t2,t3,t4;
mt19937_64 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
//ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n,m,k;cin>>n>>m>>k;
for(int a=1;a<n;a++)
{
cin>>t1;
childlist[t1].pb(a);
}
for(int a=1;a<=m;a++)
{
cin>>t1>>t2>>t3;
myval[t1]=t2;
}
int ans=dfs(1);
cout<<thesets[ans].size();
}
# | 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... |