|시간 제한||메모리 제한||제출||정답||맞힌 사람||정답 비율|
|1 초||128 MB||5||3||3||60.000%|
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:
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
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.
Your program will read in six possible commands, with the action to be performed by your program outlined below. You may assume that x and y are integers, with x ≠ y, x ≥ 1, y ≥ 1, x < 50 and y < 50. You may also assume that instructions (
q) occur one per line and parameters (zero, one or two integers) occur one per line.
ix y – make person x and person y friends. If they are already friends, no change needs to be made. If either x or y is a new person, add them.
dx y – delete the friendship between person x and person y.
nx – output the number of friends that person x has.
fx – output the number of “friends of friends” that person x has. Notice that x and direct friends of x are not counted as “friends of friends.”
sx y – output the degree of separation between x and y. If there is no path from x to y, output Not connected.
q– quit the program.
i 20 10 i 20 9 n 20 f 20 s 20 6 q
2 3 4