#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
int n, m, s;
int pre[maxn * 2], last[maxn], other[maxn * 2], l;
long long len[maxn * 2];
int pre2[maxn * 2], last2[maxn], other2[maxn * 2], l2;
int pre3[maxn * 2], last3[maxn], other3[maxn * 2], l3;
int pre4[maxn * 2], last4[maxn], other4[maxn * 2], l4;
void add(int x, int y, long long z) {
  l++;
  pre[l] = last[x];
  last[x] = l;
  other[l] = y;
  len[l] = z;
}
void add2(int x, int y) {
  l2++;
  pre2[l2] = last2[x];
  last2[x] = l2;
  other2[l2] = y;
}
void add3(int x, int y) {
  l3++;
  pre3[l3] = last3[x];
  last3[x] = l3;
  other3[l3] = y;
}
void add4(int x, int y) {
  l4++;
  pre4[l4] = last4[x];
  last4[x] = l4;
  other4[l4] = y;
}
priority_queue<pair<long long, int> > qq;
bool vis[maxn];
long long dis[maxn];
void dijkstra(int x) {
  memset(vis, 0, sizeof(vis));
  memset(dis, 0x3f, sizeof(dis));
  dis[x] = 0;
  qq.push(make_pair(0, x));
  while (!qq.empty()) {
    int u = qq.top().second;
    qq.pop();
    if (vis[u]) continue;
    vis[u] = 1;
    for (int p = last[u]; p; p = pre[p]) {
      int v = other[p];
      if (dis[v] > dis[u] + len[p]) {
        dis[v] = dis[u] + len[p];
        qq.push(make_pair(-dis[v], v));
      }
    }
  }
}
queue<int> q;
int topo[maxn], sum, in_eage[maxn];
void toposort() {
  for (int i = 1; i <= n; i++) {
    if (in_eage[i] == 0 && dis[i] != dis[0]) q.push(i);
  }
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    topo[++sum] = x;
    for (int p = last2[x]; p; p = pre2[p]) {
      int v = other2[p];
      in_eage[v]--;
      if (in_eage[v] == 0) {
        q.push(v);
      }
    }
  }
}
int father[maxn], f[maxn][200];
int dep[maxn];
void rmq(int x) {
  f[x][0] = father[x];
  for (int i = 1; i <= 17; i++) {
    f[x][i] = f[f[x][i - 1]][i - 1];
  }
}
int LCA(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  for (int j = 0; j <= 17; j++) {
    if ((dep[x] - dep[y]) & (1 << j)) x = f[x][j];
  }
  if (x == y) return x;
  for (int j = 17; j >= 0; j--) {
    if (f[x][j] != f[y][j]) {
      x = f[x][j];
      y = f[y][j];
    }
  }
  return father[x];
}
void build() {
  father[n + 1] = n + 1;
  f[n + 1][0] = n + 1;
  dep[n + 1] = 1;
  for (int i = 1; i <= n; i++) {
    if (!topo[i]) continue;
    int x = topo[i];
    if (!last4[x]) {
      dep[x] = 2;
      father[x] = n + 1;
      f[x][0] = n + 1;
      add3(n + 1, x);
      continue;
    }
    int lca = other4[last4[x]];
    for (int p = last4[x]; p; p = pre4[p]) {
      int v = other4[p];
      lca = LCA(lca, v);
    }
    father[x] = lca;
    dep[x] = dep[lca] + 1;
    add3(lca, x);
    rmq(x);
  }
}
int siz[maxn];
int ans;
void dfs(int x) {
  siz[x] = 1;
  for (int p = last3[x]; p; p = pre3[p]) {
    int v = other3[p];
    dfs(v);
    siz[x] += siz[v];
  }
  if (x != n + 1 && x != s) ans = max(ans, siz[x]);
}
int main() {
  scanf("%d%d%d", &n, &m, &s);
  for (int i = 1; i <= m; i++) {
    int x, y;
    long long z;
    scanf("%d%d%lld", &x, &y, &z);
    add(x, y, z);
    add(y, x, z);
  }
  dijkstra(s);
  for (int i = 1; i <= n; i++) {
    for (int p = last[i]; p; p = pre[p]) {
      int v = other[p];
      if (dis[v] == dis[i] + len[p]) {
        add2(i, v);
        add4(v, i);
        in_eage[v]++;
      }
    }
  }
  toposort();
  build();
  dfs(n + 1);
  printf("%d", ans);
  return 0;
}
