1090.Highest Price in Supply Chain (25)

Source: Internet
Author: User

1090.Highest Price in Supply Chain (25)

pat-al-1090

2017-03-03 DFS and BFS should all be implemented, this time the DFS

/**
 * pat-al-1090
 * 2017-03-03
 * Cpp version
 * author:fenglian_s */
#include <stdio.h>
#include <vector>
#define MAX 100010
using namespace std;
Vector<int> V[max];
int maxDepth =-1, CNT;
void Dfs (int root, int depth)
{
  if (Depth > MaxDepth)
  {
    maxDepth = depth;
    CNT = 1;
  }
  else if (depth = = maxDepth)
    cnt++;
  for (int i = 0;i < V[root].size (); i++)
  {
    dfs (v[root][i], depth+1);
  }
}
int main ()
{
  freopen ("In.txt", "R", stdin);
  int n;
  Double p, R;
  scanf ("%d%lf%lf", &n, &p, &r);
  int root;
  for (int i = 0;i < n;i++)
  {
    int father;
    scanf ("%d", &father);
    if (father! =-1)
      v[father].push_back (i);
    else
      root = i;
  }
  DFS (root, 0);
  for (int i = 0;i < maxdepth;i++)
  {
    P *= (1+r/100);
  }
  printf ("%.2lf%d\n", p, CNT);
  return 0;
}

-fin-

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.