 # Need help | PERCAPTA | python3

even after so many days passed still strugging with PERCAPTA

i tried posting my query in many threads of codechef but nothing happened .
the only reason is my language (python)

i would be greatefull if u any of u guys helps me…
thanks…

below is my code which works for sample inputs and random test cases i tried . gives RE neither TLE nor WA

``````import collections

def dfs(p):

if(node not in visited and selected[node]):

dfs(node)

t=int(input())
for _ in range(t):
n,m=map(int,input().split())
income=list(map(int,input().split()))
pop=list(map(int,input().split()))
for __ in range(m):
a,b=map(int,input().split())
i=income
p=pop
# to find max per capita
for x in range(1,n):
if(i*pop[x]<p*income[x]):
i=income[x]
p=pop[x]

selected=[False]*n
# to select node with max per capita
for x in range(n):
if(pop[x]*i== income[x]*p):
selected[x]=True

visited=set()
ans=set()

for each in range(n):

if(each not in visited and selected[each]):
temp=set()
dfs(each)
if(len(temp)>len(ans)):
ans=temp
print(len(ans))
print(*ans)
``````

What verdict are you getting?

RE @ameybhavsar brother

I don’t code much in Python but rename the “pop” variable in your code to something else because pop is a built in function in python.Then Submit and tell the output please.

indeed it is brother @zephxr .
i changed it here is solution
verdict RE same
but ran succesfully for the following inputs:
2
2 1
99992 99999
10 10
1 2
3 3
10 1 2
5 1 1
1 2
2 3
1 3

2 Likes

thanks a lot buddy ,it helped got accepted.

1 Like

How it got accepted?

increased recursion depth .
limitation of python in cp … @zephxr

His code was giving RE because of recursion stack overflow, so simply increase the size of recursion stack and it gave him AC.

Ohh… I got it!

Okay Brother @faisal1947

bTw thanks to all of you who replied .
i was really rest less before.
thanks a ton.
@zephxr @ameybhavsar @tusshar_2000
happy coding

Always there, Brother!

1 Like