LATOKEN PROBLEM — Little Alwan Puzzle Runtime Error

Revision en2, by Leggasick, 2021-06-14 01:14:41

I have tried it using both adjacency matrix and dictionary but both are giving run time error on TC 3.Can anyone tell me what the problem in the code? import sys sys.stdin=open('input.txt','r') sys.stdout=open('output.txt','w') import math import heapq def input(): return sys.stdin.readline().strip("\n") def I(): return (input()) def II(): return (int(input())) def MI(): return (map(int,input().split())) def LI(): return (list(map(int,input().split()))) def isPerfectSquare(x): return (int(math.sqrt(x))**2 == x) MOD = 10**9 + 7 def dfs(i): visited[i] = 1 for l in graph[i]: if visited[l] == 0: dfs(l) for _ in range(II()): n = II() a = LI() b = LI() graph = {} visited = [0]*(n+1) for i in range(n): if a[i] not in graph: graph[a[i]] = [b[i]] # print(graph) ans = 1 for i in range(1,n): if visited[i] == 0: dfs(i) ans = (ans * 2) % MOD print(ans)

Tags latoken, #python 3

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en4 English Leggasick 2021-06-14 01:28:12 8 Tiny change: 'sion/119405558)' -> 'sion/119406032)'
en3 English Leggasick 2021-06-14 01:16:27 775
en2 English Leggasick 2021-06-14 01:14:41 22
en1 English Leggasick 2021-06-14 01:13:28 998 Initial revision (published)