#include using namespace std; #define ALL(x) x.begin(),x.end() #define rep(i,n) for(int i=0;i<(n);i++) #define debug(v) cout<<#v<<":";for(auto x:v){cout<bool chmax(T &a,const T &b){if(abool chmin(T &a,const T &b){if(b par; vector siz; int c;//親の個数(グループ数) void init(int n){ c=n; for(int i=0;i> g; vector> to,from; vector comp,order,used; StronglyConnectedComponents(vector> &g): g(g),to(g.size()),from(g.size()),comp(g.size(),-1),used(g.size()){ for(int i=0;i> &t){ for(int i=0;i>n>>m; UnionFind uf(n); vector> es; rep(i,m){ int a,b,c;cin>>a>>b>>c;a--,b--; if(c==1){ if(uf.sameParent(a,b)){ cout<<"Yes"< id; rep(i,n){ id[i]=uf.root(i); } vector> g(id.size()); for(auto &p:es){ if(id[p.first]==id[p.second]){ cout<<"Yes"<> t; SCC.build(t); cout<<(t.size()==id.size()?"No":"Yes")<