Otvio is a calm guy with a guilty pleasure: kicking PCs. Now he is participating in a programming competition where the computers are arranged as a tree, that is, the N PCs are connected by N - 1 cables and there is only one cable path from one PC to another.
Otvio wants to kick as many PCs as possible. To do so, he will walk along a cable path, kicking all the PCs in the path. He will start at PC a, the one he will use in the contest. However, to prevent getting caught, he will not pass by PCs he already kicked nor kick any PC twice.
Laerco, knowing Otvio’s guilty pleasure, wants to know the maximum number of PCs Otvio can kick satisfying the conditions above. Remember that Otvio will kick his own PC for sure.
Input
The first line of the input consist of two integers integer N and a (1 ≤ N, a ≤ 105), the number of PCs in the contest and the number of Otvio’s PC, in this order. Each of the next N - 1 lines contains two integers u and v (1 ≤ u, v ≤ N), indicating that there is a cable connecting PCs u and v.
Output
Output a single integer - the maximum number of PCs Otvio can kick.
Example
Input
5 2
1 2
1 3
2 5
3 4
Output
4
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = 1e5 + 10;
struct cnode
{
int v;
int next;
}edg[maxn << 1];
int head[maxn << 1];
int vis[maxn];
int tot;
void add(int u, int v)
{
edg[tot].v = v;
edg[tot].next = head[u];
head[u] = tot++;
}
int dfs(int u)
{
int ans = 1;
vis[u] = 1;
for(int i = head[u]; i != 1; i = edg[i].next)
{
int v = edg[i].v;
if(vis[v] == 0)
{
ans = max(ans,dfs(v)+1);
}
}
return ans;
}
int main()
{
int n, s;
scanf("%d %d",&n,&s);
memset(head, -1, sizeof(head));
for(int i = 1; i <= n - 1; i++)
{
int x, y;
scanf("%d %d",&x,&y);
add(x,y);
add(y,x);
}
int z = dfs(s);
printf("%d\n",z);
return 0;
}