#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e17;
const int N = 200005;
const int LGN = 20;
int n, m, s;
vector<pair<int, int> > adj[N];
vector<long long> dis(N, INF);
int par[LGN][N];
vector<int> treeAdj[N];
int sz[N];
vector<int> shor[N];
int depth[N];
inline int LCA(int u, int v) {
  if (depth[u] > depth[v]) swap(u, v);
  for (int h = LGN - 1; h >= 0 && depth[v] > depth[u]; h--)
    if (depth[par[h][v]] >= depth[u]) v = par[h][v];
  if (u == v) return u;
  for (int h = LGN - 1; h >= 0; h--)
    if (par[h][u] != par[h][v]) u = par[h][u], v = par[h][v];
  return par[0][u];
}
void dfs(int node, int par = 0) {
  sz[node] = 1;
  for (auto child : treeAdj[node]) {
    if (child != par) {
      dfs(child, node);
      sz[node] += sz[child];
    }
  }
}
int main() {
  scanf("%d%d%d", &n, &m, &s);
  int x, y, w;
  while (m--) {
    scanf("%d%d%d", &x, &y, &w);
    adj[x].push_back({y, w});
    adj[y].push_back({x, w});
  }
  set<pair<long long, int> > Qu;
  bool done[N];
  memset(done, false, sizeof done);
  dis[s] = 0;
  for (int i = 1; i <= n; i++) {
    Qu.insert({dis[i], i});
  }
  depth[s] = 1;
  while (!Qu.empty()) {
    int vertex = Qu.begin()->second;
    Qu.erase(Qu.begin());
    if (dis[vertex] == INF) {
      break;
    }
    done[vertex] = true;
    if (par[0][vertex]) {
      for (auto other : shor[vertex])
        par[0][vertex] = LCA(par[0][vertex], other);
      for (int h = 1; h < LGN; h++)
        par[h][vertex] = par[h - 1][par[h - 1][vertex]];
      depth[vertex] = depth[par[0][vertex]] + 1;
      treeAdj[par[0][vertex]].push_back(vertex);
    }
    for (auto ver : adj[vertex]) {
      if (!done[ver.first]) {
        if (dis[ver.first] > dis[vertex] + ver.second) {
          par[0][ver.first] = vertex;
          shor[ver.first].clear();
          Qu.erase({dis[ver.first], ver.first});
          dis[ver.first] = dis[vertex] + ver.second;
          Qu.insert({dis[ver.first], ver.first});
        } else if (dis[ver.first] == dis[vertex] + ver.second) {
          shor[ver.first].push_back(vertex);
        }
      }
    }
  }
  dfs(s);
  int ans = 0;
  for (auto child : treeAdj[s]) ans = max(ans, sz[child]);
  printf("%d\n", ans);
  return 0;
}
