using System; using System.Collections; using System.Collections.Generic; class TEST{ static void Main(){ Sol mySol =new Sol(); mySol.Solve(); } } class Sol{ public void Solve(){ int[] prev=new int[N]; for(int i=0;i SH =new SkewHeap(); Tot[S]=0; SH.Push(new Pair(S,0)); bool[] used=new bool[N]; while(SH.Count>0){ Pair p = SH.Top; SH.Pop(); if(used[p.Pos])continue; used[p.Pos]=true; foreach (Pair e in E[p.Pos]) { if (Tot[e.Pos] > p.Cost + e.Cost) { Tot[e.Pos] = p.Cost + e.Cost; prev[e.Pos]=p.Pos; SH.Push(new Pair(e.Pos, Tot[e.Pos])); } } } List L=new List(); int now=G; while(now!=S){ L.Add(now); now=prev[now]; } L.Add(now); var AA=L.ToArray(); Array.Reverse(AA); Console.WriteLine(String.Join(" ",AA)); } int N,M; int S,G; List[] E; public Sol(){ var d=ria(); N=d[0];M=d[1];S=d[2];G=d[3]; E=new List[N]; for(int i=0;i(); for(int i=0;ix.Pos>y.Pos?1:x.Posint.Parse(e));} static long[] rla(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>long.Parse(e));} static double[] rda(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>double.Parse(e));} } class Pair : IComparable { public int Pos; public int Cost; public Pair(int p, int c) { Pos = p; Cost = c; } public int CompareTo(Pair t) { //return this.Cost > t.Cost ? -1 : this.Cost < t.Cost ? 1 : 0; return this.Cost > t.Cost ? 1 : this.Cost < t.Cost ? -1 : 0; } } class SkewHeap where T:IComparable{ public int Count{ get{return cnt;} private set{cnt=value;} } public SkewHeap(){ root=null; this.Count=0; } public void Push(T v){ NodeSH p=new NodeSH(v); root=NodeSH.Meld(root,p); this.Count++; } public void Pop(){ if(root==null)return; root=NodeSH.Meld(root.L,root.R); this.Count--; } public T Top{ get{return root.Val;} } int cnt; NodeSH root; class NodeSH where S : IComparable { public NodeSH L, R; public S Val; public NodeSH(S v){ Val = v; L = null; R = null; } public static NodeSH Meld(NodeSH a, NodeSH b){ if(a == null)return b; if (b == null) return a; if (a.Val.CompareTo(b.Val) > 0) swap(ref a, ref b); a.R = Meld(a.R, b); swap(ref a.L, ref a.R); return a; } static void swap(ref U x, ref U y) { U t = x; x = y; y = t; } } }