This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
import sys
n = int(sys.stdin.readline())
personer = []
elsket1 = []
elsket2 = []
A = []
pile = 0
for _ in range(n):
s, t = map(str, sys.stdin.readline().split())
personer.append(s)
elsket1.append(t)
for l in range(n):
elsket2.append(personer.index(elsket1[l]))
for _ in range(n):
A.append(0)
for i in range(n):
if n % 2 == 1:
break
if A[i] == 0 and A[elsket2[i]] == 0 and i == elsket2[elsket2[i]] and i != elsket2[i]:
A[elsket2[i]] = 1
A[i] = 1
for j in range(n):
if n % 2 == 1:
break
if A[j] == 0 and A[elsket2[j]] == 0 and j != elsket2[j]:
A[j] = 1
A[elsket2[j]] = 1
pile += 1
if n % 2 == 1:
print(-1)
else:
print(pile + A.count(0))
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |