#include "migrations.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 10005;
vector<int> con[MAXN];
int one, two;
bool print = false;
pair<int, int> most_dist(int curr, int par)
{
pair<int, int> res = {1, curr};
for (auto i : con[curr])
{
if (i != par)
{
auto temp = most_dist(i, curr);
if (temp.first + 1 > res.first)
res = temp;
}
}
return res;
}
int send_message(int n, int i, int p)
{
con[i].push_back(p), con[p].push_back(i);
if (i < n - 2)
return 0;
if (i == n - 2)
{
one = most_dist(0, -1).second;
two = most_dist(one, -1).second;
return one;
}
print = true;
pair<int, int> a = most_dist(one, -1);
print = false;
pair<int, int> b = most_dist(two, -1);
if (a.first > b.first)
return a.second;
return n + two;
}
std::pair<int, int> longest_path(std::vector<int> s)
{
int n = s.size();
int last = s[n - 1], prev = s[n - 2];
if (last >= n)
return {last - n, n - 1};
return {prev, last};
}