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

Other questions on the subject: Computers and Technology

image
Computers and Technology, 21.06.2019 16:00, oranzajimenez
Create a logic array qualifyingindex with true for any location where the runner is male with a running time less than 8.2. row array runnergenders indicate if a runner if male (m) or female ( f. row array runnertimes indicates the corresponding runner's time.
Answers: 1
image
Computers and Technology, 24.06.2019 12:00, yagalneedshelp8338
Match the function to its purpose. fast worth 50pts.
Answers: 1
image
Computers and Technology, 24.06.2019 15:30, lizziesuks
What is the function of compilers and interpreters? how does a compiler differ from an interpreter?
Answers: 2
image
Computers and Technology, 24.06.2019 22:00, ivethzurita0425
What is a number system, and what is the total number of digits used in this system called? a number system is a system that uses different (options: a) numbers b) symbols c) codes d) digits e) alphabets) to represent different numbers. the total number of digits used in a number system is known as its (options: 1) processor 2) converter 3) radix 4) least significant digit 5) most significant digit)
Answers: 1
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 in other subjects: