Infinity = 10000000

def floydwarshall graph, n

  dist = Array.new(n).map{Array.new(n, Infinity)}
  n.times do |u|
    graph[u].each do |edge|
      v = edge[0]
      w = edge[1]
      dist[u][v] = w
    end
    dist[u][u] = 0
  end

  n.times do |k|
    n.times do |u|
      n.times do |v|
        total = dist[u][k] + dist [k][v]
        if total < dist[u][v]
          dist[u][v] = total
        end
      end
    end
  end

  dist
end

MaxNode = 10
graph = Array.new(MaxNode).map{Array.new}
while (numEdge = $stdin.gets.to_i) != 0
  #入力
  #全ての入力を受け取るまで最大町番号は不明
  numCity = -1
  numEdge.times do
    a,b,c = $stdin.gets.chomp.split(" ").map(&:to_i)
    graph[a] << [b, c]
    graph[b] << [a, c]
    numCity = a if numCity < a
    numCity = b if numCity < b
  end
  #街番号はゼロはじまりなので数は＋１
  numCity += 1

  #全対最短経路情報をもとに解答を算出
  dist = floydwarshall(graph, numCity)
  home = -1
  sum = Infinity
  numCity.times do |u|
    next if dist[u][0] == Infinity
    total = 0
    numCity.times do |v|
      unless dist[u][v] == Infinity
        total += dist[u][v]
      end
    end
    if total < sum
      sum = total
      home = u
    end
  end

  printf "%d %d\n", home, sum
end