Advertisement
josiftepe

Untitled

Mar 2nd, 2022
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. #include <cstring>
  5. #include <cmath>
  6. #include <queue>
  7. #include <fstream>
  8. using namespace std;
  9. typedef long long ll;
  10. const int maxn = 1e5 + 10;
  11. int n, m, k;
  12. vector<int> graph[maxn];
  13. int gas[maxn];
  14. struct node {
  15. int idx, passed, mood;
  16. node () {}
  17. node(int _i, int _p, int _m) {
  18. idx = _i;
  19. passed = _p;
  20. mood = _m;
  21. }
  22. bool operator < (const node &tmp) const {
  23. int p1 = 0, p2 = 0;
  24. if(mood > tmp.mood) {
  25. p1 += 1;
  26. }
  27. else {
  28. p2 += 1;
  29. }
  30. if(passed < tmp.passed) {
  31. p1 += 1;
  32. }
  33. else {
  34. p2 += 1;
  35. }
  36. return p1 < p2;
  37. }
  38. };
  39. int main() {
  40. ios_base::sync_with_stdio(false);
  41. cin >> n >> m >> k;
  42. for(int i = 0; i < n; i++) {
  43. cin >> gas[i];
  44. }
  45. for(int i = 0; i < m; i++) {
  46. int a, b;
  47. cin >> a >> b;
  48. --a; --b;
  49. graph[a].push_back(b);
  50. graph[b].push_back(a);
  51. }
  52. priority_queue<node> Q;
  53. Q.push(node(0, 1, gas[0]));
  54. vector<int> dist(n + 5, -2e9);
  55. int r1 = 0, r2 = 2e9;
  56. dist[0] = gas[0];
  57. while(!Q.empty()) {
  58. node c = Q.top();
  59. Q.pop();
  60. if(c.idx == n - 1) {
  61. if(r1 < c.mood) {
  62. r1 = c.mood;
  63. r2 = c.passed;
  64. }
  65. else if(r1 == c.mood) {
  66. if(r2 > c.passed) {
  67. r2 = c.passed;
  68. }
  69. }
  70. continue;
  71. }
  72. for(int i = 0; i < (int) graph[c.idx].size(); i++) {
  73. int neigh = graph[c.idx][i];
  74. if(c.passed < k and dist[neigh] < min(c.mood, gas[neigh])){
  75. Q.push(node(neigh, c.passed + 1, min(c.mood, gas[neigh])));
  76. dist[neigh] = min(c.mood, gas[neigh]);
  77. }
  78. }
  79. }
  80. cout << r1 << " " << r2 << endl;
  81. return 0;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement