|
| 1 | +const fs = require('fs'); |
| 2 | +const stdin = (process.platform === 'linux' |
| 3 | + ? fs.readFileSync('/dev/stdin').toString().trim() |
| 4 | + : `2 |
| 5 | +2 |
| 6 | +0 0 1 |
| 7 | +1 0 1 |
| 8 | +3 |
| 9 | +0 0 1 |
| 10 | +2 0 1 |
| 11 | +10 0 5 |
| 12 | +` |
| 13 | +).split('\n'); |
| 14 | + |
| 15 | +const input = (() => { |
| 16 | + let line = 0; |
| 17 | + return () => stdin[line++]; |
| 18 | +})(); |
| 19 | + |
| 20 | +const parent = {}; |
| 21 | +const rank = {}; |
| 22 | + |
| 23 | +// ์๋ ์ธ๊ฐ์ ํจ์๋ ์น์๋ ์ฝ๋ ์ฐธ๊ณ (์ต์ ํ๋ ์ ๋์จ ํ์ธ๋) |
| 24 | +function init(v) { |
| 25 | + parent[v] = v; |
| 26 | + rank[v] = 0; |
| 27 | +} |
| 28 | + |
| 29 | +function findParent(v) { |
| 30 | + if (parent[v] !== v) { |
| 31 | + parent[v] = findParent(parent[v]); |
| 32 | + } |
| 33 | + return parent[v]; |
| 34 | +} |
| 35 | + |
| 36 | +function unionParent(v, u) { |
| 37 | + const root1 = findParent(v); |
| 38 | + const root2 = findParent(u); |
| 39 | + if (root1 !== root2) { |
| 40 | + if (rank[root1] > rank[root2]) { |
| 41 | + parent[root2] = root1; |
| 42 | + } else { |
| 43 | + parent[root1] = root2; |
| 44 | + if (rank[root1] == rank[root2]) { |
| 45 | + rank[root2]++; |
| 46 | + } |
| 47 | + } |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +let T = parseInt(input()); |
| 52 | + |
| 53 | +for (let tc = 0; tc < T; tc++) { |
| 54 | + let N = parseInt(input()); |
| 55 | + let arr = Array.from(Array(N), () => Array(3).fill(0)); |
| 56 | + for (let i = 0; i < N; i++) { |
| 57 | + const [x, y, r] = input() |
| 58 | + .split(' ') |
| 59 | + .map((each) => parseInt(each)); |
| 60 | + |
| 61 | + arr[i][0] = x; |
| 62 | + arr[i][1] = y; |
| 63 | + arr[i][2] = r; |
| 64 | + init(i); |
| 65 | + } |
| 66 | + |
| 67 | + let answer = N; |
| 68 | + |
| 69 | + for (let i = 0; i < N; i++) { |
| 70 | + for (let j = i + 1; j < N; j++) { |
| 71 | + let xPos = arr[i][0] - arr[j][0]; |
| 72 | + let yPos = arr[i][1] - arr[j][1]; |
| 73 | + let radius = arr[i][2] + arr[j][2]; |
| 74 | + let edistPow = Math.pow(xPos, 2) + Math.pow(yPos, 2); // ์ ํด๋ฆฌ๋ ๊ฑฐ๋ฆฌ์ ์ ๊ณฑ |
| 75 | + if (edistPow <= Math.pow(radius, 2)) { |
| 76 | + if (findParent(i) !== findParent(j)) { |
| 77 | + unionParent(i, j); |
| 78 | + answer--; |
| 79 | + } |
| 80 | + } |
| 81 | + } |
| 82 | + } |
| 83 | + console.log(answer); |
| 84 | +} |
| 85 | + |
| 86 | +/* |
| 87 | +
|
| 88 | +## How |
| 89 | +์ด๋ ค์ ๋ค. ์ขํ์์ ์์ด ์๋ค๊ณ ์๊ฐํด๋ณด์ ๋ ์์ด ๊ฒน์น๋ ๊ฒ์ ํ์ธํ๋ ค๋ฉด ์ด๋ป๊ฒ ํด์ผํ ๊น? ์ ํด๋ฆฌ๋ ๊ฑฐ๋ฆฌ๋ฅผ ๊ตฌํ๊ณ ๊ฐ๊ฐ์ ๋ฐ์ง๋ฆ์ ๋ํ ๊ฒ๋ณด๋ค ์๊ฑฐ๋ ๊ฐ์์ง ๋ณด๋ฉด ๋๋ค. |
| 90 | +
|
| 91 | +์ ํด๋ฆฌ๋ ๊ฑฐ๋ฆฌ๋ ํผํ๊ณ ๋ผ์ค ์ ์๋ฅผ ํตํด ์ ๋ํ ์ ์๋ค. ๋๊ฐ์ ์ขํ์ x์ y์ ๊ฐ์ ๊ฐ๊ฐ์ ์ฐจ์ด๋ฅผ ์ ๊ณฑํ์ฌ ๋ํ ๋ค ๋ฃจํธ๋ฅผ ์์ฐ๋ฉด ๋ ์ ๊ฐ์ ๊ฑฐ๋ฆฌ๋ฅผ ๊ตฌํ ์ ์๋ค๋ ๊ท์น์ด๋ค.(์๋จ์ ์ฝ๋๋ ์ด ๊ท์น์ ๋ํด ์ ๊ณฑ์ ํด์ ๊ตฌํ๋ค) |
| 92 | +
|
| 93 | +์ด๋ ๊ฒ ์ ํด๋ฆฌ๋ ๊ฑฐ๋ฆฌ๋ฅผ ์ด์ฉํด ๋ ์ ์ฌ์ด์ ๊ฑฐ๋ฆฌ๋ฅผ ๊ตฌํ๊ณ ๊ทธ๊ฒ์ด ๊ฐ ์ขํ์ ํด๋นํ๋ ์์ ๋ฐ์ง๋ฆ๋ณด๋ค ์๊ฑฐ๋ ๊ฐ์ผ๋ฉด ๋ ์์ด ๊ฒน์ณ์๋ค๊ณ ๋ณผ ์ ์๋ค. |
| 94 | +
|
| 95 | +๋ ์์ด ๊ฒน์น๋ค๋ ์กฐ๊ฑด์ด ๋ง๋ค๋ฉด ์ ๋์จ ํ์ธ๋๋ฅผ ์ด์ฉํด ์ต์์ ๋
ธ๋๊ฐ ๋ค๋ฅด๋ค๋ฉด ๋ ํธ๋ฆฌ๋ฅผ ํฉ์น ๋ค N๋ถํฐ ์์ํ๋ count๋ฅผ 1์ฉ ๊ฐ์์ํค๋ ์์ผ๋ก ๋ฌธ์ ์ ์๊ตฌ์ฌํญ์ธ ์ ๊ตฐ ์ง์์ ๊ทธ๋ฃน ๊ฐฏ์๋ฅผ ๊ตฌํ ์ ์๋ค. |
| 96 | +
|
| 97 | +## Retrospective |
| 98 | +
|
| 99 | +*/ |
0 commit comments