Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Number of trips You are ghveri a map comsistirg of N cities. Each city has a directed path to ariorher sity or it ran be
Number of trips You are ghveri a map comsistirg of N cities. Each city has a directed path to ariorher sity or it ran be to itself (this meams, each city has exactly one attgoirag erige). You are given an array Ar. There is a directed path from city i to Arrii]. where 7iA You have to start from every city and then travel through cities until you reach a city that you have already visited before. $ Task For each city, determine the number of cities you would visit if you start from that city. Note: 1-based indexing is followed in the problem. Example Assumptions - N=3 - Ar=[2,3,1] tpproach Input format Note: This is the input fommat that you must use to provicle custom input. (avallable above the Compile and Test buttons). - The first line contains T denoting the number of test cases. T also specifies the number of times you have to run the solve function on a different set of inputs. - For each test case: - The first line contains a single integer N denoting the number of cities. - The second line contains an array Aly denoting the array containing the destination city for paths fromp each city. Output format For each test case, print N integers according to the shoblemn staitement. Constraints 1T1001N
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started