#include <bits/stdc++.h>
using namespace std;
int a[16], b[16], c[16], n, m, r;
int main() {
  cin >> n >> m >> r;
  if (m > 16) return 0;
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i] >> c[i];
  }
  int minx = 1000000000;
  for (int i = 0; i < (1 << m); i++) {
    int bit[16], s = 0, t = 0;
    for (int j = 0; j < m; j++) {
      bit[j] = (i / (1 << j)) % 2;
      s += bit[j];
      t += bit[j] * c[j];
    }
    if (s != n - 1) continue;
    int dist[16];
    for (int j = 0; j < 16; j++) dist[j] = 0;
    queue<int> Q;
    Q.push(r);
    dist[r] = 1;
    while (!Q.empty()) {
      int to = Q.front();
      Q.pop();
      for (int j = 0; j < m; j++) {
        if (bit[j] == 0) continue;
        if (a[j] != to) continue;
        if (dist[b[j]] == 0) {
          dist[b[j]] = 1;
          Q.push(b[j]);
        }
      }
    }
    int OK = 1;
    for (int i = 0; i < n; i++) {
      if (dist[i] == 0) OK = 0;
    }
    if (OK == 1) minx = min(minx, t);
  }
  cout << minx << endl;
  return 0;
}
