//poj3099
题目给定了一个三维坐标系的若干个点,每个点找离自己最近已知的点连边,形成一棵树,求这棵树的重心
按题意建边后,两次dfs求出直径,由于边权都是1,直接再直径上找中点即可
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
const int N=1010;
int n,id[N],tot;
vector<int>G[N];
double x[N],y[N],z[N],dis[N][N];
double calc(int i,int j){
double dx=x[i]-x[j],dy=y[i]-y[j],dz=z[i]-z[j];
return sqrt(dx*dx+dy*dy+dz*dz);
}
void build(){
for(int i=2,k;i<=n;i++){
double mn=1e100;
for(int j=1;j<i;j++)
if(dis[id[i]][id[j]]<mn){mn=dis[id[i]][id[j]];k=j;}
G[id[i]].push_back(id[k]);
G[id[k]].push_back(id[i]);
}
}
int max_dis,st,ed,pre[N],path[N];
void dfs(int u,int fa,int len){
if(len>max_dis){max_dis=len;st=u;}
for(int i=0;i<G[u].size();i++)if(G[u][i]!=fa)dfs(G[u][i],u,len+1);
}
void dfs1(int u,int fa,int len){
pre[u]=fa;
if(len>max_dis){max_dis=len;ed=u;}
for(int i=0;i<G[u].size();i++)if(G[u][i]!=fa)dfs1(G[u][i],u,len+1);
}
int main(){
while(scanf("%d",&n) && n){
for(int i=1;i<=n;i++)G[i].clear();
for(int i=1;i<=n;i++){
scanf("%d%lf%lf%lf",&id[i],&x[i],&y[i],&z[i]);
for(int j=1;j<i;j++)dis[id[i]][id[j]]=calc(i,j);
}
build();
max_dis=0;dfs(id[1],-1,0);
max_dis=0;dfs1(st,-1,0);
tot=0;for(int i=ed;i!=-1;i=pre[i])path[++tot]=i;
int mid=(tot+1)/2;
if(tot%2==1) printf("%d\n",path[mid]);
else printf("%d %d\n",min(path[mid],path[mid+1]),max(path[mid],path[mid+1]));
}
return 0;
}