#include <bits/stdc++.h>
using namespace std;
#define maxn 5005
struct node {
int to, nxt;
int w;
} e[maxn * 10];
int head[maxn], cnt = 0;
void add(int x, int y, int z) {
++cnt;
e[cnt].to = y;
e[cnt].w = z;
e[cnt].nxt = head[x];
head[x] = cnt;
return;
}
int n, m;
queue<int> que;
int vis[maxn], dis[maxn], tot[maxn];
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; ++i) {
int op, a, b, c;
scanf("%d%d%d", &op, &a, &b);
if (op == 1) {
scanf("%d", &c);
add(a, b, -c);
}
else if (op == 2) {
scanf("%d", &c);
add(b, a, c);
}
else {
add(a, b, 0);
add(b, a, 0);
}
}
for (int i = 1; i <= n; ++i)
add(0, i, 0);
memset(dis, 0x3f, sizeof dis);
vis[0] = 1;
dis[0] = 0;
que.emplace(0);
while (que.size()) {
int now = que.front();
que.pop();
vis[now] = 0;
for (int i = head[now]; i; i = e[i].nxt) {
int to = e[i].to;
tot[to] = tot[now] + 1;
if (tot[to] >= n + 1) {
puts("No");
return 0;
}
if (dis[to] > dis[now] + e[i].w) {
dis[to] = dis[now] + e[i].w;
if (!vis[to]) {
vis[to] = 1;
que.emplace(to);
}
}
}
}
puts("Yes");
return 0;
}