#include <bits/stdc++.h>
const int maxn = 800 + 10;
const int maxm = 4e5 + 10;
const int inf = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
const double eps = 1e-7;
using namespace std;
struct Node {
  int to, next, val;
} edge[maxm];
int n, m, s, t, ans, cnt = 1, head[maxn], N, K, a[maxn];
void add(int u, int v, int w) {
  cnt++;
  edge[cnt].to = v;
  edge[cnt].next = head[u];
  edge[cnt].val = w;
  head[u] = cnt;
}
int dep[maxn];
queue<int> q;
bool bfs() {
  memset(dep, 0, (t + 1) * sizeof(int));
  q.push(s);
  dep[s] = 1;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int p = head[u]; p; p = edge[p].next) {
      int v = edge[p].to;
      if (edge[p].val && !dep[v]) {
        dep[v] = dep[u] + 1;
        q.push(v);
      }
    }
  }
  return dep[t];
}
int dfs(int u, int in) {
  if (u == t) return in;
  int out = 0;
  for (int p = head[u]; p && in; p = edge[p].next) {
    int v = edge[p].to;
    if (edge[p].val && dep[v] == dep[u] + 1) {
      int res = dfs(v, min(edge[p].val, in));
      edge[p].val -= res;
      edge[p ^ 1].val += res;
      in -= res;
      out += res;
    }
  }
  if (out == 0) dep[u] = 0;
  return out;
}
int d[maxn][maxn], h[maxn];
struct E {
  int to, dis, next;
} e[maxm];
int tot;
inline void add_edge(int u, int v, int d) {
  tot++;
  e[tot].dis = d;
  e[tot].to = v;
  e[tot].next = h[u];
  h[u] = tot;
}
struct node {
  int dis, pos;
  bool operator<(const node& x) const { return x.dis < dis; }
};
priority_queue<node> q1;
bool vis[maxn];
inline void Dijkstra(int s) {
  fill(vis, vis + maxn, 0);
  q1.push(node{0, s});
  for (int i = 1; i <= n; i++) d[s][i] = inf;
  d[s][s] = 0;
  while (!q1.empty()) {
    node temp = q1.top();
    q1.pop();
    long long x = temp.pos;
    if (vis[x]) continue;
    vis[x] = 1;
    for (int i = h[x]; i; i = e[i].next) {
      int y = e[i].to;
      if (d[s][y] > d[s][x] + e[i].dis) {
        d[s][y] = d[s][x] + e[i].dis;
        q1.push(node{d[s][y], y});
      }
    }
  }
}
bool check(int x) {
  cnt = 1;
  memset(head, 0, sizeof(head));
  for (int i = 0; i < maxm; i++) edge[i].next = edge[i].to = edge[i].val = 0;
  ans = 0;
  s = 0;
  t = N + n + 1;
  for (int i = 1; i <= N; i++) {
    add(s, i, 1);
    add(i, s, 0);
    for (int j = 1; j <= n; j++) {
      if (d[a[i]][j] <= x) {
        add(i, N + j, 1);
        add(N + j, i, 0);
      }
    }
  }
  for (int j = 1; j <= n; j++) add(N + j, t, 1), add(t, N + j, 0);
  while (bfs()) ans += dfs(s, 2e9);
  return ans >= K;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  cin >> n >> m >> N >> K;
  for (int i = 1; i <= N; i++) cin >> a[i];
  for (int i = 1; i <= m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    add_edge(u, v, w);
    add_edge(v, u, w);
  }
  for (int i = 1; i <= n; i++) Dijkstra(i);
  int l = 0, r = 1731311;
  int res = -1;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check(mid)) {
      res = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  cout << res;
  return ~~(0 - 0);
}

### Prompt

Construct a Cpp code solution to the problem outlined:

The competitors of Bubble Cup X gathered after the competition and discussed what is the best way to get to know the host country and its cities.

After exploring the map of Serbia for a while, the competitors came up with the following facts: the country has V cities which are indexed with numbers from 1 to V, and there are E bi-directional roads that connect the cites. Each road has a weight (the time needed to cross that road). There are N teams at the Bubble Cup and the competitors came up with the following plan: each of the N teams will start their journey in one of the V cities, and some of the teams share the starting position.

They want to find the shortest time T, such that every team can move in these T minutes, and the number of different cities they end up in is at least K (because they will only get to know the cities they end up in). A team doesn't have to be on the move all the time, if they like it in a particular city, they can stay there and wait for the time to pass.

Please help the competitors to determine the shortest time T so it's possible for them to end up in at least K different cities or print -1 if that is impossible no matter how they move.

Note that there can exist multiple roads between some cities.

Input

The first line contains four integers: V, E, N and K (1 ≤ V ≤ 600, 1 ≤ E ≤ 20000, 1 ≤ N ≤ min(V, 200), 1 ≤ K ≤ N), number of cities, number of roads, number of teams and the smallest number of different cities they need to end up in, respectively.

The second line contains N integers, the cities where the teams start their journey.

Next E lines contain information about the roads in following format: Ai Bi Ti (1 ≤ Ai, Bi ≤ V, 1 ≤ Ti ≤ 10000), which means that there is a road connecting cities Ai and Bi, and you need Ti minutes to cross that road.

Output

Output a single integer that represents the minimal time the teams can move for, such that they end up in at least K different cities or output -1 if there is no solution.

If the solution exists, result will be no greater than 1731311.

Example

Input

6 7 5 4
5 5 2 2 5
1 3 3
1 5 2
1 6 5
2 5 4
2 6 7
3 4 11
3 5 3


Output

3

Note

Three teams start from city 5, and two teams start from city 2. If they agree to move for 3 minutes, one possible situation would be the following: Two teams in city 2, one team in city 5, one team in city 3 , and one team in city 1. And we see that there are four different cities the teams end their journey at.

### Response

```cpp
#include <bits/stdc++.h>
const int maxn = 800 + 10;
const int maxm = 4e5 + 10;
const int inf = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
const double eps = 1e-7;
using namespace std;
struct Node {
  int to, next, val;
} edge[maxm];
int n, m, s, t, ans, cnt = 1, head[maxn], N, K, a[maxn];
void add(int u, int v, int w) {
  cnt++;
  edge[cnt].to = v;
  edge[cnt].next = head[u];
  edge[cnt].val = w;
  head[u] = cnt;
}
int dep[maxn];
queue<int> q;
bool bfs() {
  memset(dep, 0, (t + 1) * sizeof(int));
  q.push(s);
  dep[s] = 1;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int p = head[u]; p; p = edge[p].next) {
      int v = edge[p].to;
      if (edge[p].val && !dep[v]) {
        dep[v] = dep[u] + 1;
        q.push(v);
      }
    }
  }
  return dep[t];
}
int dfs(int u, int in) {
  if (u == t) return in;
  int out = 0;
  for (int p = head[u]; p && in; p = edge[p].next) {
    int v = edge[p].to;
    if (edge[p].val && dep[v] == dep[u] + 1) {
      int res = dfs(v, min(edge[p].val, in));
      edge[p].val -= res;
      edge[p ^ 1].val += res;
      in -= res;
      out += res;
    }
  }
  if (out == 0) dep[u] = 0;
  return out;
}
int d[maxn][maxn], h[maxn];
struct E {
  int to, dis, next;
} e[maxm];
int tot;
inline void add_edge(int u, int v, int d) {
  tot++;
  e[tot].dis = d;
  e[tot].to = v;
  e[tot].next = h[u];
  h[u] = tot;
}
struct node {
  int dis, pos;
  bool operator<(const node& x) const { return x.dis < dis; }
};
priority_queue<node> q1;
bool vis[maxn];
inline void Dijkstra(int s) {
  fill(vis, vis + maxn, 0);
  q1.push(node{0, s});
  for (int i = 1; i <= n; i++) d[s][i] = inf;
  d[s][s] = 0;
  while (!q1.empty()) {
    node temp = q1.top();
    q1.pop();
    long long x = temp.pos;
    if (vis[x]) continue;
    vis[x] = 1;
    for (int i = h[x]; i; i = e[i].next) {
      int y = e[i].to;
      if (d[s][y] > d[s][x] + e[i].dis) {
        d[s][y] = d[s][x] + e[i].dis;
        q1.push(node{d[s][y], y});
      }
    }
  }
}
bool check(int x) {
  cnt = 1;
  memset(head, 0, sizeof(head));
  for (int i = 0; i < maxm; i++) edge[i].next = edge[i].to = edge[i].val = 0;
  ans = 0;
  s = 0;
  t = N + n + 1;
  for (int i = 1; i <= N; i++) {
    add(s, i, 1);
    add(i, s, 0);
    for (int j = 1; j <= n; j++) {
      if (d[a[i]][j] <= x) {
        add(i, N + j, 1);
        add(N + j, i, 0);
      }
    }
  }
  for (int j = 1; j <= n; j++) add(N + j, t, 1), add(t, N + j, 0);
  while (bfs()) ans += dfs(s, 2e9);
  return ans >= K;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  cin >> n >> m >> N >> K;
  for (int i = 1; i <= N; i++) cin >> a[i];
  for (int i = 1; i <= m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    add_edge(u, v, w);
    add_edge(v, u, w);
  }
  for (int i = 1; i <= n; i++) Dijkstra(i);
  int l = 0, r = 1731311;
  int res = -1;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check(mid)) {
      res = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  cout << res;
  return ~~(0 - 0);
}

```