Rating changes for last rounds are temporarily rolled back. They will be returned soon. ×

loverBoUy's blog

By loverBoUy, history, 17 months ago, In English

In today's kickstart C problem of Round H, my approach was:

a) IN one dfs func, find the number of nodes in the subtree which is strictly lesser than the node. b) in anohter dfs func, find the number of nodes which are strictly greater than the node parent and if a[node]>a[parent] add answer of parent into node. c)combine both and find ans;

code:

Your code here...

void dfs(int node)
{

     vis[node] = true;

     for (auto it : g[node])
     {
          if (vis[it] == false)
          {
               dfs(it);
               if (a[it] < a[node])
                    niche[node] += niche[it] + 1;
          }
     }
     return;
}
void dfs2(int node, int par)
{
     vis[node] = true;
     if (par != -1)
     {
          if (a[node] > a[par])
          {
               upar[node] = upar[par] + 1;

               upar[node] += niche[par];
          }
     }

     for (auto it : g[node])
     {
          if (vis[it] == false)
          {
               dfs2(it, node);
          }
     }
     return;
}
// in main function 
 for (int i = 0; i < n; i++)
     {
          if (ans < upar[i] + niche[i] + 1)
          {
               ans = upar[i] + niche[i] + 1;
               
          }
     }

why is this wrong?

  • Vote: I like it
  • -13
  • Vote: I do not like it