A. A Simple Tree Problem How to solve this? My approach : Build rooted tree using two dimensional vector or say in form of linked list containing all the nodes for a parent.
operation — "o" use queue to negate all values. Query — "q" use queue to count all the nodes of subtree having values as non-zero.
My approach was leading to TLE. Can you please share your approach.
why my below solution is leading to WA?
Your code here...
while(scanf("%d%d%d",&N,&W,&K) == 3)
{
N=N+2;
float cost=0.0;
while(N > 0)
{
if(N>=K)
{
cost+=(W*(K-1));
N=N-K;
}
else
{
cost+=(W*N);
N=0;
}
}
float ans=cost/2.0;
printf("%.2f\n",ans);
}