#include #include #define MAX 1000 // Maximální velikost vstupu #define INFTY 1000000000 // Nekonečno :-) typedef struct { // Pozice jednoho stromu int x, y; } tree; int N; // Počet stromů tree trees[MAX]; // Stromy tree temp[MAX]; // Pole pomocné víceúčelové // Minimum a druhá mocnina int min(int x, int y) { return (x < y) ? x : y; } int sqr(int x) { return x*x; } // Místo vzdáleností počítáme vždy jejich druhé mocniny, předpokládáme, že jsou 0, třídíme podle X, jinak podle Y. void merge(tree *a, int mid, int n, int by_x) { int i=0, j=mid, k=0; while (k < n) if (j >= n || i < mid && (by_x ? (a[i].x <= a[j].x) : (a[i].y <= a[j].y))) temp[k++] = a[i++]; else temp[k++] = a[j++]; for (i=0; i