Q2: Ginormous Campus The campus is pretty big. There are n buildings scattered around it, numbered from 0 to n-1. These buildings are so far away from each other that the only way to get from one to another is to take a campus bus. There are m campus bus routes. The i-th one (0 <= i < m) takes you from building u_i to building v_i (but not the other way around). These buses run very frequently. Professor Zingaro is deciding where to hold his CS lectures. He believes a building x is accessible from a building y if you can get from y to x taking at most two buses. For his students’ convenience, he wants to hold his lectures in the most accessible building. Help him out by telling him how many buildings the most accessible building is accessible from. In addition, list all buildings that are the most accessible. Input The first line of the input contains two space-separated integers n and m, denoting the number of buildings and bus routes, respectively. m lines follow. The i-th one contains two space-separated integers u_i and v_i, as described above. Output The output should consist of two lines. The first line should contain a single integer x denoting the number of buildings that the most accessible building is accessible from The second line should contain a list of up to n integers, denoting the list of buildings that are accessible from exactly x buildings. List the buildings in increasing order. Constraints 1 <= n <= 10000 0 <= u_i, v_i < n u_i != v_i (i.e. no route connects a building to itself) For any building, there are at most 70 bus routes that end at it. There are no additional constraints on m or the routes. Time Limit Your program must finish running on any valid input within 9 seconds. Sample Input 1 6 5 0 1 1 2 2 3 3 4 4 5 Sample Output 1 3 2 3 4 5 Sample 1 Explanation The first line indicates that there are 6 buildings and 5 bus routes. The bus routes are described in the next 5 lines. For instance, the second route takes you from building 1 to building 2. Building 0 is only accessible from itself. Building 1 is accessible from building 0 and itself. The remaining buildings are all accessible from 3 buildings, including themselves. Sample Input 2 6 8 0 1 2 1 1 3 4 3 3 5 0 1 3 0 1 0 Sample Output 2 5 0 3
Q2: Ginormous Campus
The campus is pretty big. There are n buildings scattered around it, numbered from 0 to n-1. These buildings are so far away from each other that the only way to get from one to another is to take a campus bus.
There are m campus bus routes. The i-th one (0 <= i < m) takes you from building u_i to building v_i (but not the other way around). These buses run very frequently.
Professor Zingaro is deciding where to hold his CS lectures. He believes a building x is accessible from a building y if you can get from y to x taking at most two buses. For his students’ convenience, he wants to hold his lectures in the most accessible building. Help him out by telling him how many buildings the most accessible building is accessible from. In addition, list all buildings that are the most accessible.
Input
The first line of the input contains two space-separated integers n and m, denoting the number of buildings and bus routes, respectively.
m lines follow. The i-th one contains two space-separated integers u_i and v_i, as described above.
Output
The output should consist of two lines. The first line should contain a single integer x denoting the number of buildings that the most accessible building is accessible from
The second line should contain a list of up to n integers, denoting the list of buildings that are accessible from exactly x buildings. List the buildings in increasing order.
Constraints
- 1 <= n <= 10000
- 0 <= u_i, v_i < n
- u_i != v_i (i.e. no route connects a building to itself)
- For any building, there are at most 70 bus routes that end at it.
- There are no additional constraints on m or the routes.
Time Limit
Your program must finish running on any valid input within 9 seconds.
Sample Input 1
6 5
0 1
1 2
2 3
3 4
4 5
Sample Output 1
3
2 3 4 5
Sample 1 Explanation
- The first line indicates that there are 6 buildings and 5 bus routes.
- The bus routes are described in the next 5 lines. For instance, the second route takes you from building 1 to building 2.
- Building 0 is only accessible from itself. Building 1 is accessible from building 0 and itself. The remaining buildings are all accessible from 3 buildings, including themselves.
Sample Input 2
6 8
0 1
2 1
1 3
4 3
3 5
0 1
3 0
1 0
Sample Output 2
5
0 3
Step by step
Solved in 4 steps with 5 images
thank you for your anser but I wanted an answer in python language sorry for not clarifying.