using System;
using System.Collections.Generic;

namespace GRL1B{
    public class Program{
        public static void Main(string[] args){
            var sr = new StreamReader();
            //---------------------------------
            var V = sr.Next<int>();
            var E = sr.Next<int>();
            var R = sr.Next<int>();

            var bf = new BellmanFord(V);
            for(var i = 0; i < E; i++){
                bf.AddEdge(sr.Next<int>(), sr.Next<int>(), sr.Next<int>());
            }

            var res = bf.Solve(R);
            if(res == null){
                Console.WriteLine("NEGATIVE CYCLE");
                return;
            }

            Array.ForEach(res, x => Console.WriteLine(x == int.MaxValue ? "INF" : x.ToString()));
            //---------------------------------
        }
    }

    public class BellmanFord{
        public class Edge{
            public int From;
            public int To;
            public int Cost;
        }

        private readonly int _v;
        private readonly  List<Edge> _es;

        public BellmanFord(int v){
            _v = v;
            _es = new List<Edge>();
        }

        public void AddEdge(int from, int to, int cost){
            _es.Add(new Edge{From = from, To = to, Cost = cost});
        }

        public int[] Solve(int start){
            var res = new int[_v];

            for(var i = 0; i < _v; i++) res[i] = int.MaxValue;
            res[start] = 0;

            for(var i = 0; i < _v; i++) {
                var end = true;
                foreach(var e in _es){
                    if(res[e.From] != int.MaxValue && res[e.To] > res[e.From] + e.Cost){
                        res[e.To] = res[e.From] + e.Cost;
                        end = false;
                    }
                }
                if(end) return res;
            }

            return null;
        }
    }

    public class StreamReader{
        private readonly char[] _c = {' '};
        private int _index = -1;
        private string[] _input = new string[0];
        private readonly System.IO.StreamReader _sr = new System.IO.StreamReader(Console.OpenStandardInput());

        public T Next<T>(){
            if(_index == _input.Length - 1){
                _index = -1;
                while(true){
                    string rl = _sr.ReadLine();
                    if(rl == null){
                        if(typeof(T).IsClass) return default(T);
                        return (T)typeof(T).GetField("MinValue").GetValue(null);
                    }
                    if(rl != ""){
                        _input = rl.Split(_c, StringSplitOptions.RemoveEmptyEntries);
                        break;
                    }
                }
            }
            return (T)Convert.ChangeType(_input[++_index], typeof(T), System.Globalization.CultureInfo.InvariantCulture);
        }

        public T[] Next<T>(int x){
            var ret = new T[x];
            for(var i = 0; i < x; ++i) ret[i] = Next<T>();
            return ret;
        }

        public T[][] Next<T>(int y, int x){
            var ret = new T[y][];
            for(var i = 0; i < y; ++i) ret[i] = Next<T>(x);
            return ret;
        }
    }
}

Measured memory_bytes: 9952