- BC20260050's blog
hahahahhahahaahahahahahahahahahahgahgasbncgchgfzhccwgfsccsfc
- 2024-11-21 17:07:09 @
#include<bits/stdc++.h> using namespace std; #define int long long const int N=5e5+10; int n,m,q,fa[N],vis[N],k,c[N]; struct node{ int u,v,w,id; }e[N],g[N]; int find(int x){ if(fa[x]x)return x; return fa[x]=find(fa[x]); } void merge(int x,int y){ x=find(x),y=find(y); fa[x]=y; } bool cmp(node x,node y){ return x.w<y.w; } signed main(){ scanf("%lld %lld",&n,&m); for(int i=1;i<=m;i++){ scanf("%lld %lld %lld",&e[i].u,&e[i].v,&e[i].w); g[i]=e[i]; e[i].id=i; } sort(e+1,e+m+1,cmp); for(int l=1,r;l<=m;l++){ r=l; if(r<m&&e[r+1].we[r].w)r++; for(int i=l;i<=r;i++){ int u=find(e[i].u),v=find(e[i].v); if(u!=v){ vis[e[i].id]=1; } } for(int i=l;i<=r;i++){ int u=find(e[i].u),v=find(e[i].v); if(u!=v){ merge(u,v); } } } scanf("%lld",&q); while(q--){ scanf("%lld",&k); int f=1; for(int i=1;i<=k;i++){ scanf("%lld",&c[i]); fa[g[c[i]].u]=g[c[i]].u; fa[g[c[i]].v]=g[c[i]].v; if(vis[c[i]])f=0; } if(!f){ printf("NO\n"); continue; } for(int i=1;i<=k;i++){ int u=find(g[c[i]].u),v=find(g[c[i]].v); if(u!=v){ merge(u,v); }else{ f=0; break; } } if(!f){ printf("NO\n"); }else{ printf("YES\n"); } } return 0; }