#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> to; vector> from; vector vs; vector depth; vector used; vector cmp; void dfs(int v){ used[v]=true; for(auto t:to[v]) if(!used[t]) dfs(t); vs.push_back(v); } int r_dfs(int v,int k){ int ret=0; used[v]=true; cmp[v]=k; for(const auto t:from[v]){ if(!used[t]) r_dfs(t,k); depth[v]=max(depth[v],depth[t]+1); } } DirectedGraph(int V) : V(V), to(vector>(V)), from(vector>(V)), cmp(vector(V)), depth(vector(V)) {} void add_edge(int from_,int to_){ to[from_].push_back(to_); from[to_].push_back(from_); } int scc_num=-1; int scc(){ used=vector(V,false); vs.clear(); for(int v=0;v(V,false); scc_num=0; for(int i=vs.size()-1;i>=0;i--)if(!used[vs[i]]){ max_len=max(max_len,r_dfs(vs[i],scc_num++)); } return scc_num; } bool isCyclic(){ return (scc_num!=V); } DirectedGraph makeTopologicalGraph(){ DirectedGraph TG(scc_num); rep(s,V) for(auto t:to[s]){ if(cmp[s]!=cmp[t]) TG.add_edge(cmp[s],cmp[t]); } return TG; } }; signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,m;cin>>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); } DirectedGraph g(id.size()); for(auto &p:es){ if(uf.root(p.first)==uf.root(p.second)){ cout<<"Yes"<