import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.Scanner; public class Indoorienteering { static int n; static long l; static long[][] dist; static HashMap> firstSet = new HashMap>(); static HashMap> secondSet = new HashMap>(); public static void populateSet(HashSet nums, int pos, HashMap> set, long sum) { if(nums.size() == 0) { long total = sum + dist[pos][0]; if(!set.containsKey(pos)) set.put(pos, new HashSet()); set.get(pos).add(total); } for(int nextPos: new HashSet(nums)) { nums.remove(nextPos); Indoorienteering.populateSet(nums, nextPos, set,sum+dist[pos][nextPos]); nums.add(nextPos); } } public static boolean solvePartition(HashSet first, HashSet second) { /* System.out.println(first.size()); System.out.println(second.size()); System.out.println("FIRST:"); for(Integer i : first) System.out.println(i); System.out.println("SECOND:"); for(Integer i : second) System.out.println(i); */ Indoorienteering.populateSet(first, 0, firstSet, 0); Indoorienteering.populateSet(second, 0, secondSet, 0); /*for(int x: firstSet.keySet()) { System.out.println("POSITION:" + x); for(long pos : firstSet.get(x)) System.out.println(" LEN:" + pos); } System.out.println(); for(int x: secondSet.keySet()) { System.out.println("POSITION:" + x); for(long pos : secondSet.get(x)) System.out.println(" LEN:" + pos); } */ for(int firstBreak : firstSet.keySet()) { for(int secondBreak : secondSet.keySet()) { for(long firstLength: firstSet.get(firstBreak)) { for(long secondLength: secondSet.get(secondBreak)) { if(firstLength + secondLength - dist[0][firstBreak] - dist[0][secondBreak] + dist[firstBreak][secondBreak] == l) { return true; } } } } } return false; } public static HashSet> powerSet(HashSet orig) { HashSet> result = new HashSet>(); result.add(new HashSet()); for (Integer i : orig) { HashSet> temp = new HashSet>(); for(HashSet prev : result) { prev = new HashSet(prev); prev.add(i); temp.add(prev); } result.addAll(temp); } return result; } public static void main(String[] args) { Scanner s = new Scanner(System.in); n = s.nextInt(); l = s.nextLong(); dist = new long[n][n]; for(int i = 0; i < n; i++) for (int j = 0; j < n; j++) dist[i][j] = s.nextLong(); s.close(); HashSet original = new HashSet(); for(int i = 1; i < n; i++) original.add(i); HashSet> power = Indoorienteering.powerSet(original); for(HashSet first : power) { HashSet second = new HashSet(); for(Integer elem: original) if(!first.contains(elem)) second.add(elem); if(Indoorienteering.solvePartition(first, second)) { System.out.println("possible"); return; } } System.out.println("impossible"); } }