3-5TLE求解决
class node:
def __init__(self,local):
self.local = local
self.next = None
class link:
def __init__(self):
self.head = node(None)
first = node(1)
self.head.next = first
def add(self,newlocal,local):
newnode = node(newlocal)
cur = self.head
while cur.next is not None:
if cur.next.local != local:
cur = cur.next
else:
break
newnode.next = cur.next
cur.next = newnode
def addr(self,newlocal,local):
newnode = node(newlocal)
cur = self.head
while cur.next is not None:
if cur.local != local:
cur = cur.next
else:
break
newnode.next = cur.next
cur.next = newnode
def remove(self,local):
cur = self.head
while cur.next is not None:
if cur.next.local != local:
cur = cur.next
else:
break
if cur.next is not None:
cur.next = cur.next.next
def put(self):
cur = self.head.next
while cur is not None:
print(cur.local,end = ' ')
cur = cur.next
print()
n = int(input())
l = link()
for i in range(2,n + 1):
x,y = map(int,input().split())
if y == 0:
l.add(i,x)
elif y == 1:
l.addr(i,x)
m = int(input())
for i in range(m):
z = int(input())
l.remove(z)
l.put()