Computers and Technology

You are given a map of the Roman Empire. There are N + 1 cities (numbered from 0 to N) and N directed roads between them. The road network is connected; that is, ignoring the directions of roads, there is a route between each pair of cities. The capital of the Roman Empire is Rome. We know that all roads lead to Rome. This means that there is a route from each city to Rome. Your task is to find Rome on the map, or decide that it is not there. The roads are described by two arrays A and B of N integers each. For each integer K (0 <= K < N), there exists a road from city A[K] to city B[K]. Write a function: function solution(A, B); that, given two arrays A and B, returns the number of the city which is Rome (the city that can be reached from all other cities). If no such city exists, your function should return -1. Examples: 1. Given A = [1,2,3] and B = [0,0,0], the function should return 0. Rome has the number 0 on the map. 2. Given A = [0,1,2,4,5] and B = [2,3,3,3,2], the function should return 3. Rome has the number 3 on the map. From cities 1,2 and 4, there is a direct road to city 3. From cities 0 and 5, the roads to city 3 go through city 2.3. Given A = [2,3,3,4] and B = [1,1,0,0], the function should return -1. There is no Rome on the map. Write an efficient algorithm for the following assumptions: • N is an integer within the range [1...200,000]; • each element of arrays A, B is an integer within the range [0...N]; • the road network is connected


You are given a map of the Roman Empire. There are N + 1 cities (numbered from 0 to N) and N direct
You are given a map of the Roman Empire. There are N + 1 cities (numbered from 0 to N) and N direct
You are given a map of the Roman Empire. There are N + 1 cities (numbered from 0 to N) and N direct

answer
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 22:50, cheyennecarrillo14
Which is the best minecraft server? a. mineplex b. worldonecraft c. 9b9t d. 2b2t
Answers: 2
image
Computers and Technology, 23.06.2019 07:10, anika420
If you want to import a picture into a dtp application, what must you do first? draw an image frame. import text. open the folder containing the file. select get image… from the windows menu.
Answers: 2
image
Computers and Technology, 24.06.2019 18:30, HavenShort3075
These factors limit the ability to attach files to e-mail messages. location of sender recipient's ability to open file size of file type of operating system used
Answers: 1
image
Computers and Technology, 24.06.2019 18:30, gucc4836
In what way is your social media footprint related to your digital id
Answers: 1
Do you know the correct answer?
You are given a map of the Roman Empire. There are N + 1 cities (numbered from 0 to N) and N directe...

Questions in other subjects:

Konu
Mathematics, 07.11.2021 09:40
Konu
Mathematics, 07.11.2021 09:40