output_description: For each vertex, print its ID and the distance separated by a space character
  in a line respectively. Print in order of vertex IDs.
input_description: In the first line, an integer $n$ denoting the number of vertices in $G$ is
  given. In the following $n$ lines, adjacency lists for each vertex $u$ are
  respectively given in the following format:
  
  $u$ $k$ $v_1$ $c_1$ $v_2$ $c_2$ ... $v_k$ $c_k$
  
  Vertices in $G$ are named with IDs $0, 1, ..., n-1$. $u$ is ID of the target
  vertex and $k$ denotes its degree. $v_i (i = 1, 2, ... k)$ denote IDs of
  vertices adjacent to $u$ and $c_i$ denotes the weight of a directed edge
  connecting $u$ and $v_i$ (from $u$ to $v_i$).
attempt: import sys
  import heapq
  
  input = sys.stdin.readline
  INF = 2 << 28
  
  
  def dijkstra(G, start, n):  # グラフ,初期頂点,頂点数
  
      dist = [INF] * n
      dist[start] = 0
      used = [False] * n
      used[0] = True
      q = []
  
      for v in G[start]:
          heapq.heappush(q, v)
  
      while len(q) > 0:
          now = heapq.heappop(q)
          if used[now[1]]:
              continue
          v = now[1]
          dist[v] = now[0]
          used[v] = True
  
          for e in G[v]:
              if not used[e[1]]:
                  heapq.heappush(q, (e[0] + dist[v], e[1]))
  
      return dist
  
  
  N = int(input().rstrip())
  g = [[] for _ in range(N)]
  for _ in range(N):
      u, k, *c = map(int, input().split())
      for j in range(0, k * 2, 2):
          g[u].append((c[j + 1], c[j]))
  
  ans = dijkstra(g, 0, N)
  for i, x in enumerate(ans):
      print(i, x)
  
problem_description: Single Source Shortest Path
  
  For a given weighted graph $G = (V, E)$, find the shortest path from a source
  to each vertex. For each vertex $u$, print the total weight of edges on the
  shortest path from vertex $0$ to $u$.
samples: [{"input": "5\n    0 3 2 3 3 1 1 2\n    1 2 0 2 3 4\n    2 3 0 3 3 1 4 1\n    3 4 2 1 0 1 1 4 4 3\n    4 2 2 1 3 3", "output": "0 0\n    1 2\n    2 2\n    3 1\n    4 3"}]