#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using pii = pair<ll, ll>;
const ll maxN = 201005;
const ll MAXLOG = 20;
struct BinaryLifting {
  ll BL[maxN][MAXLOG];
  ll D[maxN];
  void init(ll root) { D[root] = 1; }
  void insert(ll n, ll par) {
    D[n] = D[par] + 1;
    BL[n][0] = par;
    for (ll j = (1); j < ll(MAXLOG); j++) BL[n][j] = BL[BL[n][j - 1]][j - 1];
  }
  ll lift(ll node, ll h) {
    ll cnt = 0;
    while (h) {
      if (h & 1) node = BL[node][cnt];
      cnt++;
      h >>= 1;
    }
    return node;
  }
  int lca(int a, int b) {
    if (D[a] > D[b]) swap(a, b);
    for (ll i = (MAXLOG)-1; i >= ll(0); i--)
      if (D[BL[b][i]] >= D[a]) b = BL[b][i];
    if (a == b) return a;
    for (ll i = (MAXLOG)-1; i >= ll(0); i--)
      if (BL[a][i] != BL[b][i]) a = BL[a][i], b = BL[b][i];
    return BL[a][0];
  }
};
vector<pii> adj[maxN];
ll dist[maxN];
bool visited[maxN];
vector<ll> adj2[maxN];
ll indeg[maxN];
ll imdom[maxN];
vector<ll> adjdom[maxN];
BinaryLifting bl;
void domdfs(ll cur) {
  for (auto o : adj2[cur]) {
    if (imdom[o] == -1) {
      imdom[o] = cur;
    } else {
      imdom[o] = bl.lca(cur, imdom[o]);
    }
    indeg[o]--;
    if (!indeg[o]) {
      adjdom[imdom[o]].push_back(o);
      bl.insert(o, imdom[o]);
      domdfs(o);
    }
  }
}
ll coun[maxN];
void countc2(ll cur) {
  ll c = 1;
  for (auto o : adjdom[cur]) {
    countc2(o);
    c += coun[o];
  }
  coun[cur] = c;
}
ll countc(ll cur) {
  ll c = 1;
  for (auto o : adjdom[cur]) {
    c += countc(o);
  }
  return c;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, m, s;
  cin >> n >> m >> s;
  for (ll i = (0); i < ll(m); i++) {
    ll a, b, c;
    cin >> a >> b >> c;
    adj[a].emplace_back(b, c);
    adj[b].emplace_back(a, c);
  }
  memset(dist, 0x3f, sizeof(dist));
  dist[s] = 0;
  priority_queue<pii, vector<pii>, greater<pii>> pq;
  pq.push(make_pair(0, s));
  while (!pq.empty()) {
    ll cur = pq.top().second;
    pq.pop();
    if (visited[cur]) continue;
    visited[cur] = true;
    for (auto &o : adj[cur]) {
      if (dist[o.first] > dist[cur] + o.second) {
        dist[o.first] = dist[cur] + o.second;
        pq.push(make_pair(dist[o.first], o.first));
      }
    }
  }
  for (ll i = (1); i < ll(n + 1); i++) {
    if (0) cout << i << ": " << dist[i] << endl;
    for (auto &o : adj[i]) {
      if (dist[i] + o.second == dist[o.first]) {
        adj2[i].push_back(o.first);
        indeg[o.first] += 1;
      }
    }
  }
  memset(imdom, -1, sizeof(imdom));
  bl.init(s);
  domdfs(s);
  ll res = 0;
  countc2(s);
  for (ll i = (1); i < ll(n + 1); i++) {
    if (i != s && dist[i] < (1ll << 50)) res = max(coun[i], res);
  }
  cout << res << endl;
}
