N city Question

In a state of India every city has been given 1 to 7 stars according to facilities in the city.

So Lets consider N cities(c1 to cn) os that state and every city is given a number 1 to 7 corresponding to the level of cities.Some cities are connected to each other as well.

A person plays very interesting game.He starts from city1 and after visiting some cities out of c1 to cn (he may visit a city multiple times and also he can leave a city also).During the course of journey the person construct a number (call this number S) by appending the rating of the city in the right of already formed number.Initial he start with empty and append rating of c1 as he starts with city c1.

The interesting part is he wants to visits city in a way that the number S formed should be divisible by all of its digits and the sum of all the digits of S should be as less as possible.

Note : Output should be -1 if no solution exists.

Input Specifications :-

1) An Array of size N Corresponding to rating of the cities

2) A 2-D array of size N* N which shows connectivity of the cities.If in this array entry E[i][j] then it means Ci is connected to Cj by graph.

Author: Priya Sharma 4
Login to Answer
Sort By:
My Answer