fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  4.  
  5. int main()
  6. {
  7. FASTIO;
  8. int t;
  9. cin>>t;
  10. while(t--){
  11. int n,r,m,a,b;
  12. list<int> *adj;
  13. bool *visited;
  14. bool flag = true;
  15. cin>>n>>r>>m;
  16. adj= new list<int>[n+1];
  17. visited = new bool[n+1];
  18. list<int> queue;
  19. for(int i = 0; i < r; i++){
  20. cin>>a>>b;
  21. adj[a].push_back(b);
  22. adj[b].push_back(a);
  23. }
  24. for(int i = 0; i < m; i++){
  25. cin>>a>>b;
  26. if(visited[a]){
  27. flag = false;
  28. }
  29. queue.push_back(a);
  30. visited[a] = true;
  31. while(!queue.empty() && b != 0){
  32. a = queue.front();
  33. queue.pop_front();
  34. for(auto i = adj[a].begin(); i != adj[a].end(); ++i){
  35. if(!visited[*i]){
  36. visited[*i] = true;
  37. queue.push_back(*i);
  38. }
  39. }
  40. b--;
  41. }
  42. while(!queue.empty()) queue.pop_front();
  43. }
  44. for(int i = 1; i <= n; i++){
  45. if(!visited[i]){
  46. flag = false;
  47. }
  48. }
  49.  
  50. if(flag) cout<<"Yes"<<endl;
  51. else cout<<"No"<<endl;
  52. }
  53. return 0;
  54. }
  55.  
Success #stdin #stdout 0s 4320KB
stdin
2

3 2 2

1 2

2 3

1 2

2 0

4 5 2

1 4

1 2

1 3

4 2

3 4

2 1

3 0
stdout
No
Yes