Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <vector>
- #include <cstring>
- #include <cmath>
- #include <queue>
- #include <fstream>
- using namespace std;
- typedef long long ll;
- const int maxn = 1e5 + 10;
- int n, m, k;
- vector<int> graph[maxn];
- int gas[maxn];
- struct node {
- int idx, passed, mood;
- node () {}
- node(int _i, int _p, int _m) {
- idx = _i;
- passed = _p;
- mood = _m;
- }
- bool operator < (const node &tmp) const {
- int p1 = 0, p2 = 0;
- if(mood > tmp.mood) {
- p1 += 1;
- }
- else {
- p2 += 1;
- }
- if(passed < tmp.passed) {
- p1 += 1;
- }
- else {
- p2 += 1;
- }
- return p1 < p2;
- }
- };
- int main() {
- ios_base::sync_with_stdio(false);
- cin >> n >> m >> k;
- for(int i = 0; i < n; i++) {
- cin >> gas[i];
- }
- for(int i = 0; i < m; i++) {
- int a, b;
- cin >> a >> b;
- --a; --b;
- graph[a].push_back(b);
- graph[b].push_back(a);
- }
- priority_queue<node> Q;
- Q.push(node(0, 1, gas[0]));
- vector<int> dist(n + 5, -2e9);
- int r1 = 0, r2 = 2e9;
- dist[0] = gas[0];
- while(!Q.empty()) {
- node c = Q.top();
- Q.pop();
- if(c.idx == n - 1) {
- if(r1 < c.mood) {
- r1 = c.mood;
- r2 = c.passed;
- }
- else if(r1 == c.mood) {
- if(r2 > c.passed) {
- r2 = c.passed;
- }
- }
- continue;
- }
- for(int i = 0; i < (int) graph[c.idx].size(); i++) {
- int neigh = graph[c.idx][i];
- if(c.passed < k and dist[neigh] < min(c.mood, gas[neigh])){
- Q.push(node(neigh, c.passed + 1, min(c.mood, gas[neigh])));
- dist[neigh] = min(c.mood, gas[neigh]);
- }
- }
- }
- cout << r1 << " " << r2 << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement