subject

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

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 00:40
If you arrive at the same time as another user straight across from you yield if a. they flash your headlights at you b. you can’t see their turn signals c. you’re going street and they’re running d. you’re turning they’re going straight plz
Answers: 1
question
Computers and Technology, 22.06.2019 17:30
Ou listened to a song on your computer. did you use hardware or software?
Answers: 2
question
Computers and Technology, 22.06.2019 23:20
How can you tell if someone sent you a text message to your email instead of a email
Answers: 1
question
Computers and Technology, 23.06.2019 01:50
Create a class named majors that includes an enumeration for the six majors offered by a college as follows: acc, chem, cis, eng, his, phys. display the enumeration values for the user, then prompt the user to enter a major. display the college division in which the major falls. acc and cis are in the business division, chem and phys are in the science division, and eng and his are in the humanities division. save the file as majors.java.
Answers: 2
You know the right answer?
You are given a map of the Roman Empire. There are N + 1 cities (numbered from 0 to N) and N directe...
Questions
question
Mathematics, 09.01.2021 01:40
question
Mathematics, 09.01.2021 01:40