- 2026suzhongcheng 的博客
temp by cs
- @ 2025-10-9 21:05:57
#include<bits/stdc++.h>
using namespace std;
vector<vector<int> > f(100005);
vector<int> h(100005,-1);
queue<int> q;
int n,p,c,i,j,t1,t2,C,maxs=0,u;
int main(){
cin>>n>>p>>c>>C;
for(i=0;i<p;i++){
cin>>t1>>t2;
f[t1].push_back(t2);
f[t2].push_back(t1);
}
h[c]=0;
q.push(c);
while(!q.empty()){
u=q.front();
q.pop();
for(int v:f[u]){
if(h[v]==-1){
h[v]=h[u]+1;
q.push(v);
}
}
}
for(i=1;i<=n;i++){
maxs=max(maxs,h[i]);
}
cout<<maxs+C+1;
return 0;
}
/*
4 3 1
2
1 2
2 3
1 4
*/