#include <bits/stdc++.h>
#define range(i, l, r) for(int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

vec<lint> topological_order;

bool dfs(lint node, const vec<vec<lint>>& adj, vec<bool>& visited, vec<bool>& done) {
    for (const lint neighbor : adj.at(node)) {
        if (!visited.at(neighbor)) {
            visited.at(neighbor) = true;
            if (!dfs(neighbor, adj, visited, done)) return false;
        }
        else if (!done.at(neighbor)) return false;
    }
    topological_order.emplace_back(node);
    done.at(node) = true;
    return true;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    lint N, M;
    cin >> N >> M;
    vec<vec<lint>> adj(N, vec<lint>());
    map<plint, lint> w;
    range(i, 0, M) {
        lint L, R, D;
        cin >> L >> R >> D;
        L--; R--;
        adj.at(L).emplace_back(R);
        w[{L, R}] = D;
    }
    vec<bool> visited(N, false);
    vec<bool> done(N, false);
    range(node, 0, N) {
        if (!visited.at(node)) {
            visited.at(node) = true;
            // if a cycle exists, there must be a contradiction.
            if (!dfs(node, adj, visited, done)) {
                cout << "No" << "\n";
                return 0;
            }
        }
    }
    reverse(topological_order.begin(), topological_order.end());
    assert(topological_order.size() == N);
    vec<lint> dist(N, 0);
    for (const lint node : topological_order) {
        lint dist_to_node = dist.at(node);
        for (const lint neighbor : adj.at(node)) {
            if (dist.at(neighbor) == 0) {
                dist.at(neighbor) = dist_to_node + w.at({node, neighbor});
            }
            else if (dist.at(neighbor) != dist_to_node + w.at({node, neighbor})) {
                cout << "No" << "\n";
                return 0;
            }
        }
    }
    cout << "Yes" << "\n";
    return 0;
}


Measured memory_bytes: 21240