#include <bits/stdc++.h>
using namespace std;
template <typename T>
T BigMod(T b, T p, T m) {
  if (p == 0) return 1;
  if (p % 2 == 0) {
    T s = BigMod(b, p / 2, m);
    return ((s % m) * (s % m)) % m;
  }
  return ((b % m) * (BigMod(b, p - 1, m) % m)) % m;
}
template <typename T>
T ModInv(T b, T m) {
  return BigMod(b, m - 2, m);
}
template <typename T>
T in() {
  char ch;
  T n = 0;
  bool ng = false;
  while (1) {
    ch = getchar();
    if (ch == '-') {
      ng = true;
      ch = getchar();
      break;
    }
    if (ch >= '0' && ch <= '9') break;
  }
  while (1) {
    n = n * 10 + (ch - '0');
    ch = getchar();
    if (ch < '0' || ch > '9') break;
  }
  return (ng ? -n : n);
}
template <typename T>
T POW(T B, T printf) {
  if (printf == 0) return 1;
  if (printf & 1)
    return B * POW(B, printf - 1);
  else
    return (POW(B, printf / 2) * POW(B, printf / 2));
}
template <typename T>
T Bigmod(T b, T p, T m) {
  if (p == 0)
    return 1;
  else if (!(p & 1))
    return (Bigmod(b, p / 2, m) * Bigmod(b, p / 2, m)) % m;
  else
    return ((b % m) * Bigmod(b, p - 1, m)) % m;
}
template <typename T>
T Dis(T x1, T y1, T x2, T y2) {
  return sqrt((x1 - x2 * x1 - x2) + (y1 - y2 * y1 - y2));
}
template <typename T>
T Angle(T x1, T y1, T x2, T y2) {
  return atan(double(y1 - y2) / double(x1 - x2));
}
template <typename T>
T DIFF(T a, T b) {
  T d = a - b;
  if (d < 0)
    return -d;
  else
    return d;
}
template <typename T>
T ABS(T a) {
  if (a < 0)
    return -a;
  else
    return a;
}
template <typename T>
T gcd(T a, T b) {
  if (a < 0) return gcd(-a, b);
  if (b < 0) return gcd(a, -b);
  return (b == 0) ? a : gcd(b, a % b);
}
template <typename T>
T lcm(T a, T b) {
  if (a < 0) return lcm(-a, b);
  if (b < 0) return lcm(a, -b);
  return a * (b / gcd(a, b));
}
template <typename T>
T euclide(T a, T b, T &x, T &y) {
  if (a < 0) {
    T d = euclide(-a, b, x, y);
    x = -x;
    return d;
  }
  if (b < 0) {
    T d = euclide(a, -b, x, y);
    y = -y;
    return d;
  }
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  } else {
    T d = euclide(b, a % b, x, y);
    T t = x;
    x = y;
    y = t - (a / b) * y;
    return d;
  }
}
template <typename T>
void ia(T a[], int n) {
  for (int i = 0; i < n; i++) cin >> a[i];
}
template <typename T>
void pa(T a[], int n) {
  for (int i = 0; i < n - 1; i++) cout << a[i] << " ";
  cout << a[n - 1] << endl;
}
template <typename T>
long long int isLeft(T a, T b, T c) {
  return (a.x - b.x) * (b.y - c.y) - (b.x - c.x) * (a.y - b.y);
}
int Set(int N, int pos) { return N = N | (1 << pos); }
int Reset(int N, int pos) { return N = N & ~(1 << pos); }
bool Check(int N, int pos) { return (bool)(N & (1 << pos)); }
template <class T, class first>
inline T togglebit(T a, first i) {
  T t = 1;
  return (a ^ (t << i));
}
int toInt(string s) {
  int sm;
  stringstream ss(s);
  ss >> sm;
  return sm;
}
int toLlint(string s) {
  long long int sm;
  stringstream ss(s);
  ss >> sm;
  return sm;
}
int cdigittoint(char ch) { return ch - '0'; }
bool isVowel(char ch) {
  ch = toupper(ch);
  if (ch == 'A' || ch == 'U' || ch == 'I' || ch == 'O' || ch == 'E')
    return true;
  return false;
}
bool isConst(char ch) {
  if (isalpha(ch) && !isVowel(ch)) return true;
  return false;
}
double DEG(double x) { return (180.0 * x) / (2.0 * acos(0.0)); }
double RAD(double x) { return (x * (double)2.0 * acos(0.0)) / (180.0); }
vector<int> adj[200007], dag[200007], par[200007];
int DP[200007][18], siz[200007];
long long int dis[200007];
int L[200007];
int inDeg[200007];
bool vis[200007];
void Init(int n) {
  for (int i = 0; i <= n; i++) {
    dis[i] = 1LL << 60;
    adj[i].clear();
    dag[i].clear();
    par[i].clear();
    inDeg[i] = siz[i] = vis[i] = 0;
    for (int j = 0; j < 18; j++) DP[i][j] = -1;
  }
}
void Update(int u, int p) {
  DP[u][0] = p;
  L[u] = L[p] + 1;
  adj[p].push_back(u);
  for (int i = 1; i < 18; i++)
    if (DP[u][i - 1] != -1) DP[u][i] = DP[DP[u][i - 1]][i - 1];
}
int LCA(int p, int q) {
  if (L[p] < L[q]) swap(p, q);
  for (int i = 18 - 1; i >= 0; i--)
    if (L[p] - (1 << i) >= L[q]) p = DP[p][i];
  if (p == q) return p;
  for (int i = 18 - 1; i >= 0; i--)
    if (DP[p][i] != -1 && DP[p][i] != DP[q][i]) {
      p = DP[p][i];
      q = DP[q][i];
    }
  return DP[p][0];
}
void Dijkstra(int n, int s) {
  set<pair<long long int, long long int> > pq;
  pq.insert(make_pair(0, s));
  dis[s] = 0;
  L[s] = 1;
  while (!pq.empty()) {
    pair<long long int, long long int> tmp = *pq.begin();
    pq.erase(pq.begin());
    int u = tmp.second;
    for (int i = 0; i < adj[u].size(); i += 2) {
      int v = adj[u][i];
      int w = adj[u][i + 1];
      if (dis[v] > dis[u] + w) {
        dis[v] = dis[u] + w;
        pq.insert(make_pair(dis[v], v));
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < adj[i].size(); j += 2) {
      int v = adj[i][j];
      int w = adj[i][j + 1];
      if (dis[i] + w == dis[v]) {
        inDeg[v]++;
        dag[i].push_back(v);
        par[v].push_back(i);
      }
    }
    adj[i].clear();
  }
}
void TopSort(int s) {
  queue<int> q;
  q.push(s);
  L[s] = 1;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    if (!par[u].empty()) {
      int lca = par[u][0];
      for (int i = 1; i < par[u].size(); i++) {
        lca = LCA(lca, par[u][i]);
      }
      Update(u, lca);
    }
    for (int i = 0; i < dag[u].size(); i++) {
      int v = dag[u][i];
      inDeg[v]--;
      if (!inDeg[v]) q.push(v);
    }
  }
}
void Dfs(int u) {
  siz[u] = 1;
  vis[u] = 1;
  for (int i = 0; i < adj[u].size(); i++) {
    Dfs(adj[u][i]);
    siz[u] += siz[adj[u][i]];
  }
}
int main() {
  int n, m, s;
  scanf("%d%d%d", &n, &m, &s);
  Init(n);
  for (int i = 1; i <= m; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    adj[u].push_back(v);
    adj[u].push_back(w);
    adj[v].push_back(u);
    adj[v].push_back(w);
  }
  Dijkstra(n, s);
  TopSort(s);
  Dfs(s);
  int mx = 0;
  for (int i = 1; i <= n; i++) {
    if (i != s) mx = max(mx, siz[i]);
  }
  cout << mx << endl;
  return 0;
}
