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 06:00
Which of the following is a way that advancements in technology improve humans' ability to measure air quality and protect human health? a. air quality data gathered by new instruments can be used to reduce exposure to pollutants. b. new technologies enable natural and human-made pollution sources to be located and monitored. c. air quality data gathered by new instruments can be used to predict trends in pollution over time. d. new technologies allow governments to make informed decisions about the regulation of pollution. (choose more than one)
Answers: 2
question
Computers and Technology, 22.06.2019 17:00
Which of the following is not contained on the slide show toolbar? a. next button b. slide button c. close button d. pen too
Answers: 2
question
Computers and Technology, 24.06.2019 04:30
Fall protection, confined space entry procedures, controlled noise levels, and protection from chemical hazards are some of the things that contribute to a safe what
Answers: 1
question
Computers and Technology, 24.06.2019 10:10
Which view in a presentation program displays a split window showing the slide in the upper half and a blank space in the lower half?
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
question
Mathematics, 06.04.2020 00:04
question
Mathematics, 06.04.2020 00:04
question
Computers and Technology, 06.04.2020 00:05
question
Mathematics, 06.04.2020 00:06
question
Mathematics, 06.04.2020 00:06
question
History, 06.04.2020 00:06
question
History, 06.04.2020 00:06
Questions on the website: 13722361