• [C] Chaotic Alice's Puppets

  • 时间限制: 1000 ms 内存限制: 65535 K
  • 问题描述
  • Alice Margatroid (アリス·マーガトロイド) can control puppets. What's more, she can control her pupet to control other pupets.
    The puppets she controls directly called the first-level puppet. And the puppets which are controlled by the first-level puppets are called the second-level puppet. So as the third, fourth and the ith-level.
    One day she wants to do an experiment - reverse the relation between a controller and a controlled puppet.
    but the rule is : one controlled poppet only can have one controller.
    what you have to do is that tell Alice how to change the relation can she get the max-level puppet. (After reversal, Alice can be a puppet as well.)
    Before reversal, the puppets controlled by Alice are the first level.
    After reversal, the puppets controlled by the Chief puppet are the first level.
  • 输入
  • This problem has several cases. Input until EOF.
    The first line of each case is an integer N, indicates the number of puppets. (0 < N < 10000)
    Then follow N lines. Each line contains two strings, indecates the puppet's name and its controllor. I'm not sure that the controllor's name has appeared as a puppet's name before.
    Every name is no longer than 20.
  • 输出
  • For each case, you should output the difference max-level between after and between reversal. Of cause, if the original state is the maximum, you can keep it without doing anyting.
  • 样例输入
  • 3
    Peps Blahblah
    Blahblah Alice
    Grugru Alice
    
  • 样例输出
  • 1
  • 提示
  • You can change the relation between Alice and Grugru, then the max-level is 3.
    You can either change the ralation between Alice and Blahblah, and change the ralation between Blahblah and
    Peps, then the max-level is 3 too.
    And in the original state, the max-level is 2.
    So the difference is 1.
    
  • 来源
  • XadillaX
  • 操作

显示春菜