Back to problems

Count Paths Visiting Exactly One Shop of Each Type

Algorithm · OpenAI · Medium

Problem A town has four kinds of shops, identified by integer codes from 0 to 3: 0: bookshop 1: school supplies shop 2: sports store 3: stationery store The array shops gives the kind of each shop, so shops[i] is the kind of shop i. The array roads lists the roads, where each entry [u, v] is a two-way road joining shop u and shop v. Count the valid paths. A valid path is an ordered sequence of exactly four shop indices that meets all of these conditions: The four shops are…

Loading the rest of the question…