#include<bits/stdc++.h> usingnamespace std; #define ll long long #define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define maxn 2005 #define int long long structnode{ int x,y,z; int id; }; node a[maxn]; boolcmp(node c,node b){ if(c.x!=b.x)return c.x<b.x; if(c.y!=b.y)return c.y<b.y; return c.z<b.z; } int vis[maxn]={0}; intdis( node c, node d){ return (c.x-d.x)*(c.x-d.x)+(c.y-d.y)*(c.y-d.y)+(c.z-d.z)*(c.z-d.z); } signedmain(){ IOS int n; cin>>n; for (int i = 1; i <=n ; ++i) { cin>>a[i].x>>a[i].y>>a[i].z; a[i].id=i; } sort(a+1,a+1+n,cmp); int cnt=0,tmp=1; while(cnt!=n){ for (int k = 1; k <=n ; ++k) { if(vis[k]==0){ tmp=k; break; } }vis[tmp]=1; int mi=0x3f3f3f3f3f3f3f3f; int pos=1; for (int i = 1; i <=n ; ++i) { if(dis(a[i],a[tmp])<mi&&vis[i]==0){ mi=dis(a[i],a[tmp]); pos=i; } } vis[pos]=1;