fork download
  1. /* Author: the_kalakar/infinity23
  2.   ----ASEEM BARANWAL----*/
  3. #include<bits/stdc++.h>
  4. #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  5. using namespace std;
  6.  
  7. const int maxN = 1000001;
  8. vector<int> G[maxN], vis(maxN), so(maxN);
  9. int n;
  10.  
  11. inline void output(string x){cout << x << endl;}
  12.  
  13. void solve(){
  14. cin >> n;
  15. for(int i = 1; i <=n; i++){
  16. G[i].clear();
  17. vis[i] = 0;
  18. }
  19. int r, m, a, b; cin >> r >> m;
  20. while(r--){
  21. cin >> a >> b;
  22. G[a].push_back(b);
  23. G[b].push_back(a);
  24. }
  25. queue<int> q;
  26. while(m--){
  27. int k, s; cin >> k >> s;
  28. q.push(k);
  29. if(vis[k]){
  30. output("No");
  31. break;
  32. }
  33. vis[k] = 1, so[k] = k;
  34. int curr = 0;
  35. while(!q.empty() and curr < s){
  36. int node = q.front(); q.pop();
  37. for(int x: G[node]){
  38. if(vis[x] and so[x] != k){
  39. output("No");
  40. return;
  41. }
  42. vis[x] = 1;
  43. so[x] = k;
  44. q.push(x);
  45. }
  46. curr++;
  47. }
  48. }
  49. output("Yes");
  50. }
  51. int main(){
  52. fastio
  53. int t;cin>>t;
  54. while(t--){
  55. solve();
  56. }
  57. return 0;
  58. }
Success #stdin #stdout 0.02s 34496KB
stdin
1
4 4 1
1 2
1 3
2 3
3 4
1 2
stdout
Yes