没什么好说的,就是判断 y 是否在之前有出现在左边过而已
numMap = {0} n, k = map(int, input().split()) count = 0 for i in range(0, k): x, y = map(int, input().split()) if y not in numMap: count += 1 numMap.add(x) print(count)