baekjoon 20260123
This commit is contained in:
parent
0a8c4f38aa
commit
9aa4b28a45
1
code_study/Baekjoon/python/10797.py
Normal file
1
code_study/Baekjoon/python/10797.py
Normal file
@ -0,0 +1 @@
|
||||
print((lambda x : input().split().count(x))(input()))
|
||||
38
code_study/Baekjoon/python/9466.py
Normal file
38
code_study/Baekjoon/python/9466.py
Normal file
@ -0,0 +1,38 @@
|
||||
import sys
|
||||
sys.setrecursionlimit(10**6)
|
||||
input = sys.stdin.readline
|
||||
|
||||
ans = []
|
||||
|
||||
for t in range(int(input())) :
|
||||
n, selet = int(input()), [0] + list(map(int, input().split()))
|
||||
|
||||
visited = [False] * (n+1)
|
||||
finished = [False] * (n+1)
|
||||
ans.append(n)
|
||||
|
||||
def dfs(now) :
|
||||
visited[now] = True
|
||||
next = selet[now]
|
||||
|
||||
if not visited[next] :
|
||||
dfs(next)
|
||||
|
||||
else :
|
||||
if not finished[next] :
|
||||
temp = next
|
||||
|
||||
while temp != now :
|
||||
ans[t] -= 1
|
||||
temp = selet[temp]
|
||||
|
||||
ans[t] -= 1
|
||||
|
||||
finished[now] = True
|
||||
|
||||
for i in range(1, n+1) :
|
||||
if not visited[i] :
|
||||
dfs(i)
|
||||
|
||||
print('\n'.join(list(map(str, ans))))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user