编程介的小学生 2017-09-04 11:33 采纳率: 20.5%
浏览 860
已采纳

Trouble with Election!

Problem Description
Taman and his friends are going to arrange an election for their club. The rule of this election is simple. Every member of the club can cast a single vote for one person. Even one can vote for himself too. If A casts his vote for B and B casts his vote for C then it means that C gets both the votes of A and B. It means if a man casts his vote for someone then the votes he got will also be added to the person he votes for. Now there is a problem if A’s vote goes for B and B’s vote for A. In this case, both of them have the same number of votes and it is a tie! So a tiebreaker will be needed. In this situation, all the votes of A and B and their supporters will be cancelled. If one’s vote goes for another then one is considered as the supporter of another.
Now you are elected as the election commissioner for the election of the club. It is your duty to publish the result of the election. If you find no possible winner or if two or more members have same number of votes then you should declare the situation as “Trouble”, print the name of the winner otherwise. Instead of name, a unique number for each member identifies the members of this club and the number should always be non-negative and less than the total number of members of the club.

Input
There will be multiple test cases. Every test case starts with a single integer N on a line. 0<N<= 100000. N denotes the number of members of the club. N lines following. Each I’th line will be consisting of a single integer J; denoting I’th member casts his vote for J’th member. 0<=I, J<N.

Output
The output for every case consists of a single integer, which denotes that the M’th member is the winner or a single word, “Trouble”, if a unique winner can not be determined. Here quotes are for clarity.

Sample Input
3
1
2
2
4
1
2
0
3
2
1
0
5
1
2
0
2
3
10
7
6
1
8
9
2
7
9
5
4

Sample Output
2
3
Trouble
Trouble
Trouble

  • 写回答

1条回答

  • threenewbee 2017-09-18 21:26
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?