#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define fin(ans) cout << (ans) << endl
#define STI(s) atoi(s.c_str())
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    };
};
const ll MOD = 1000000007;
const double EPS = 1e-9;
const int INF = INT_MAX;
const ll LLINF = 1LL << 62;

//頂点fromから頂点toへのコストcostの辺
struct edge
{
    ll from;
    ll to;
    ll cost;
};

class Bellman_Ford
{
public:
    vector<edge> es; //辺
    vector<ll> d;    //d[i]...頂点sから頂点iまでの最短距離
    int V, E;        //Vは頂点数、Eは辺数

    Bellman_Ford(int v, int e)
    {
        V = v;
        E = e;
        d = vector<ll>(v);
    }

    void add(int from, int to, int cost)
    {
        edge ed = {from, to, cost};
        es.push_back(ed);
    }

    //s番目の頂点から各頂点への最短距離を求める
    void shortest_path(int s)
    {
        for (int i = 0; i < V; i++)
        {
            d[i] = INF;
        }
        d[s] = 0;
        int count = 0;
        while (true)
        {
            bool update = false;
            for (int i = 0; i < E; i++)
            {
                edge e = es[i];
                if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost)
                {
                    d[e.to] = d[e.from] + e.cost;
                    update = true;
                }
            }
            count++;
            if (count > 500 * V)
                break;
            if (!update)
                break;
        }
    }
    //trueなら負の閉路が存在する
    bool is_nagative_loop()
    {
        for (int i = 0; i < V; i++)
        {
            d[i] = 0;
        }
        for (int i = 0; i < 2 * V; i++)
        {
            for (int j = 0; j < E; j++)
            {
                edge e = es[j];
                if (d[e.to] > d[e.from] + e.cost)
                {
                    d[e.to] = d[e.from] + e.cost;

                    //n回目にも更新があるなら負の閉路が存在する
                    if (i == V - 1)
                        return true;
                }
            }
        }
        return false;
    }
};

int main(void)
{

    int v, e, r, s, t, d;
    cin >> v >> e >> r;
    ll neg = 0;
    Bellman_Ford bf(v, e);
    rep(i, e)
    {
        cin >> s >> t >> d;
        bf.add(s, t, d);
        neg += min(0, d);
    }
    bf.shortest_path(r);
    rep(i, v)
    {
        if (bf.d[i] < 2 * neg)
        {
            cout <<"NEGATIVE CYCLE" << endl;
            return 0;
        }
    }
    {
        rep(i, v)
        {
            if (INF == bf.d[i])
                cout << "INF" << endl;
            else
                cout << bf.d[i] << endl;
        }
    }
}


Measured memory_bytes: 3228