Rezultati

Up. imeNalogaJezikRezultatČas oddaje
vlakectomaz-2018 Prehitevanje Python 3 0/100Prekoračen čas (TLE) 04. okt '18 @ 18:50

Test Točke Porabljen spomin Porabljen čas Status
#1 16/16 8,598 MiB 0,000 s OK
#2 16/16 8,605 MiB 0,000 s OK
#3 17/17 8,688 MiB 0,000 s OK
#4 17/17 11,211 MiB 1,382 s OK
#5 0/17 65,520 MiB 4,600 s Prekoračen čas
#6 17/17 8,527 MiB 0,000 s OK

Ocenjevani program (prehitevanje.py):
N = int(input())

class Node:
    def __init__(self, prevn, nextn, name):
        self.prevn = prevn
        self.nextn = None
        self.name = name
    
    
name2node = {}
first = None
cur = None
for i in range(N):
    ime = input()
    n=Node(cur, None, ime)
    
    if(cur):
        cur.nextn = n
    
    name2node[ime] = n
    cur = n
    if(first is None):
        first = n

P = int(input())
for i in range(P):
    ime1, ime2 = input().split(" ")
    n1, n2 = name2node[ime1], name2node[ime2]
    
    if(n1.prevn is None):
        first = n1.nextn
    
    if(n1.prevn):
        n1.prevn.nextn = n1.nextn
    if(n1.nextn):
        n1.nextn.prevn = n1.prevn
    
    n1.prevn = n2.prevn
    if(n2.prevn):
        n2.prevn.nextn = n1
        
    n1.nextn = n2
    n2.prevn = n1
    
    if(n1.prevn is None):
        first = n1
        
    #print(first.name)
    
cur = first
while(cur is not None):
    print(cur.name)
    cur = cur.nextn