#include <bits/stdc++.h>
using namespace std;
vector<vector<long long int> > G, W;
long long int solve(int n, int start) {
  vector<long long int> rep(n, -1);
  vector<long long int> dist(n, 1e16);
  priority_queue<vector<long long int> > Q;
  Q.push({-0, start, start});
  rep[start] = start;
  while (not Q.empty()) {
    vector<long long int> aux = Q.top();
    Q.pop();
    long long int d = -aux[0], v = aux[1], p = aux[2];
    if (dist[v] < d) continue;
    if (dist[v] == d) {
      if (rep[v] != rep[p]) rep[v] = v;
    }
    if (dist[v] > d) {
      dist[v] = d;
      rep[v] = rep[p];
      if (rep[v] == start) rep[v] = v;
      for (int i = 0; i < G[v].size(); ++i) {
        int u = G[v][i], w = W[v][i];
        if (u == p or dist[u] < d + w) continue;
        Q.push({-d - w, u, v});
      }
    }
  }
  vector<long long int> times(n, 0);
  for (int i = 0; i < n; ++i) {
    if (rep[i] == -1 or rep[i] == start) continue;
    ++times[rep[i]];
  }
  long long int ans = 0;
  for (int i = 0; i < n; ++i) ans = max(ans, times[i]);
  return ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m, c;
  cin >> n >> m >> c;
  --c;
  G = W = vector<vector<long long int> >(n);
  for (int i = 0; i < m; ++i) {
    long long int x, y, w;
    cin >> x >> y >> w;
    --x;
    --y;
    G[x].push_back(y);
    G[y].push_back(x);
    W[x].push_back(w);
    W[y].push_back(w);
  }
  cout << solve(n, c) << endl;
}
