文件目录

#include <bits/stdc++.h>
using namespace std;
int n, p, c, m, s, t;
vector<int> e[100050];
struct node
{
    int num;
    int step;
};
bool vis[100050];
int ans = 0;
void bfs(int x)
{
    queue<node> q;
    q.push({x, 1});
    vis[x] = 1;
    while (!q.empty())
    {
        node u = q.front();
        q.pop();
        int num = u.num, step = u.step;
        ans = max(ans, step);
        for (int i = 0; i < e[num].size(); i++)
        {
            int v = e[num][i];
            if (vis[v])
                continue;
            vis[v] = 1;
            q.push({v, step + 1});
        }
    }
}
int main()
{
    cin >> n >> p >> c >> m;
    while (p--)
    {
        cin >> s >> t;
        e[s].push_back(t);
        e[t].push_back(s);
    }
    bfs(c);
    cout << ans + m;
    return 0;
}