#include"diameter.h"
#include<bits/stdc++.h>
#define L(i, a, b) for (int i = (a); i <= (b); i++)
#define R(i, a, b) for (int i = (a); i >= (b); i--)
using namespace std;
pair<int, int> find_diameter(int subid, int n){
const int inf = 1e18;
if (n == 1) return {1, 1};
if (n == 2) return {1, 2};
if (n == 3){
if (in(1, 2, 3)) return {2, 3};
if (in(2, 1, 3)) return {1, 3};
return {1, 2};
}
int mx = 0, p = 0;
L(i, 3, n){
int ret = query(1, 2, i);
if (ret > mx){
mx = ret;
p = i;
}
}
int x = p;
mx = p = 0;
L(i, 1, n){
if ((i ^ 2) && (i ^ x)){
int ret = query(2, x, i);
if (ret > mx){
mx = ret;
p = i;
}
}
}
int y = p;
return {x, y};
mx = p = 0;
int mn = inf / 2;
L(i, 1, n){
if ((i ^ x) && (i ^ y)){
int ret = query(x, y, i);
ckmin(mn, ret);
if (ret > mx){
mx = ret;
p = i;
}
}
}
}