Untitled
// y.ha #include <bits/stdc++.h> #define cook '\n' #define maxn 100001 #define Task "E" using namespace std; struct D { int u,v,w,pos ; }; int n,m,q,parent[maxn] ; D in[maxn] ; int Find(int u) { if ( !parent[u] ) return u ; return parent[u] = Find(parent[u]) ; } bool cmp(D x,D y) { return x.w < y.w ; } bool Check(D X[maxn],int k) { memset(parent,0,sizeof(parent)) ; sort(X+1,X+1+n,cmp) ; for ( int i = 1; i <= m; i++ ) { int pu = Find(X[i].u) ; int pv = Find(X[i].v) ; if ( pu != pv ) { parent[pv] = pu ; if ( k == X[i].pos ) return true ; } } return false ; } int main() { ios_base::sync_with_stdio(0) ; cin.tie(nullptr) ; if(fopen(Task".INP","r")) { freopen(Task".INP","r",stdin); freopen(Task".OUT","w",stdout); } cin >> n >> m >> q ; for ( int i = 1; i <= m; i++ ) { cin >> in[i].u >> in[i].v >> in[i].w ; in[i].pos = i ; } while ( q-- ) { int k,s ; cin >> k >> s; while ( s-- ) { int t,c ; cin >> t >> c ; in[t].w = c; } if ( Check(in,k) ) cout << "NO" ; else cout << "YES" ; cout << cook ; } return(0) ; }
Leave a Comment