#include <bits/stdc++.h>
struct edge {
  int to, nxt, co;
} e1[300005 << 1], e2[300005], e3[300005], e4[300005];
int n, m, s, N, dfn[300005], hdfs[300005], tf[300005], fa[300005], val[300005],
    ans[300005], Ans;
int sdom[300005], idom[300005];
long long dis[300005];
int h1[300005], h2[300005], h3[300005], h4[300005];
int cnt1, cnt2, cnt3, cnt4;
std::priority_queue<std::pair<long long, int>,
                    std::vector<std::pair<long long, int> >,
                    std::greater<std::pair<long long, int> > >
    pq;
int Min(int x, int y) { return dfn[x] < dfn[y] ? x : y; }
void ins(int x, int y, int co, edge *e, int *h, int &cnt) {
  e[++cnt].nxt = h[x];
  h[x] = cnt;
  e[cnt].to = y;
  e[cnt].co = co;
}
void find(int x) {
  if (fa[x] == x) return;
  find(fa[x]);
  val[x] = dfn[sdom[val[x]]] < dfn[sdom[val[fa[x]]]] ? val[x] : val[fa[x]];
  fa[x] = fa[fa[x]];
}
void dijsktra() {
  for (int i = 1; i <= n; i++) dis[i] = 30000000000000000ll;
  dis[s] = 0;
  pq.push(std::make_pair(0, s));
  for (; !pq.empty();) {
    std::pair<long long, int> x = pq.top();
    pq.pop();
    int fr = x.second;
    long long g = x.first;
    if (dis[fr] != g) continue;
    for (int i = h1[fr]; i; i = e1[i].nxt) {
      long long kk = e1[i].co + g;
      if (kk < dis[e1[i].to]) {
        dis[e1[i].to] = kk;
        pq.push(std::make_pair(kk, e1[i].to));
      }
    }
  }
  for (int i = 1; i <= n; i++)
    for (int j = h1[i]; j; j = e1[j].nxt)
      if (dis[i] + e1[j].co == dis[e1[j].to]) {
        ins(i, e1[j].to, 0, e2, h2, cnt2);
        ins(e1[j].to, i, 0, e3, h3, cnt3);
      }
}
void dfs(int x) {
  ans[x] = 1;
  hdfs[dfn[x] = ++N] = x;
  for (int i = h2[x]; i; i = e2[i].nxt)
    if (!dfn[e2[i].to]) {
      tf[e2[i].to] = x;
      dfs(e2[i].to);
    }
}
int main() {
  scanf("%d%d%d", &n, &m, &s);
  for (int i = 1; i <= m; i++) {
    int x, y, co;
    scanf("%d%d%d", &x, &y, &co);
    ins(x, y, co, e1, h1, cnt1);
    ins(y, x, co, e1, h1, cnt1);
  }
  dijsktra();
  for (int i = 1; i <= n; i++) fa[i] = val[i] = sdom[i] = i;
  dfs(s);
  for (int i = N; i > 1; i--) {
    int x = hdfs[i];
    for (int j = h3[x]; j; j = e3[j].nxt) {
      int y = e3[j].to;
      if (dfn[y] < i)
        sdom[x] = Min(sdom[x], y);
      else {
        find(y);
        sdom[x] = Min(sdom[x], sdom[val[y]]);
      }
    }
    ins(sdom[x], x, 0, e4, h4, cnt4);
    x = fa[x] = tf[x];
    for (int j = h4[x]; j; j = e4[j].nxt) {
      int y = e4[j].to;
      find(y);
      idom[y] = val[y];
    }
    h4[x] = 0;
  }
  for (int i = 2; i <= N; i++)
    if (idom[hdfs[i]] != sdom[hdfs[i]]) idom[hdfs[i]] = idom[idom[hdfs[i]]];
  for (int i = N; i > 1; i--)
    ans[idom[hdfs[i]]] += ans[hdfs[i]], Ans = std::max(Ans, ans[hdfs[i]]);
  printf("%d\n", Ans);
}
