#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const long long infLL = 1000000000000000000;
inline bool checkBit(long long n, int i) { return n & (1LL << i); }
inline long long setBit(long long n, int i) {
  return n | (1LL << i);
  ;
}
inline long long resetBit(long long n, int i) { return n & (~(1LL << i)); }
int dx[] = {0, 0, +1, -1};
int dy[] = {+1, -1, 0, 0};
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
inline bool isLeapYear(long long year) {
  return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0);
}
inline void normal(long long &a) {
  a %= 1000000007;
  (a < 0) && (a += 1000000007);
}
inline long long modMul(long long a, long long b) {
  a %= 1000000007, b %= 1000000007;
  normal(a), normal(b);
  return (a * b) % 1000000007;
}
inline long long modAdd(long long a, long long b) {
  a %= 1000000007, b %= 1000000007;
  normal(a), normal(b);
  return (a + b) % 1000000007;
}
inline long long modSub(long long a, long long b) {
  a %= 1000000007, b %= 1000000007;
  normal(a), normal(b);
  a -= b;
  normal(a);
  return a;
}
inline long long modPow(long long b, long long p) {
  long long r = 1;
  while (p) {
    if (p & 1) r = modMul(r, b);
    b = modMul(b, b);
    p >>= 1;
  }
  return r;
}
inline long long modInverse(long long a) { return modPow(a, 1000000007 - 2); }
inline long long modDiv(long long a, long long b) {
  return modMul(a, modInverse(b));
}
long long dm[200100], dst[200100], n, m, st;
vector<vector<long long> > pr, g2;
vector<vector<pair<long long, long long> > > g;
bool vis[200100];
void dijkxtra(long long src) {
  long long i, j;
  dst[st] = 0LL;
  priority_queue<pair<long long, long long> > pq;
  pq.push(pair<long long, long long>(0, src));
  while (!pq.empty()) {
    pair<long long, long long> x = pq.top();
    long long sz = (long long)g[x.second].size();
    pq.pop();
    x.first *= (-1);
    for (i = 0; i < sz; ++i) {
      j = g[x.second][i].first;
      if (dst[j] > dst[x.second] + g[x.second][i].second) {
        dst[j] = dst[x.second] + g[x.second][i].second;
        pq.push(pair<long long, long long>(-dst[j], j));
      }
    }
  }
}
long long idg[200100], lv[200100];
vector<long long> ts;
void topsort(void) {
  long long i, j, s = st;
  queue<long long> q;
  q.push(s);
  while (!q.empty()) {
    s = q.front();
    q.pop();
    ts.push_back(s);
    long long sz = (long long)g2[s].size();
    for (i = 0; i < sz; ++i) {
      j = g2[s][i];
      --idg[j];
      if (idg[j] == 0) q.push(j);
    }
  }
}
long long lca[200100][22];
vector<vector<long long> > tr;
void topsort1(long long u) {
  if (vis[u]) return;
  vis[u] = true;
  for (auto v : g2[u])
    if (!vis[v]) topsort1(v);
  ts.push_back(u);
}
int query(long long p, long long q) {
  if (lv[p] < lv[q]) swap(p, q);
  long long i, j;
  for (i = 20; i >= 0; i--) {
    if (lca[p][i] != -1 && lv[lca[p][i]] >= lv[q]) {
      p = lca[p][i];
    }
  }
  if (p == q) return p;
  for (i = 20; i >= 0; i--) {
    if (lca[p][i] != -1) {
      if (lca[p][i] != lca[q][i]) {
        p = lca[p][i];
        q = lca[q][i];
      }
    }
  }
  return lca[p][0];
}
long long sbtreesz[200100], ans = -1;
long long dfs(long long u, long long parr = -1) {
  long long i, j, sz = (long long)tr[u].size();
  sbtreesz[u] = 1;
  for (i = 0; i < sz; ++i) {
    j = tr[u][i];
    if (j - parr) sbtreesz[u] += dfs(j, u);
  }
  return sbtreesz[u];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cout.unsetf(ios::floatfield);
  cout.precision(10);
  cout.setf(ios::fixed, ios::floatfield);
  ;
  cin >> n >> m >> st;
  long long i, j, sz;
  memset(lca, -1LL, sizeof(lca));
  fill(dst, dst + 200100, infLL);
  g.resize(n + 10);
  pr.resize(n + 10);
  memset(idg, 0, sizeof(idg));
  memset(vis, false, sizeof(vis));
  for (i = 0; i < m; ++i) {
    long long c, a, b;
    cin >> a >> b >> c;
    g[a].push_back(pair<long long, long long>(b, c));
    g[b].push_back(pair<long long, long long>(a, c));
  }
  dijkxtra(st);
  g2.resize(n + 10);
  memset(idg, 0LL, sizeof(idg));
  pr.clear();
  pr.resize(n + 10LL);
  for (i = 1; i <= n; ++i) {
    for (pair<long long, long long> v : g[i]) {
      if (dst[i] + v.second == dst[v.first]) {
        g2[i].push_back(v.first);
        pr[v.first].push_back(i);
      }
    }
    g[i].clear();
  }
  memset(vis, false, sizeof(vis));
  topsort1(st);
  tr.clear();
  tr.resize(n + 10);
  sz = (long long)ts.size();
  memset(dm, -1, sizeof(dm));
  lv[ts[sz - 1LL]] = 0;
  for (i = sz - 2; i >= 0; --i) {
    j = ts[i];
    long long sz2 = (long long)pr[ts[i]].size();
    long long lc;
    for (long long k = 0; k < sz2; ++k) {
      if (k == 0) {
        lc = pr[ts[i]][k];
        continue;
      }
      lc = query(lc, pr[ts[i]][k]);
    }
    dm[j] = lc;
    lv[j] = lv[lc] + 1;
    lca[j][0] = lc;
    for (long long k = 1; k <= 20; k++) {
      if (lca[j][k - 1] != -1) {
        lca[j][k] = lca[lca[j][k - 1]][k - 1];
      }
    }
  }
  for (i = 1; i <= n; ++i) {
    if (dm[i] + 1) tr[dm[i]].push_back(i);
  }
  memset(sbtreesz, 0, sizeof(sbtreesz));
  dfs(st, -1);
  for (i = 1; i <= n; ++i)
    if (i != st) ans = max(ans, sbtreesz[i]);
  cout << max(0LL, ans);
}
