We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I am considering initial use-case: 000000 1
Before the PM number is met for the second time (call number 622573) almost all the previous calls have been made between "independent" users. In other words, all of them are parts of groups within size 2. So, there is no one big group of frends which include 10000 users/friends of PM. SO, It looks like there is an issue. OR I've not got something.
Here is my code:
# Enter your code here. Read input from STDIN. Print output to STDOUTSk_cache=dict()defSk(k):globalSk_cacheifkinSk_cache:returnSk_cache[k]res=0ifk<=55:res=(100003-200003*k+300007*(k**3))%(10**6)else:res=(Sk(k-24)+Sk(k-55))%(10**6)Sk_cache[k]=resreturnresNUMBER,p=map(int,input().rstrip().split())groups=0number2group=dict()#number->agroup_cnt=dict()#a->intgroup_connection=set()#(a,b)number_found=Falsetarget_number_group=0cur_p=0#print("NUMBER {} p {}".format(NUMBER, p))i=1calls=0while(notnumber_foundorcur_p<p*(10**4))andi<=2*10**6:calls+=1cur_number_from=Sk(2*calls-1)cur_number_to=Sk(2*calls)#print("call N{} from {} to {}".format(calls, cur_number_from, cur_number_to))ifcur_number_from==NUMBERorcur_number_to==NUMBER:number_found=Truenumber_from_group=0number_to_group=0ifcur_number_fromisnumber2group:#print("Already grouped 1")number_from_group=number2group[cur_number_from]ifcur_number_toisnumber2group:#print("Already grouped 2")number_to_group=number2group[cur_number_to]#if number_from_group != number_to_group and number_from_group != 0 and number_to_group != 0:# print("Connection found!")ifnumber_from_group!=number_to_groupandnumber_from_group!=0andnumber_to_group!=0and(number_from_group,number_to_group)notingroup_connection:group_connection.add((number_from_group,number_to_group))group_connection.add((number_to_group,number_from_group))prev_cnt=group_cnt[number_from_group]group_cnt[number_from_group]+=group_cnt[number_to_group]group_cnt[number_to_group]+=prev_cntifnumber_from_group==0andnumber_to_group!=0:#print("Group extension 1")number_from_group=number_to_groupnumber2group[cur_number_from]=number_to_groupgroup_cnt[number_to_group]+=1ifnumber_from_group!=0andnumber_to_group==0:#print("Group extension 2")number_to_group==number_from_groupnumber2group[cur_number_to]=number_from_groupgroup_cnt[number_from_group]+=1ifnumber_from_group==0andnumber_to_group==0andcur_number_from!=cur_number_to:groups+=1number2group[cur_number_to]=groupsnumber2group[cur_number_from]=groupsgroup_cnt[groups]=2number_to_group=groupsnumber_from_group=groups#if number_to_group != 0:# if group_cnt[number_to_group] > 2:# print("group {} number {}".format(number_to_group, group_cnt[number_to_group]))#if number_from_group != 0:# if group_cnt[number_from_group] > 2:# print("group {} number {}".format(number_from_group, group_cnt[number_from_group]))ifcur_number_from==NUMBERorcur_number_to==NUMBER:number_found=Truetarget_number_group=number2group[cur_number_from]source_number_group=number2group[cur_number_to]#print("call N{} from {} to {} groups {}, {} total_groups {}".format(calls, cur_number_from, cur_number_to, target_number_group, source_number_group, groups))iftarget_number_group!=0:cur_p=group_cnt[target_number_group]#print("{}".format(cur_p))i+=2ifnumber_foundandcur_p>=p*(10**4):print("{}".format(calls))#print("target group count = {}".format(group_cnt[target_number_group]))#print("target group number = {}".format(target_number_group))#print("group connection {}".format(len(group_connection)))
`
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #186: Connectedness of a network.
You are viewing a single comment's thread. Return to all comments →
I am considering initial use-case: 000000 1 Before the PM number is met for the second time (call number 622573) almost all the previous calls have been made between "independent" users. In other words, all of them are parts of groups within size 2. So, there is no one big group of frends which include 10000 users/friends of PM. SO, It looks like there is an issue. OR I've not got something. Here is my code:
`