run time error this code is giving on test8 of this q https://mirror.codeforces.com/contest/1833/problem/E

Правка en1, от 112101017, 2023-06-08 21:06:38
def dfsvisit():
    global d
    global vis
    count=0
    count1=0
    for i in d:
        c1=0
        if vis[i-1]==0:
            vis[i-1]=1
            c1=dfs(i)
            if c1==0:
                count=count+1
            else:
                count1+=1
    if count1>0:
        return(count+1,count+count1)
    else:
        return(count,count+count1)
def dfs(i):
    global d
    global vis
    t1=d[i]
    flag=0
    if len(t1)<2:
        flag=-1
    for i in range(len(t1)):
        if vis[t1[i]-1]==0:
            vis[t1[i]-1]=1
            c=dfs(t1[i])
            if c==-1:
                flag=-1
    return flag        
t=int(input(""))
for i in range(t):
    n=int(input(""))
    d={}
    vis=[0]*n
    for i in range(1,n+1):
        d[i]=()
    x = list(map(int, input("").split()))    
    for i in range(len(x)):
        if (i+1) not in d[x[i]]:
            d[x[i]]=d[x[i]]+(i+1,)
        if (x[i]) not in d[i+1]:    
            d[i+1]=d[i+1]+(x[i],)
    c3,c4=dfsvisit()
    print(c3,c4)

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский 112101017 2023-06-08 21:06:38 1344 Initial revision (published)