output_description: For each query, print the distance. The output values should be in a decimal
  fraction with an error less than 0.00000001.
input_description: The entire input looks like:
  
      
      
      q (the number of queries)
      1st query
      2nd query
      ...
      qth query
      
  
  Each query consists of integer coordinates of end points of s1 and s2 in the
  following format:
  
      
      
      xp0 yp0 xp1 yp1 xp2 yp2 xp3 yp3
attempt: # !/usr/bin/env python
  # -*- coding: utf-8 -*-
  
  """
  input:
  4 5 1
  0 1 2
  0 2 3
  1 2 -5
  1 3 1
  2 3 2
  
  output:
  INF
  0
  -5
  -3
  
  OR
  input:
  4 6 0
  0 1 2
  0 2 3
  1 2 -5
  1 3 1
  2 3 2
  3 1 0
  
  output:
  NEGATIVE CYCLE
  """
  
  import sys
  from math import isinf
  
  
  def generate_adj_table(_v_info):
      for each in _v_info:
          source, target, cost = map(int, each)
          init_adj_table[source][target] = cost
      return init_adj_table
  
  
  def bellman_ford():
      distance[root] = 0
  
      for j in range(vertices - 1):
          for current, current_info in enumerate(adj_table):
              for adj, cost in current_info.items():
                  if distance[current] + cost < distance[adj]:
                      distance[adj] = distance[current] + cost
  
      for current, current_info in enumerate(adj_table):
          for adj, cost in current_info.items():
              if distance[current] + cost < distance[adj]:
                  print("NEGATIVE CYCLE")
                  return list()
  
      return distance
  
  
  if __name__ == "__main__":
      _input = sys.stdin.readlines()
      vertices, edges, root = map(int, _input[0].split())
      v_info = map(lambda x: x.split(), _input[1:])
  
      distance = [float("inf")] * vertices
      init_adj_table = tuple(dict() for _ in range(vertices))
  
      adj_table = generate_adj_table(v_info)
  
      res = bellman_ford()
      for ele in res:
          if isinf(ele):
              print("INF")
          else:
              print(ele)
  
problem_description: Distance
  
    
  
  For given two segments s1 and s2, print the distance between them.
  
  s1 is formed by end points p0 and p1, and s2 is formed by end points p2 and
  p3.
samples: [{"input": "0 0 1 0 0 1 1 1\n    0 0 1 0 2 1 1 2\n    -1 0 1 0 0 1 0 -1", "output": ".0000000000\n    1.4142135624\n    0.0000000000"}]