Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MyList = []
- def addToList(string):
- words = []
- vertex = [int(string[0]), int(string[1])]
- for i in range(2, len(string)): words.append(string[i])
- vertex.append(' '.join(words))
- MyList.append(vertex)
- while (True):
- try:
- string = input()
- addToList(list(string.split()))
- except EOFError:
- break
- ChildList = [[] for _ in range(len(MyList) + 1)]
- for vertex in MyList:
- ChildList[vertex[1]].append(vertex)
- def printSymbCode(symbCode):
- if len(symbCode) < 2:
- return
- i = 1
- while (i < len(symbCode) and symbCode[i] == 1):
- print(" ", end='')
- i += 1
- while (i < len(symbCode)):
- print("┃ ", end='')
- i += 1
- def wierdDfs(MyList, ChildList, n, deep, symbCode):
- #n - текущий номер вершины
- #d - уровень в дереве
- lastSymb = ""
- if symbCode:
- if (symbCode[-1] == 1):
- lastSymb = "┗╸"
- elif (symbCode[-1] == 0):
- lastSymb = "┣╸"
- printSymbCode(symbCode)
- print(str(lastSymb), end="")
- print(MyList[n][2])
- if not ChildList[n]:
- return
- newSymbCode = symbCode.copy()
- for i in range(len(ChildList[n])):
- if (i == len(ChildList[n]) - 1):
- newSymbCode.append(1)
- else:
- newSymbCode.append(0)
- wierdDfs(MyList, ChildList, ChildList[n][i][0], deep+1, newSymbCode)
- wierdDfs(MyList, ChildList, 0, 0, [])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement