I haven't checked over your code, but this construct is probably a mistake:

tree=[[]]*500001

This is equivalent to:
x = []
tree = [x] * 500001

Here's an example of how that can be problematic:
>>> q = [[]] * 3
>>> q
[[], [], []]
>>> q[0].append(5)
>>> q
[[5], [5], [5]]




On Sun, Jul 12, 2020 at 9:17 PM Prince Zarzees <[email protected]>
wrote:

> Problem Link
>
> https://codingcompetitions.withgoogle.com/kickstart/round/000000000019ff08/0000000000386edd
> My Solution:
> tree=[[]]*500001
>
> v=[0]*500001
>
> visita=[0]*500001
>
> visitb=[0]*500001
> def f(k):
>
>     n,a,b=map(int,input().split(" "))
>
>     l=list(map(int,input().split(" ")))
>
>     for i in range(1,n+1):
>
>         tree[i]=[]
>
>         v[i]=0
>
>         visita[i]=0
>
>         visitb[i]=0
>     for i in range(0,len(l)):
>
>         tree[l[i]].append(i+2)
>
>     path=[1]
>     while(len(path)):
>             item=path[len(path)-1]
>
>             if (v[item]==len(tree[item])):
>
>                 visita[item]+=1
>
>                 visitb[item]+=1
>
>                 if (len(path)-1-a>=0):
>
>                     visita[path[len(path)-1-a]]+=visita[item]
>
>                 if (len(path)-1-b>=0):
>
>                     visitb[path[len(path)-1-b]]+=visitb[item]
>
>                 path.pop(len(path)-1)
>
>             else:
>
>                 path.append(tree[item][v[item]])
>
>                 v[item]+=1
>     s=0
>
>     for i in range(1,n+1):
>
>         s+=n*visita[i]+n*visitb[i]-visita[i]*visitb[i]
>
>     print ("Case #"+str(k)+": "+str(s/(n*n)))
> for i in range(int(input())):
>
>     f(i+1)
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Code Jam" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/google-code/f1cab47d-e372-49ae-bd13-5060589a04f1o%40googlegroups.com
> <https://groups.google.com/d/msgid/google-code/f1cab47d-e372-49ae-bd13-5060589a04f1o%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/CAHaiWHOX51WVyU%3Dncy%2BxmPrdFikuJKPvMvbxd7E0zFV_RbS%3DZA%40mail.gmail.com.

Reply via email to