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

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

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

Expert Solution
steps

Step by step

Solved in 4 steps with 5 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

thank you for your anser but I wanted an answer in python language sorry for not clarifying. 

Solution
Bartleby Expert
SEE SOLUTION
Follow-up Question

is there any chance this can be in python? 

 

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Topological Sort
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY