-
Notifications
You must be signed in to change notification settings - Fork 0
/
16710.cpp
48 lines (43 loc) · 1.13 KB
/
16710.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <bits/stdc++.h>
using namespace std;
const int MX = 2e5 + 5;
vector <int> adj[MX];
int N, M, K, C[MX], S, E;
bitset <500001> b1, b2;
void BFS(queue <int> &q, bitset <500001> &b){
for(int i = 0; i < 2; i++){
int sz = q.size();
while(sz--){
int pos = q.front();
q.pop();
for(int next : adj[pos]){
if(b.test(next)) continue;
q.push(next), b.set(next);
}
}
}
}
int main(){
cin.tie(nullptr), ios::sync_with_stdio(false);
cin >> N >> M >> K;
for(int i = 1; i <= N; i++) cin >> C[i];
for(int i = 0; i < M; i++){
cin >> S >> E;
adj[S].push_back(E);
adj[E].push_back(S);
}
if(!K){cout << C[1]; return 0;}
int lo = 0, hi = 1e9;
while(lo < hi){
int mid = lo + hi >> 1;
queue <int> q1, q2;
b1.reset(), b2.reset();
q1.push(1), b1.set(1);
for(int i = 1; i <= N; i++) if(C[i] <= mid) q2.push(i), b2.set(i);
BFS(q1, b1), BFS(q2, b2);
b2.flip();
if((b1 & b2).any()) lo = mid + 1;
else hi = mid;
}
cout << lo;
}