ГлавнаяСборникиТурнирыРазделыФорумыУчастникиПечатьПомощьО системе

Сборники > Data Structures > задача:


50876 - He is my cousin

Гость
• Вопросы к жюри (2)

Задачи сборника

• 51062 - Fish Pond II
• 51067 - Jumping frog
• 50840 - Tanker trucks
• 51080 - Deepest Point
• 51079 - Key person - 2
• 50877 - Friendly Queue
• 51021 - Number of Nodes
• 51044 - Number of Trees
• 50876 - He is my cousin
• 50997 - Dynamic Knights
• 50816 - Largest Sum Path
• 50857 - Nine-Stones Game
• 50490 - Across the River
• 50837 - Sum is equal to K
• 51010 - Max Sequential Sum
• 50772 - The Path of a Node
• 50936 - Saving the Soldiers

Обратная связь

Если у вас есть предложения или пожелания по работе Contester, посетите форум сайта www.contester.ru.

Лимит времени 2000/4000/4000/4000 мс. Лимит памяти 65000/65000/65000/65000 Кб.
Question by Ibrahim Mesecan.

He is my cousin

Question: You are given family relationship between n people. A degree of 1 means that they are first degree relatives, like father and son, or brother and sister, etc. A degree of two means the second degree relative: like aunt, uncle, cousin, etc. If 1 is the first degree relative of 2 and if 3 is the first degree relative of 2 and if no other information is provided, 1 is the second degree relative of 3.

Question: Write a program that reads the family relationship of n people. Then, the program finds the min distance between the given people and shows the total distance.

Input specification
You will be first given three numbers:

  • The number of people (n): where 0 ≤ n ≤ 250,
  • The number of family relationships (m) given where 0 ≤ m ≤ 2000,
  • The number of family relationships (k) asked where 0 ≤ k ≤ 100.
The people have the IDs between 1 and n. The following m lines give three numbers: ID of two people and the degree of relationship. The following k lines give two numbers: ID of two people whose relationship is asked. If there are several relationships between two people, use the min degree of relationships. For example, your brother is your uncle's nephew. So, the degree of relationship is 1.

Output specification:
Calculate the total distance of relationships for k pairs of people. If no relationship is defined between two people, do not calculate anything for it.

Note: The image on the right is just for representation. It's not one-to-one related by the example below.

Sample Input I
8 5 4
3 5 1
3 2 2
3 4 1
3 8 2
2 7 1
8 5
4 1
7 3
7 4
Sample Output I
10

Explanation: There are 8 people and 6 family relationships are given. Then 4 relationships are asked. According to the given relationship scheme:

Person 1Person 2Degree of Rel.
853
41Unknown
733
744
So, the total minimum relationship is 10.



Для отправки решений необходимо выполнить вход.

www.contester.ru