#include <bits/stdc++.h>
using namespace std;
const int maxn = 600 + 5;
const int inf = 1e9;
const long double eps = 1e-8;
const long long mod = 1e9 + 7;
struct FlowEdge {
  int v, u;
  long long cap, flow = 0;
  FlowEdge(int v, int u, long long cap) : v(v), u(u), cap(cap) {}
};
struct Dinic {
  const long long flow_inf = 1e18;
  vector<FlowEdge> edges;
  vector<vector<int>> adj;
  int n, m = 0;
  int s, t;
  vector<int> level, ptr;
  queue<int> q;
  Dinic(int n, int s, int t) : n(n), s(s), t(t) {
    adj.resize(n);
    level.resize(n);
    ptr.resize(n);
  }
  void add_edge(int v, int u, long long cap) {
    edges.emplace_back(v, u, cap);
    edges.emplace_back(u, v, 0);
    adj[v].push_back(m);
    adj[u].push_back(m + 1);
    m += 2;
  }
  bool bfs() {
    while (!q.empty()) {
      int v = q.front();
      q.pop();
      for (int id : adj[v]) {
        if (edges[id].cap - edges[id].flow < 1) continue;
        if (level[edges[id].u] != -1) continue;
        level[edges[id].u] = level[v] + 1;
        q.push(edges[id].u);
      }
    }
    return level[t] != -1;
  }
  long long dfs(int v, long long pushed) {
    if (pushed == 0) return 0;
    if (v == t) return pushed;
    for (int& cid = ptr[v]; cid < (int)adj[v].size(); cid++) {
      int id = adj[v][cid];
      int u = edges[id].u;
      if (level[v] + 1 != level[u] || edges[id].cap - edges[id].flow < 1)
        continue;
      long long tr = dfs(u, min(pushed, edges[id].cap - edges[id].flow));
      if (tr == 0) continue;
      edges[id].flow += tr;
      edges[id ^ 1].flow -= tr;
      return tr;
    }
    return 0;
  }
  long long flow() {
    long long f = 0;
    while (true) {
      fill(level.begin(), level.end(), -1);
      level[s] = 0;
      q.push(s);
      if (!bfs()) break;
      fill(ptr.begin(), ptr.end(), 0);
      while (long long pushed = dfs(s, flow_inf)) {
        f += pushed;
      }
    }
    return f;
  }
};
int v, e, n, k;
int dp[maxn][maxn];
set<int> leftSide;
int cnt[maxn];
bool ok(int mid) {
  Dinic dinic(v + n + 2, 0, n + v + 1);
  for (int i = (int)1; i <= (int)n; i++) {
    dinic.add_edge(0, i, 1);
    for (int j = (int)1; j <= (int)v; j++) {
      if (dp[cnt[i]][j] > mid) continue;
      dinic.add_edge(i, j + n, 1);
    }
  }
  for (int i = (int)1; i <= (int)v; i++) {
    dinic.add_edge(i + n, v + n + 1, 1);
  }
  return dinic.flow() >= k;
}
int main() {
  ios_base::sync_with_stdio(false);
  ;
  cin >> v >> e >> n >> k;
  for (int i = (int)1; i <= (int)v; i++) {
    for (int j = (int)1; j <= (int)v; j++) {
      dp[i][j] = inf;
    }
    dp[i][i] = 0;
  }
  for (int i = (int)1; i <= (int)n; i++) {
    int x;
    cin >> x;
    cnt[i] = x;
  }
  for (int i = (int)1; i <= (int)e; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    dp[u][v] = dp[v][u] = min(dp[u][v], w);
  }
  for (int k = (int)1; k <= (int)v; k++) {
    for (int i = (int)1; i <= (int)v; i++) {
      for (int j = (int)1; j <= (int)v; j++) {
        dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
      }
    }
  }
  int lo = 0;
  int hi = 1731311;
  int res = -1;
  while (lo <= hi) {
    int mid = lo + hi;
    mid >>= 1;
    if (ok(mid)) {
      res = mid;
      hi = mid - 1;
    } else
      lo = mid + 1;
  }
  cout << res << endl;
}

### Prompt

Please formulate a Cpp solution to the following problem:

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>
using namespace std;
const int maxn = 600 + 5;
const int inf = 1e9;
const long double eps = 1e-8;
const long long mod = 1e9 + 7;
struct FlowEdge {
  int v, u;
  long long cap, flow = 0;
  FlowEdge(int v, int u, long long cap) : v(v), u(u), cap(cap) {}
};
struct Dinic {
  const long long flow_inf = 1e18;
  vector<FlowEdge> edges;
  vector<vector<int>> adj;
  int n, m = 0;
  int s, t;
  vector<int> level, ptr;
  queue<int> q;
  Dinic(int n, int s, int t) : n(n), s(s), t(t) {
    adj.resize(n);
    level.resize(n);
    ptr.resize(n);
  }
  void add_edge(int v, int u, long long cap) {
    edges.emplace_back(v, u, cap);
    edges.emplace_back(u, v, 0);
    adj[v].push_back(m);
    adj[u].push_back(m + 1);
    m += 2;
  }
  bool bfs() {
    while (!q.empty()) {
      int v = q.front();
      q.pop();
      for (int id : adj[v]) {
        if (edges[id].cap - edges[id].flow < 1) continue;
        if (level[edges[id].u] != -1) continue;
        level[edges[id].u] = level[v] + 1;
        q.push(edges[id].u);
      }
    }
    return level[t] != -1;
  }
  long long dfs(int v, long long pushed) {
    if (pushed == 0) return 0;
    if (v == t) return pushed;
    for (int& cid = ptr[v]; cid < (int)adj[v].size(); cid++) {
      int id = adj[v][cid];
      int u = edges[id].u;
      if (level[v] + 1 != level[u] || edges[id].cap - edges[id].flow < 1)
        continue;
      long long tr = dfs(u, min(pushed, edges[id].cap - edges[id].flow));
      if (tr == 0) continue;
      edges[id].flow += tr;
      edges[id ^ 1].flow -= tr;
      return tr;
    }
    return 0;
  }
  long long flow() {
    long long f = 0;
    while (true) {
      fill(level.begin(), level.end(), -1);
      level[s] = 0;
      q.push(s);
      if (!bfs()) break;
      fill(ptr.begin(), ptr.end(), 0);
      while (long long pushed = dfs(s, flow_inf)) {
        f += pushed;
      }
    }
    return f;
  }
};
int v, e, n, k;
int dp[maxn][maxn];
set<int> leftSide;
int cnt[maxn];
bool ok(int mid) {
  Dinic dinic(v + n + 2, 0, n + v + 1);
  for (int i = (int)1; i <= (int)n; i++) {
    dinic.add_edge(0, i, 1);
    for (int j = (int)1; j <= (int)v; j++) {
      if (dp[cnt[i]][j] > mid) continue;
      dinic.add_edge(i, j + n, 1);
    }
  }
  for (int i = (int)1; i <= (int)v; i++) {
    dinic.add_edge(i + n, v + n + 1, 1);
  }
  return dinic.flow() >= k;
}
int main() {
  ios_base::sync_with_stdio(false);
  ;
  cin >> v >> e >> n >> k;
  for (int i = (int)1; i <= (int)v; i++) {
    for (int j = (int)1; j <= (int)v; j++) {
      dp[i][j] = inf;
    }
    dp[i][i] = 0;
  }
  for (int i = (int)1; i <= (int)n; i++) {
    int x;
    cin >> x;
    cnt[i] = x;
  }
  for (int i = (int)1; i <= (int)e; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    dp[u][v] = dp[v][u] = min(dp[u][v], w);
  }
  for (int k = (int)1; k <= (int)v; k++) {
    for (int i = (int)1; i <= (int)v; i++) {
      for (int j = (int)1; j <= (int)v; j++) {
        dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
      }
    }
  }
  int lo = 0;
  int hi = 1731311;
  int res = -1;
  while (lo <= hi) {
    int mid = lo + hi;
    mid >>= 1;
    if (ok(mid)) {
      res = mid;
      hi = mid - 1;
    } else
      lo = mid + 1;
  }
  cout << res << endl;
}

```