#include <bits/stdc++.h>
using namespace std;
vector<long long int> g[200001], rg[200001];
bool vis[200001];
long long int par[200001];
long long int sz[200001], dnom[200001];
long long int ans = 0, no = 0;
long long int n, m, S;
deque<long long int> top;
void dfs(long long int x) {
  vis[x] = 1;
  for (auto v : g[x]) {
    if (!vis[v]) dfs(v);
  }
  top.push_front(x);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m >> S;
  S--;
  vector<pair<long long int, long long int> > g1[n];
  long long int dis[n];
  for (int i = 0; i < n; i++) {
    dis[i] = LLONG_MAX / 2;
  }
  for (int i = 0; i < m; i++) {
    long long int u, v, w;
    cin >> u >> v >> w;
    u--;
    v--;
    g1[u].push_back({v, w});
    g1[v].push_back({u, w});
  }
  set<pair<long long int, long long int> > second;
  second.insert({0, S});
  dis[S] = 0;
  while (!second.empty()) {
    pair<long long int, long long int> p = *second.begin();
    second.erase(second.begin());
    if (vis[p.second]) continue;
    vis[p.second] = 1;
    long long int cd = p.first, u = p.second;
    for (auto v : g1[u]) {
      if (cd == dis[v.first] + v.second) {
        g[v.first].push_back(u);
        rg[u].push_back(v.first);
      }
      if (dis[v.first] > cd + v.second) {
        dis[v.first] = cd + v.second;
        second.insert({dis[v.first], v.first});
      }
    }
  }
  memset(vis, 0, sizeof(vis));
  dfs(S);
  long long int ans = 0;
  dnom[top[0]] = -1;
  for (int i = 1; i < top.size(); i++) {
    long long int u = top[i];
    long long int x = dnom[rg[u][0]];
    bool flag = 1;
    for (auto par : rg[u]) {
      if (dnom[par] != x) {
        flag = 0;
        break;
      }
    }
    if (!flag || x == -1)
      dnom[u] = u;
    else
      dnom[u] = x;
    sz[dnom[u]]++;
    ans = max(ans, sz[dnom[u]]);
  }
  cout << ans;
}
