bapc-prelim-2016/f.py
Felix C. Stegerman 3cc48c7648 ...
2016-09-24 13:28:47 +02:00

27 lines
591 B
Python

from __future__ import print_function
import sys
N = int(sys.stdin.readline())
K = int(sys.stdin.readline())
D = {}; done = 0
for line in sys.stdin:
C1, C2, P1, P2 = line.split(); C1, C2 = map(int, (C1, C2))
if P1 == P2: done += 1
D.setdefault(P1, set()).add(C1)
D.setdefault(P2, set()).add(C2)
doubles = len([ k for k, v in D.iteritems() if len(v) == 2 ])
singles = len([ k for k, v in D.iteritems() if len(v) == 1 ])
left = N - 2*doubles - singles
answer = doubles - done
if singles == 0 and left == 2:
answer += 1
elif singles == left:
answer += left
print(answer)