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))
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
13 ms |
2900 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
2844 KB |
Output is correct |
2 |
Correct |
19 ms |
2812 KB |
Output is correct |
3 |
Correct |
18 ms |
2900 KB |
Output is correct |
4 |
Execution timed out |
2065 ms |
19772 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2059 ms |
19684 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
13 ms |
2900 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |