fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. void __print(int x) {cerr << x;}
  5. void __print(long x) {cerr << x;}
  6. void __print(long long x) {cerr << x;}
  7. void __print(unsigned x) {cerr << x;}
  8. void __print(unsigned long x) {cerr << x;}
  9. void __print(unsigned long long x) {cerr << x;}
  10. void __print(float x) {cerr << x;}
  11. void __print(double x) {cerr << x;}
  12. void __print(long double x) {cerr << x;}
  13. void __print(char x) {cerr << '\'' << x << '\'';}
  14. void __print(const char *x) {cerr << '\"' << x << '\"';}
  15. void __print(const string &x) {cerr << '\"' << x << '\"';}
  16. void __print(bool x) {cerr << (x ? "true" : "false");}
  17.  
  18. template<typename T, typename V>
  19. void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
  20. template<typename T>
  21. void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
  22. void _print() {cerr << "]\n";}
  23. template <typename T, typename... V>
  24. void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
  25. #ifndef ONLINE_JUDGE
  26. #define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
  27. #else
  28. #define debug(x...)
  29. #endif
  30.  
  31. #define int long long
  32. typedef pair<int, int> ii;
  33.  
  34. const int N = 2e6 + 5;
  35. const int MOD = 1e9 + 7;
  36. const int oo = 0x3f3f3f3f;
  37.  
  38. #define endl '\n'
  39. #define all(a) a.begin(), a.end()
  40. #define rall(a) a.rbegin(), a.rend()
  41.  
  42. int binpow(int a, int b, int m) {
  43. a %= m;
  44. int res = 1;
  45. while (b > 0) {
  46. if (b & 1)
  47. res = res * a % m;
  48. a = a * a % m;
  49. b >>= 1;
  50. }
  51. return res;
  52. }
  53. vector<int> g[N];
  54. int used[N];
  55. int cnt;
  56. void bfs(int s, int d) {
  57. queue<int> q;
  58. used[s]++;
  59. q.push(s);
  60. while (!q.empty()) {
  61. int u = q.front();
  62. q.pop();
  63.  
  64. for (auto v : g[u]) {
  65. if (used[v] == 0) {
  66. used[v]++;
  67. q.push(v);
  68. }
  69. }
  70. ++cnt;
  71. if (cnt == d) return;
  72. }
  73. }
  74. void solve() {
  75. // Do something
  76. int n, r, m;
  77. cin >> n >> r >> m;
  78.  
  79. for (int i = 1; i <= r; ++i) {
  80. int x, y;
  81. cin >> x >> y;
  82. g[x].push_back(y);
  83. g[y].push_back(x);
  84. }
  85. fill(used + 1, used + n + 1, 0);
  86. for (int i = 1; i <= m; ++i) {
  87. int k, s;
  88. cin >> k >> s;
  89. cnt = 0;
  90. bfs(k, s);
  91. }
  92. bool ok = true;
  93. for (int i = 1; i <= n; ++i) {
  94. //cout << used[i] << ' ';
  95. if (used[i] != 1) {
  96. ok = false;
  97. break;
  98. }
  99. }
  100. // cout << endl;
  101. cout << ((ok)? "Yes\n" : "No\n");
  102. for (int i = 0; i <= N; ++i) {
  103. g[i].clear();
  104. }
  105. }
  106. int32_t main(void) {
  107. ios_base::sync_with_stdio(false);
  108. cin.tie(0);
  109.  
  110. //freopen("cf.INP", "r", stdin);
  111. //freopen("cf.OUT", "w", stdout);
  112.  
  113. int tc = 1;
  114. cin >> tc;
  115. while (tc--) {
  116. solve();
  117. }
  118. }
Success #stdin #stdout 0.02s 52144KB
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