UnionFind() { memset(seq, 0, sizeof seq); } intFind(int x){ return !seq[x] ? x : (seq[x] = Find(seq[x])); } boolUnion(int x, int y){ x = Find(x); y = Find(y); if (x == y) returnfalse; seq[x] = y; returntrue; } } U;
doubleGetDist(int idx, int idy){ double ret = 0; int absx = std::abs(node[idx].x - node[idy].x); int absy = std::abs(node[idx].y - node[idy].y); ret = sqrt(absx * absx + absy * absy); return ret; }
int n, m, cnt; int monkey[MAXM];
doubleKruskal(){ std::sort(edge + 1, edge + 1 + cnt); int tot = 0; double maxWeight = 0; for (int i = 1; i <= cnt; ++i) { if (U.Union(edge[i].previd, edge[i].nextid)) { ++tot; maxWeight = std::max(maxWeight, edge[i].weight); } if (tot == n - 1) break; } return maxWeight; }
intmain(){ IMPROVE_IO(); cin >> m; for (int i = 1; i <= m; ++i) cin >> monkey[i]; cin >> n; for (int i = 1; i <= n; ++i) cin >> node[i].x >> node[i].y; // initialize edges for (int i = 1; i <= n; ++i) { for (int j = 1; j < i; ++j) { edge[++cnt].previd = i; edge[cnt].nextid = j; edge[cnt].weight = GetDist(i, j); } } double maxW = Kruskal(); int ans = 0; for (int i = 1; i <= m; ++i) { if (monkey[i] >= maxW) ++ans; } cout << ans << endl; return0; }