#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
#define ff first
#define ss second
#define MP make_pair
const int mxn = 1e6 + 10;
int dis[mxn], a[mxn], n, m;
vector<int> adj[mxn];
int main() {
cin >> n >> m;
for(int i = 1; i <= n; i++)
cin >> a[i];
for(int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
memset(dis, -1, sizeof dis);
priority_queue<pii> pq;
pq.push(MP(0, 1));
while(pq.size()) {
int d = -pq.top().ff;
int u = pq.top().ss;
pq.pop();
if(dis[u] > -1) continue;
dis[u] = d;
for(int v : adj[u])
if(dis[v] == -1)
pq.push(MP(-max(d, a[v]), v));
}
cout << dis[n] * 2 << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
29532 KB |
Output is correct |
2 |
Incorrect |
131 ms |
38984 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
29528 KB |
Output is correct |
2 |
Incorrect |
6 ms |
29532 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
29528 KB |
Output is correct |
2 |
Incorrect |
6 ms |
29532 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
29532 KB |
Output is correct |
2 |
Incorrect |
131 ms |
38984 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |