Company: infoedge_18oct
Difficulty: medium
Count Of Shops Problem Description A market has N shops, numbered from 0 to N - 1 . Exactly one one-way road leaves each shop. You are given a 0-indexed array paths of length N , where paths[i] is the shop that the road leaving shop i arrives at. A walk is defined as follows: pick a starting shop s , then repeatedly move along the road leaving the shop you are currently at. The walk stops at the moment you arrive at a shop you have already visited during this same walk. For every shop i , determine how many distinct shops the walk starting at shop i visits (the starting shop itself is counted). Return the array count , where count[i] is that number for shop i . Note: a road may lead back to the shop it starts from, that is paths[i] == i is allowed. Input Format The first line contains a single integer N — the number of shops. The second line contains N space-separated integers paths[0] paths[1] ... paths[N-1] . Output Format Print N space-separated integers on a single line: count[0] c