Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.


Limits 4s, 512 MB

Lukáš really likes orienteering, a sport that requires locating control points in rough terrain. To entertain the NWERC participants Lukáš wants to organize an orienteering race.However, it would be too harsh for the participants to be outdoors in this cold Swedish November weather, so he decided to jump on the new trend of indoor races, and set the race inside the B building of Linköping University.

Lukáš has already decided on the locations of the control points. He has also decided on the exact length of the race,so the only thing remaining is to decide in which order the control points should be visited such that the length of the total race is as he wishes. Because this is not always possible,he asks you to write a program to help him.

Note from the organizer: the NWERC indoorienteering race for this year has been cancelled since we neglected to apply for an orienteering permit in time from the university administration. (We still need you to solve the problem so that we can organize it for next year.)


The input consists of:

  • one line with two integers n (2 ≤ n ≤ 14) and L (1 ≤ L ≤ 1015), the number of control points and the desired length of the race, respectively;

  • n lines with n integers each. The j-th integer on the i-th line, dij, denotes the distance between control point i and j (1 ≤ dij ≤ L for i ≠ j, and dii = 0). For all 1≤ i, j, k ≤ N it is the case that dij = dji and dij ≤ dik + dkj.


Output one line with “possible” if it is possible to visit all control points once in some order and directly return to the first one such that the total distance is exactly L, and “impossible”otherwise.


4 10
0 3 2 1
3 0 1 3
2 1 0 2
1 3 2 0
3 5
0 1 2
1 0 3
2 3 0

This NWERC 2014 problem is licensed under the CC BY-SA 3.0 license.

You can find the original problem on the NWERC website.



    0% Solution Ratio


    Login to submit