Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.03 KB | None | 0 0
  1. def fun(a):
  2.     flag = False
  3.     if(len(stack)==0):
  4.         stack.append(a)
  5.     else:
  6.         lc = path[len(path)-1]
  7.         if(k[a][lc-1]=='0'):
  8.             trash.append(path[len(path)-1])
  9.             path.pop()
  10.     for i in range(n):
  11.         if(k[a][i]=='1'):
  12.             if(path.count(i+1)==0 and stack.count(i)==0 and trash.count(i)==0):
  13.                 flag = True
  14.                 stack.append(i)
  15.             else:
  16.                 flag = False
  17.     if(flag==False):
  18.        trash.append(a)
  19.     stack.pop(0)
  20.     if(flag==True):
  21.         path.append(a+1)
  22.     if(stack.count(tl)!=0):
  23.         path.append(tl+1)
  24.         return True
  25.     if(fun(stack[0])==True):
  26.         return True
  27.    
  28. f  = open('input.txt','r')
  29. res = f.read().split('\n')
  30. f.close()
  31. n = int(res[0])
  32. k=[]
  33. for i in range(n):
  34.     temp = res[i+1].split(' ')
  35.     k.append(temp)
  36. lk = res[n+1].split(' ')
  37. tk = int(lk[0])-1
  38. tl = int(lk[1])-1
  39. l = 0
  40. print(tk+1,tl+1)
  41. print("------------------")
  42. path =[]
  43. trash = []
  44. stack =[]
  45. fun(tk)
  46. print("path:",path)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement