Advertisement
Guest User

Untitled

a guest
Apr 21st, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int n;
  8. int m;
  9. int s;
  10. int t;
  11. queue<int> q;
  12. cin >> n >> m>> t;
  13. int k[n];
  14. vector<vector<int>> a;
  15. a.resize(n);
  16. for(int i = 0; i < n; i++)
  17. a[i].resize(0);
  18. int found[n];
  19. int sum = 0;
  20. for(int i = 0; i < n; i++){
  21. cin >> k[i];
  22. //sum = sum + k[i];
  23. found[i] = -1;
  24. }
  25. int x;
  26. int y;
  27. for(int i = 0; i < m; i++)
  28. {
  29. cin>> x>> y;
  30. x--;
  31. y--;
  32. a[x].resize(a[x].size() + 1);
  33. a[y].resize(a[y].size() + 1);
  34. a[x][a[x].size() - 1] = y;
  35. a[y][a[y].size() - 1] = x;
  36. }
  37. int w;
  38. cin>> s>> w;
  39. s--;
  40. q.push(s);
  41. found[s] = 0;
  42. int ans = -1;
  43. int v;
  44. while (!q.empty() && ans == -1) {
  45. v = q.front();
  46. q.pop();
  47. for (int i = 0; i < a[v].size(); i++) {
  48. //cout << "kek" << v << ' ' << k<< ' ' << "kek";
  49. if(found[a[v][i]] == -1) {
  50. // cout << "kek" << v << ' ' << k<< "kek";
  51. found[a[v][i]] = found[v] + 1;
  52. q.push(i);
  53. }
  54. }
  55. }
  56. for(int i = 0; i < n; i++)
  57. {
  58. // cout << found[i]<< " ";
  59. }
  60. cout << endl;
  61. int j = 0;
  62. int minn;
  63. while (ans == -1)
  64. {
  65. for(int i = 0; i < n; i++){
  66. //cout << found[i]<< " "<<j << endl;
  67. if(found[i] == j){
  68. //cout << "kek";
  69. sum += k[i];
  70. }
  71. }
  72. // cout<< j<<" "<< sum<< " "<< w<< " "<< t<<endl;
  73. minn = min(sum,min( w, t));
  74. sum = sum - minn;
  75. w = w - minn;
  76. if(w == 0)
  77. ans = 0;
  78. if(sum == 0 && w !=0)
  79. ans = 1;
  80. // cout<< j<<" "<< sum<< " "<< w<< " "<< t<<endl<< endl;
  81. j++;
  82. }
  83. if(ans == 0)
  84. cout << "NO";
  85. else
  86. cout << "YES";
  87. return 0; }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement