#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
const int maxm = 3e5 + 5;
const long long inf = 0x3f3f3f3f3f3f3f3fll;
int uu[maxm], vv[maxm], ww[maxm];
int up[maxn][20], dep[maxn], siz[maxn];
long long dist[maxn];
bool vis[maxn];
struct ads {
  int v, w;
};
struct node {
  int u;
  long long d;
  friend bool operator<(node a, node b) { return a.d > b.d; }
};
vector<vector<ads> > edge(maxn);
vector<vector<int> > vec(maxn), nedge(maxn);
void djstra(int s) {
  memset(dist, 0x3f, sizeof(dist));
  queue<int> q;
  q.push(s);
  dist[s] = 0;
  vis[s] = 1;
  int u;
  while (!q.empty()) {
    u = q.front();
    q.pop();
    vis[u] = 0;
    for (int i = 0; i < edge[u].size(); i++) {
      int v = edge[u][i].v, w = edge[u][i].w;
      if (dist[u] + w < dist[v]) {
        dist[v] = dist[u] + w;
        if (!vis[v]) q.push(v), vis[v] = 1;
      }
    }
  }
  return;
}
int lca(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  for (int i = 17; i >= 0; i--)
    if (dep[u] - (1 << i) >= dep[v]) u = up[u][i];
  if (u == v) return u;
  for (int i = 17; i >= 0; i--)
    if (up[u][i] != up[v][i]) u = up[u][i], v = up[v][i];
  return up[u][0];
}
void dfs(int u, int pat) {
  siz[u] = 1;
  for (int i = 0; i < vec[u].size(); i++) {
    int v = vec[u][i];
    if (v == pat) continue;
    dfs(v, u);
    siz[u] += siz[v];
  }
  return;
}
int main() {
  int n, m, s;
  scanf("%d%d%d", &n, &m, &s);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &uu[i], &vv[i], &ww[i]);
    edge[uu[i]].push_back((ads){vv[i], ww[i]});
    edge[vv[i]].push_back((ads){uu[i], ww[i]});
  }
  djstra(s);
  for (int i = 1; i <= m; i++) {
    int u = uu[i], v = vv[i], w = ww[i];
    if (dist[u] + w == dist[v]) {
      nedge[u].push_back(v);
      dep[v]++;
    }
    if (dist[v] + w == dist[u]) {
      nedge[v].push_back(u);
      dep[u]++;
    }
  }
  memset(up, -1, sizeof(up));
  queue<int> q;
  for (int i = 1; i <= n; i++) {
    if (!dep[i] && dist[i] != inf) {
      up[i][0] = 0, q.push(i);
    } else
      up[i][0] = -1;
  }
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    dep[u] = dep[up[u][0]] + 1;
    for (int i = 1; (1 << i) < dep[u]; i++) up[u][i] = up[up[u][i - 1]][i - 1];
    for (int i = 0; i < nedge[u].size(); i++) {
      int v = nedge[u][i];
      if (up[v][0] == -1)
        up[v][0] = u;
      else
        up[v][0] = lca(up[v][0], u);
      dep[v]--;
      if (!dep[v]) q.push(v);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (up[i][0] != -1) {
      vec[i].push_back(up[i][0]);
      vec[up[i][0]].push_back(i);
    }
  }
  dfs(0, 0);
  int ans = -1;
  for (int i = 1; i <= n; i++) {
    if (i == s) continue;
    ans = max(ans, siz[i]);
  }
  printf("%d\n", ans);
  return 0;
}
