INF = 9999999

while (n = gets.to_i) != 0
  a,b,c = n.times.map{gets.split.map(&:to_i)}.transpose
  vs = 0
  for i in 0..(n-1)
    vs = [vs, a[i], b[i]].max
  end
  nds = Array.new(vs+1).map{Array.new(0)}
  for i in 0..(n-1)
    nds[a[i]].push([b[i], c[i]])
    nds[b[i]].push([a[i], c[i]])
  end
  
  dist = Array.new(vs+1).map{Array.new(vs+1, INF)}
  for i in 0..(n-1)
    dist[a[i]][b[i]] = c[i]
    dist[b[i]][a[i]] = c[i]
  end
  for id in 0..vs
    dist[id][id] = 0
  end
  
  for k in 0..vs
    for i in 0..vs
      for j in 0..vs
        if dist[i][j] > dist[i][k]+dist[k][j]
          dist[i][j] = dist[i][k]+dist[k][j]
        end
      end
    end
  end
  
  sum = Array.new(vs+1, 0)
  for i in 0..vs
    for j in 0..vs
      sum[i] += dist[i][j]
    end
  end
  
  anssum = INF
  minid = 0
  for i in 0..vs
    if anssum > sum[i]
      anssum = sum[i]
      minid = i
    end
  end
  puts "#{minid} #{anssum}"
end
