/* package whatever; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ class Ideone { public static void main (String[] args) throws java.lang.Exception { // your code goes here BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] lines = br.readLine().split(" "); int n = Integer.parseInt(lines[0]); int m = Integer.parseInt(lines[1]); int s = Integer.parseInt(lines[2]); int g = Integer.parseInt(lines[3]); ArrayList stations = new ArrayList(); for(int i=0;i queue = new PriorityQueue(200,(a,b)->a.compare(b)); queue.add(stations.get(s)); while(queue.size()!=0){ Station sta = queue.poll(); for(Route route:sta.next){ Station clone = sta.clone(); clone.min_route.add(route.station.no); clone.min_cost += route.cost; if(clone.compare(route.station) < 0){ route.station.min_route = new ArrayList(clone.min_route); route.station.min_cost = clone.min_cost; queue.add(route.station); } } } System.out.println(stations.get(g).toString()); } public static class Station{ public ArrayList next = new ArrayList(); public int no; public int min_cost = Integer.MAX_VALUE; public ArrayList min_route = new ArrayList(); public Station(int no){ this.no = no; } public void addNext(Station station,int cost){ next.add(new Route(station,cost)); } public int compare(Station target){ if(this.min_cost != target.min_cost){ return this.min_cost - target.min_cost; }else{ int n = Math.min(this.min_route.size(),target.min_route.size()); for(int i=0;i(this.min_route); new_obj.next = this.next; //ディープコピーしなくてもOK return new_obj; } public String toString(){ StringBuilder sb = new StringBuilder(); for(int route:min_route){ if(sb.length() != 0){ sb.append(" "); } sb.append(route); } return sb.toString(); } } public static class Route{ public Station station; public int cost; public Route(Station station,int cost){ this.station = station; this.cost = cost; } } }