ps | |
---|---|
링크 | acmicpc.net/… |
출처 | BOJ |
문제 번호 | 33550 |
문제명 | Composius' Wrath |
레벨 | 골드 4 |
시간복잡도 | O(ElogE + m) |
인풋사이즈 | E<=10^4, m<=10^4 |
사용한 언어 | Python 3.13 |
제출기록 | 36340KB / 44ms |
최고기록 | 40ms |
해결날짜 | 2025/03/01 |
"""Solution code for "BOJ 33550. Composius' Wrath".
- Problem link: https://www.acmicpc.net/problem/33550
- Solution link: http://www.teferi.net/ps/problems/boj/33550
Tags: [number theory] [disjoint set]
"""
import sys
from teflib import disjointset
from teflib import numtheory
def main():
c, r = [int(x) for x in sys.stdin.readline().split()]
dsu = disjointset.DisjointSet(c)
pt = numtheory.PrimeTester()
p = 0
for _ in range(r):
a, b, w = [int(x) for x in sys.stdin.readline().split()]
a, b = a - 1, b - 1
if pt.is_prime(w):
if dsu.union_if_disjoint(a, b):
p += 1
print(p, c - 1 - p)
if __name__ == '__main__':
main()