#pragma GCC optimize("O3") #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; using P = pair; using T = tuple; template inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;} template inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;} constexpr int MOD = 1e9 + 7; constexpr int inf = 1e9; constexpr long long INF = 1e18; #define all(a) (a).begin(), (a).end() int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; const int MAX_V = 100010; int V; vector> G(MAX_V); vector> rG(MAX_V); vector vs; vector used(MAX_V); vector cmp(MAX_V); void add_edge(int from, int to){ G[from].push_back(to); rG[to].push_back(from); } void dfs(int v){ used[v] = true; for(int i=0; i=0; i--){ if(!used[vs[i]]) rdfs(vs[i], k++); } return k; } int main(){ cin.tie(0); ios::sync_with_stdio(false); int m; cin>>V>>m; map edge; for(int i=0; i>a>>b>>c; a--, b--; add_edge(a, b); if(c == 1) add_edge(b, a); edge[minmax(a, b)]++; } scc(); map cnt; for(int i=0; i> G(V); for(int i=0; i= 2) valid = true; } } } cout << (valid ? "Yes" : "No") << endl; return 0; }