#include <bits/stdc++.h>
using namespace std;
#define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define sp " "
#define endl "\n"
#define pii pair<int, int>
#define st first
#define nd second
#define pb push_back
#define N 300005
#define int long long
const int INF = 2e18 + 7;
int d[2][N];
vector<int> adj[N];
int arr[N], maks[2][N];
int32_t main(){
//fileio();
fastio();
int n, m;
cin>>n>>m;
vector<int> v;
for (int i = 1; i <= n; i++){
cin>>arr[i];
v.pb(arr[i]);
}
sort(v.begin(), v.end());
for (int i = 1; i <= m; i++){
int u, v;
cin>>u>>v;
adj[u].pb(v);
adj[v].pb(u);
}
int ans = INF;
for (auto K : v){
int root = 1;
for (int i = 0; i < 2; i++){
priority_queue<pii> q;
q.push({0, root});
for (int j = 1; j <= n; j++){
d[i][j] = INF;
}
d[i][root] = 0;
while(!q.empty()){
int top = q.top().nd;
int dd = -q.top().st;
q.pop();
for (auto j : adj[top]){
if (arr[j] > K) continue;
int dist = max(arr[j], dd + 1);
if (d[i][j] > dist){
d[i][j] = dist;
q.push({-dist, j});
}
}
}
root = n;
}
for (int i = 1; i <= n; i++){
if (arr[i] == K) ans = min(ans, d[0][i] + d[1][i]);
}
}
cout<<ans<<endl;
cerr<<"time taken : "<<(float)clock() / CLOCKS_PER_SEC<<" seconds\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12636 KB |
Output is correct |
2 |
Execution timed out |
1086 ms |
22440 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12636 KB |
Output is correct |
2 |
Correct |
2 ms |
12636 KB |
Output is correct |
3 |
Correct |
2 ms |
12636 KB |
Output is correct |
4 |
Correct |
2 ms |
12636 KB |
Output is correct |
5 |
Correct |
3 ms |
12632 KB |
Output is correct |
6 |
Correct |
16 ms |
12636 KB |
Output is correct |
7 |
Correct |
88 ms |
12636 KB |
Output is correct |
8 |
Correct |
36 ms |
12636 KB |
Output is correct |
9 |
Correct |
246 ms |
12884 KB |
Output is correct |
10 |
Correct |
55 ms |
12636 KB |
Output is correct |
11 |
Correct |
259 ms |
12852 KB |
Output is correct |
12 |
Correct |
73 ms |
12852 KB |
Output is correct |
13 |
Correct |
276 ms |
12884 KB |
Output is correct |
14 |
Correct |
312 ms |
12892 KB |
Output is correct |
15 |
Correct |
416 ms |
12888 KB |
Output is correct |
16 |
Correct |
408 ms |
12940 KB |
Output is correct |
17 |
Correct |
381 ms |
13148 KB |
Output is correct |
18 |
Correct |
2 ms |
12632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12636 KB |
Output is correct |
2 |
Correct |
2 ms |
12636 KB |
Output is correct |
3 |
Correct |
2 ms |
12636 KB |
Output is correct |
4 |
Correct |
2 ms |
12636 KB |
Output is correct |
5 |
Correct |
3 ms |
12632 KB |
Output is correct |
6 |
Correct |
16 ms |
12636 KB |
Output is correct |
7 |
Correct |
88 ms |
12636 KB |
Output is correct |
8 |
Correct |
36 ms |
12636 KB |
Output is correct |
9 |
Correct |
246 ms |
12884 KB |
Output is correct |
10 |
Correct |
55 ms |
12636 KB |
Output is correct |
11 |
Correct |
259 ms |
12852 KB |
Output is correct |
12 |
Correct |
73 ms |
12852 KB |
Output is correct |
13 |
Correct |
276 ms |
12884 KB |
Output is correct |
14 |
Correct |
312 ms |
12892 KB |
Output is correct |
15 |
Correct |
416 ms |
12888 KB |
Output is correct |
16 |
Correct |
408 ms |
12940 KB |
Output is correct |
17 |
Correct |
381 ms |
13148 KB |
Output is correct |
18 |
Correct |
2 ms |
12632 KB |
Output is correct |
19 |
Correct |
64 ms |
12860 KB |
Output is correct |
20 |
Correct |
25 ms |
12636 KB |
Output is correct |
21 |
Correct |
77 ms |
12632 KB |
Output is correct |
22 |
Correct |
139 ms |
12860 KB |
Output is correct |
23 |
Correct |
31 ms |
12632 KB |
Output is correct |
24 |
Correct |
99 ms |
12848 KB |
Output is correct |
25 |
Correct |
170 ms |
12892 KB |
Output is correct |
26 |
Correct |
271 ms |
12888 KB |
Output is correct |
27 |
Correct |
314 ms |
12916 KB |
Output is correct |
28 |
Correct |
257 ms |
13152 KB |
Output is correct |
29 |
Correct |
352 ms |
12920 KB |
Output is correct |
30 |
Correct |
343 ms |
12948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12636 KB |
Output is correct |
2 |
Execution timed out |
1086 ms |
22440 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |