#include using namespace std; using graph = vector>>; bool dfs(const graph &to, vector &visited, int city, int road, int term) { visited.at(road) = true; for (auto next : to.at(city)) { if (next.second == road) continue; if (next.first == term) return true; if (visited.at(next.second)) continue; visited.at(next.second) = true; if (dfs(to, visited, next.first, next.second, term)) return true; } return false; } int main() { int n, m; cin >> n >> m; graph to(n); for (int i = 0; i < m; i++) { int a, b, c; cin >> a >> b >> c; a--; b--; to.at(a).emplace_back(b, i); if (c == 1) { to.at(b).emplace_back(a, i); } } vector visited(m + 1); for (int i = 0; i < n; i++) { if (dfs(to, visited, i, m, i)) { cout << "Yes" << endl; return 0; } } cout << "No" << endl; }