public class Main { static int[] F = new int[1010];
public static void main(String[] args) { Scanner cin = new Scanner(System.in); int n = cin.nextInt(); G[] g = new G[n]; for (int i = 0; i < n; i++) { int x = cin.nextInt(); int y = cin.nextInt(); int r = cin.nextInt(); g[i] = new G(x, y, r); } for (int i = 0; i < F.length; i++) { F[i] = i; } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (charge(g[i], g[j]) && i != j) { union(i, j); } } } int count = 0; for (int i = 0; i < n; i++) { if (F[i] == i) { count++; } } System.out.println(count); cin.close(); }
private static void union(int a, int b) { int fa = find(a); int fb = find(b); if (a != b) { F[fb] = fa; } }
private static int find(int a) { return a == F[a] ? a : (F[a] = find(F[a])); }
private static boolean charge(G a, G b) { return dis(a, b) < (a.r + b.r); }
private static double dis(G a, G b) { double s = Math.sqrt(1.0 * (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); return s; }
private static class G { int x; int y; int r;
public G(int x, int y, int r) { this.x = x; this.y = y; this.r = r; } } }