#20976: python 80% (TLE)求救


youngyoung (06 蘇昱揚 306)

學校 : 臺北市私立延平高級中學
編號 : 98924
來源 : [180.217.13.133]
最後登入時間 :
2022-05-03 14:31:59
c291. APCS 2017-0304-2小群體 -- 2017年3月APCS | From: [101.12.139.165] | 發表日期 : 2020-03-23 20:10

FriendList = input()
FriendList = [eval(i) for i in input().split()]
NotInGroup = [i for i in range(len(FriendList))]
Groups = 0
while len(NotInGroup) > 0:
    head = NotInGroup.pop(NotInGroup.index(FriendList[NotInGroup[0]]))
    i = head
    while FriendList[i] != head:
        i = NotInGroup.pop(NotInGroup.index(FriendList[i]))
    Groups += 1
print(Groups)
 
#20983: Re:python 80% (TLE)求救


fire5386 (becaidorz)

學校 : 國立清華大學
編號 : 115822
來源 : [59.115.180.44]
最後登入時間 :
2024-05-03 16:46:17
c291. APCS 2017-0304-2小群體 -- 2017年3月APCS | From: [111.249.71.207] | 發表日期 : 2020-03-23 21:17

FriendList = input()
FriendList = [eval(i) for i in input().split()]
NotInGroup = [i for i in range(len(FriendList))]
Groups = 0
while len(NotInGroup) > 0:
    head = NotInGroup.pop(NotInGroup.index(FriendList[NotInGroup[0]]))
    i = head
    while FriendList[i] != head:
        i = NotInGroup.pop(NotInGroup.index(FriendList[i]))
    Groups += 1
print(Groups)



https://66lemon66.blogspot.com/2020/03/zerojudge-c291-apcs-2017-0304-2-c.html

 
ZeroJudge Forum