#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > v[200010];
vector<int> g[200010], ig[200010];
long long dis[200010];
bool vis[200010];
int deg[200010];
vector<int> T[200010];
void dijkstra(int st) {
  priority_queue<pair<long long, int>, vector<pair<long long, int> >,
                 greater<pair<long long, int> > >
      q;
  memset(dis, 0x3f, sizeof(dis));
  dis[st] = 0;
  q.push(make_pair(0, st));
  while (!q.empty()) {
    pair<long long, int> fr = q.top();
    q.pop();
    if (dis[fr.second] != fr.first) continue;
    vis[fr.second] = 1;
    for (pair<int, int> x : v[fr.second]) {
      if (dis[x.first] > fr.first + x.second) {
        dis[x.first] = fr.first + x.second;
        q.push(make_pair(dis[x.first], x.first));
      }
    }
  }
}
int n, m, st, siz[200010], fa[200010][19], dep[200010];
void getst(int pos) {
  dep[pos] = dep[fa[pos][0]] + 1;
  for (int i = 1; i <= 18; i++) fa[pos][i] = fa[fa[pos][i - 1]][i - 1];
}
inline int lca(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  for (int i = 18; i >= 0; i--) {
    if (dep[fa[x][i]] >= dep[y]) x = fa[x][i];
  }
  if (x == y) return x;
  for (int i = 18; i >= 0; i--)
    if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];
  return fa[x][0];
}
void dfs(int np) {
  siz[np] = 1;
  for (int x : T[np]) dfs(x), siz[np] += siz[x];
}
int main() {
  scanf("%d%d%d", &n, &m, &st);
  for (int i = 1, ti, tj, tk; i <= m; i++) {
    scanf("%d%d%d", &ti, &tj, &tk);
    v[ti].push_back(make_pair(tj, tk));
    v[tj].push_back(make_pair(ti, tk));
  }
  dijkstra(st);
  for (int i = 1; i <= n; i++) {
    if (vis[i]) {
      for (pair<int, int> x : v[i]) {
        if (vis[x.first] && dis[x.first] == dis[i] + x.second)
          ig[x.first].push_back(i), g[i].push_back(x.first), deg[x.first]++;
      }
    }
  }
  queue<int> q;
  dep[n + 1] = 1;
  for (int i = 1; i <= n; i++) {
    if (vis[i] && !deg[i]) {
      fa[i][0] = n + 1;
      T[n + 1].push_back(i);
      getst(i);
      q.push(i);
    }
  }
  while (!q.empty()) {
    int fr = q.front();
    q.pop();
    for (int x : g[fr]) {
      deg[x]--;
      if (!deg[x]) {
        int l = -1;
        for (int k : ig[x])
          if (vis[k]) {
            if (l == -1)
              l = k;
            else
              l = lca(l, k);
          }
        fa[x][0] = l;
        T[l].push_back(x);
        getst(x);
        q.push(x);
      }
    }
  }
  dfs(n + 1);
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (vis[i] && i != st) ans = max(ans, siz[i]);
  }
  printf("%d\n", ans);
  return 0;
}
