Degrees of Separation | 프로그래밍의 벗 PivotOJ
PivotOJ

Degrees of Separation

시간 제한: 1000ms메모리 제한: 128MB출처: CCC 2009 SeniorBOJ 6814
이 문제는 본문 이미지 일부가 표시되지 않습니다. 텍스트만으로 풀이가 어려울 수 있습니다.

문제

The main socializing tool for students today is Facebook. There are many interesting computational questions connected to Facebook, such as the “degree of separation” between two people.

For example, in the diagram below, there are many different paths between Abby and Alberto. Some of these paths are:

  • Abby → Zoey → Alberto
  • Abby → Natalie → Zoey → Alberto
  • Abby → George → Ali → Kara → Richardo → Jeff → Alberto

The shortest path between Abby and Alberto has two steps (Abby → Zoey, and Zoey → Alberto), so we say the degree of separation is 2. Additionally, Alberto would be a friend of a friend of Abby

[이미지 1]

You can assume an initial configuration of who is friends with who as outlined in the diagram above. You will need to store these relationships in your program. These relationships can change though, and your program needs to handle these changes. In particular, friendships can begin, possibly with new people. Friendships can end. You should be able to find friends of friends and determine the degree of separation between two people.

예제

예제 1

입력
i 20 10
i 20 9
n 20
f 20
s 20 6
q
출력
2
3
4
코드를 제출하려면 로그인하세요.