diff options
Diffstat (limited to '2025/08/b.py')
| -rw-r--r-- | 2025/08/b.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/2025/08/b.py b/2025/08/b.py new file mode 100644 index 0000000..4a6d610 --- /dev/null +++ b/2025/08/b.py | |||
| @@ -0,0 +1,26 @@ | |||
| 1 | import fileinput | ||
| 2 | |||
| 3 | with fileinput.input() as lines: | ||
| 4 | pts = [tuple(int(x) for x in line[:-1].split(',')) for line in lines] | ||
| 5 | |||
| 6 | r = range(len(pts)) | ||
| 7 | |||
| 8 | def dist(p, q): | ||
| 9 | return (p[0]-q[0])**2 + (p[1]-q[1])**2 + (p[2]-q[2])**2 | ||
| 10 | |||
| 11 | d = sorted([(dist(pts[i], pts[j]), i, j) for i in r for j in r if j > i]) | ||
| 12 | |||
| 13 | rep = [i for i in r] | ||
| 14 | |||
| 15 | def findrep(i): | ||
| 16 | return i if rep[i] == i else findrep(rep[i]) | ||
| 17 | |||
| 18 | def joinrep(i, j): | ||
| 19 | rep[findrep(i)] = findrep(j) | ||
| 20 | |||
| 21 | for _, j, k in d: | ||
| 22 | if findrep(j) != findrep(k): | ||
| 23 | joinrep(j, k) | ||
| 24 | sol = pts[j][0] * pts[k][0] | ||
| 25 | |||
| 26 | print(sol) | ||
