Rezultati

Up. imeNalogaJezikRezultatČas oddaje
muzik-2018 Prehitevanje Python 3 100/100OK 04. okt '18 @ 17:41

Test Točke Porabljen spomin Porabljen čas Status
#1 16/16 8,676 MiB 0,000 s OK
#2 16/16 8,719 MiB 0,000 s OK
#3 17/17 8,699 MiB 0,000 s OK
#4 17/17 70,785 MiB 1,244 s OK
#5 17/17 116,566 MiB 3,637 s OK
#6 17/17 8,695 MiB 0,000 s OK

Ocenjevani program (preh2.py):
import sys
import math

sys.setrecursionlimit(10**9)

#sys.stdin = open("a.in")

inp = sys.stdin

T = int(inp.readline())


osebe = dict()

vrstni = []

for i in range(T):
    line = inp.readline()
    vrstni.append(line.strip())

P = int(inp.readline())

preh = []

for i in range(P):
    line = inp.readline()
    preh.append(line.strip().split())

start = vrstni[0]
osebe[start] = [None, None]
osebe[None] = [vrstni[-1], vrstni[0]]

for j in range(1, len(vrstni)):
    osebe[vrstni[j]] = [vrstni[j-1], None]
    osebe[vrstni[j-1]][1] = vrstni[j]

for a,b in preh:
    preva, nexta = osebe[a]
    prevb, nextb = osebe[b]

    if prevb == a:
        continue

    osebe[a] = [prevb, b]
    osebe[b] = [a, nextb]

    osebe[preva][1] = nexta
    osebe[nexta][0] = preva

    osebe[prevb][1] = a

start = None
count = 0
while True:
    count += 1
    start = osebe[start][1]
    if start is None:
        break
    print(start)