Guest User

AKBAR.cpp

a guest
Nov 17th, 2020
83
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. #define fastIO \
  3. ios_base::sync_with_stdio(false); \
  4. cin.tie(NULL);
  5. using namespace std;
  6. unsigned long long int MOD = 1e9 + 7;
  7. unsigned long long int MAX = 1e6;
  8. #define pi pair<int, int>
  9. #define vi vector<int>
  10. #define vvi vector<vi>
  11.  
  12. #define pushb push_back
  13. #define popf pop_front
  14. #define popb pop_back
  15. #define pushf push_front
  16. #define first F
  17. #define second S
  18.  
  19. #define REP(i, a, b) for (int i = a; i < b; i++)
  20.  
  21. typedef long long ll;
  22. typedef unsigned long long ull;
  23.  
  24. void printVis(vi vis)
  25. {
  26. cout << "VIS ARRAY :";
  27. for (auto ele : vis)
  28. {
  29. cout << ele << " ";
  30. }
  31. cout << endl;
  32. }
  33.  
  34. void printAdj(vi adj[], int nodes)
  35. {
  36. int i;
  37. REP(i, 0, nodes)
  38. {
  39. cout << "\nnode :" << i << " : ";
  40.  
  41. for (auto ele : adj[i])
  42. {
  43. cout << ele << " ";
  44. }
  45. cout << endl;
  46. }
  47. }
  48.  
  49. void dfs(vi adj[], int present, vi &vis, int strength, vi &count)
  50. {
  51. vis[present] = 1;
  52. //printVis(vis);
  53. count[present]++;
  54.  
  55. if (strength > 0)
  56. {
  57.  
  58. for (auto ele : adj[present])
  59. {
  60. if (!vis[ele])
  61. {
  62. dfs(adj, ele, vis, strength - 1, count);
  63. }
  64. }
  65. }
  66. }
  67.  
  68. int main()
  69. {
  70. fastIO
  71.  
  72. int t;
  73. cin >> t;
  74.  
  75. while (t--)
  76. {
  77. int V,
  78. E, Q;
  79. cin >> V >> E >> Q;
  80.  
  81. int i;
  82. vi adj[V];
  83.  
  84. REP(i, 0, E)
  85. {
  86. int s, d;
  87. cin >> s >> d;
  88. adj[s - 1].push_back(d - 1);
  89. adj[d - 1].push_back(s - 1);
  90. }
  91.  
  92. //printAdj(adj, V);
  93. vi count(V, 0);
  94.  
  95. while (Q--)
  96. {
  97.  
  98. int node, strength;
  99. cin >> node >> strength;
  100. vi vis(V, 0);
  101.  
  102. dfs(adj, node - 1, vis, strength, count);
  103. }
  104. int flag = 0;
  105. //printVis(count);
  106. string ans = "Yes";
  107. for (auto ele : count)
  108. {
  109. if (ele == 0 || ele > 1)
  110. {
  111. flag = 1;
  112. break;
  113. }
  114. }
  115. if (flag)
  116. ans = "No";
  117. cout << ans << endl;
  118. }
  119. return 0;
  120. }
  121.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×