import std.stdio, std.array, std.string, std.conv, std.algorithm; import std.typecons, std.range, std.random, std.math, std.container; import std.numeric, std.bigint, core.bitop, core.stdc.stdlib; void main() { auto s = readln.split.map!(to!int); auto N = s[0]; auto M = s[1]; auto G = new int[][](N); foreach (i; 0..M) { s = readln.split.map!(to!int); auto u = s[0] - 1; auto v = s[1] - 1; auto c = s[2]; G[u] ~= v; if (c == 1) G[v] ~= u; } auto visited = new bool[](N); bool dfs(int n, int p) { if (visited[n]) return true; visited[n] = true; foreach (m; G[n]) { if (p == m) continue; if (dfs(m, n)) return true; } return false; } writeln(dfs(0, -1) ? "Yes" : "No"); }