#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define repi(i, a, b) for(int i=(a); i>(b); i--)
#define db(x) (cerr << #x << ": " << (x) << '\n')
#define sync ios_base::sync_with_stdio(false), cin.tie(NULL)
#define cps CLOCKS_PER_SEC
#define tests(t) int t; cin >> t; while(t--)
#define iceil(n, x) (((n) + (x) - 1) / (x))
#define ll long long
#define gcd __gcd
#define eb emplace_back
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define sz size()
#define all(v) (v).begin(), (v).end()
#define uni(v) sort(all(v)), (v).erase(unique(all(v)), (v).end())
#define pii pair<int, int>
#define vi vector<int>
#define vpii vector<pii>
#define vvi vector<vi>
#define fi first
#define se second
#define mt make_tuple
#define pqueue priority_queue
#define bitcount(x) __builtin_popcount(x)
#define PI acos(-1.0)
#define EPS 1e-9
#define mod 998244353
using namespace std;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
template<typename T1, typename T2>
ostream& operator << (ostream& os, const pair<T1, T2>& p) { return os << '(' << p.fi << ", " << p.se << ')'; }
template<typename T>
void printv(const T& v) { for(auto i : v) cerr << i << ' '; cerr << '\n'; }
template<typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using maxpq = priority_queue<T>;
//All indexing is 0-based
using namespace __gnu_pbds;
template<class key, class cmp = std::less<key>>
using ordered_set = tree<key, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
//methods: find_by_order(k); & order_of_key(k);
//To make it an ordered_multiset, use pairs of (value, time_of_insertion)
//to distinguish values which are similar
template<class key, class value, class cmp = std::less<key>>
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;
//Returns no. of values x for which ceil(n / x) == y (y must be > 1).
inline ll CC(ll n, ll y) { return iceil(n, y-1) - iceil(n, y); }
//Returns no. of values x for which floor(n / x) == y
inline ll FF(ll n, ll y) { return n / y - n / (y+1); }
//a and b are assumed to be taken modulo p
inline int add(int a, int b, int p = mod){ int c = a + b; if(c >= p) c -= p; return c; }
inline int sub(int a, int b, int p = mod){ int c = a - b; if(c < 0) c += p; return c; }
inline int mul(int a, int b, int p = mod){ return (a * 1ll * b) % p; }
#define N 505
#define int ll
// #define trace(...) 42
vector<pair<int, int>> adj[N];
int n, d[N];
const int inf = 1e9;
//O(V*E)
//Returns false if there exists a -ve weight cycle; true otherwise.
//Stores shortest dist from src to i in d[i];
bool BellmanFord() {
for(int step = 0; step < n-1; step++) {
for(int i = 0; i < n; i++) {
for(auto p : adj[i]) {
int j = p.first, w = p.second;
if(d[j] > d[i] + w) {
d[j] = d[i] + w;
}
}
}
}
for(int i = 0; i < n; i++) {
for(auto p : adj[i]) {
int j = p.first, w = p.second;
if(d[j] > d[i] + w) return 0;
}
}
return 1;
}
main()
{
#ifndef ONLINE_JUDGE
freopen("/home/tarun/Desktop/input.txt", "r", stdin);
// freopen("/home/tarun/Desktop/output.txt", "w", stdout);
#endif
sync;
clock_t clk = clock();
cerr << "I will return...\n";
int m; cin >> n >> m;
rep(i, 0, m) {
int u, v, w; cin >> u >> v >> w;
--u, --v;
adj[u].pb({v, w});
}
if(!BellmanFord()) {
cout << "NO\n"; return 0;
}
cout << "YES\n";
for(int i = 0; i < n; i++) {
cout << d[i] << " \n"[i == n-1];
}
cerr << "...don't you ever hang your head.\n";
cerr << "Time (in ms): " << (double)(clock() - clk) * 1000.0 / cps << '\n';
}
//Compile using:
//g++ -o filename.exe --std=c++11 filename.cpp
//Use -D CP for defining a macro CP in the local environment
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KI2luY2x1ZGU8ZX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QsIHcgPSBwLnNlY29uZDsKICAgICAgICAgICAgICAgIGlmKGRbal0gPiBkW2ldICsgdykgewogICAgICAgICAgICAgICAgICAgIGRbal0gPSBkW2ldICsgdzsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KCiAgICBmb3IoaW50IGkgPSAwOyBpIDwgbjsgaSsrKSB7CiAgICAgICAgZm9yKGF1dG8gcCA6IGFkaltpXSkgewogICAgICAgICAgICBpbnQgaiA9IHAuZmlyc3QsIHcgPSBwLnNlY29uZDsKICAgICAgICAgICAgaWYoZFtqXSA+IGRbaV0gKyB3KSByZXR1cm4gMDsKICAgICAgICB9CiAgICB9CiAgICByZXR1cm4gMTsKfQoKbWFpbigpCnsgICAKICAgICNpZm5kZWYgT05MSU5FX0pVREdFCiAgICAgICAgZnJlb3BlbigiL2hvbWUvdGFydW4vRGVza3RvcC9pbnB1dC50eHQiLCAiciIsIHN0ZGluKTsKICAgICAvLyBmcmVvcGVuKCIvaG9tZS90YXJ1bi9EZXNrdG9wL291dHB1dC50eHQiLCAidyIsIHN0ZG91dCk7CiAgICAjZW5kaWYKICAgIHN5bmM7CiAgICBjbG9ja190IGNsayA9IGNsb2NrKCk7CiAgICBjZXJyIDw8ICJJIHdpbGwgcmV0dXJuLi4uXG4iOwoKICAgIGludCBtOyBjaW4gPj4gbiA+PiBtOwoKICAgIHJlcChpLCAwLCBtKSB7CiAgICAgICAgaW50IHUsIHYsIHc7IGNpbiA+PiB1ID4+IHYgPj4gdzsKICAgICAgICAtLXUsIC0tdjsKICAgICAgICBhZGpbdV0ucGIoe3YsIHd9KTsKICAgIH0KCiAgICBpZighQmVsbG1hbkZvcmQoKSkgewogICAgICAgIGNvdXQgPDwgIk5PXG4iOyByZXR1cm4gMDsKICAgIH0KCiAgICBjb3V0IDw8ICJZRVNcbiI7CiAgICBmb3IoaW50IGkgPSAwOyBpIDwgbjsgaSsrKSB7CiAgICAgICAgY291dCA8PCBkW2ldIDw8IC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