$head= Array.new(210,-1)
$num=0
class Edge
@v
@w
@next
def init(a,b,c)
@v=a
@w=b
@next=c
end
def output()
print @v
print " "
print @w
print "\n"
end
def getnext()
return @next
end
def getv()
return @v
end
def getw()
return @w
end
end
$e=Array.new(40010,Edge.new)
def add(a,b,c)
$num=$num+1
l = Edge.new
l.init(b,c,$head.at(a))
$e[$num]=l
$head[a]=$num
end
def main
a=gets.split.map(&:to_i)
n=a[0]
m=a[1]
for i in 1..m
a=gets.split.map(&:to_i)
add(a.at(0),a.at(1),a.at(2))
add(a.at(1),a.at(0),a.at(2))
end
Array dis=Array.new(210,210)
dis[1]=0
hd=0
tl=1
Array que=Array.new(40010,0)
que[1]=1
for i in 1..(n-1)
hd+=1
j=$head[que[hd]]
temp=2147483640
temp2=0
while j!=-1 do
if dis[$e.at(j).getv()]>dis[que[hd]]+$e.at(j).getw().to_i()
dis[$e.at(j).getv()]=dis[que[hd]]+$e.at(j).getw().to_i()
if temp>dis[$e.at(j).getv()]
temp=dis[$e.at(j).getv()]
temp2=$e.at(j).getv()
end
end
j=$e.at(j).getnext()
end
tl+=1
que[tl]=temp2
end
for i in 2..n
print dis.at(i)
print "\n"
end
end
main()