Task: | Etäisyydet |
Sender: | Microwave Abuser |
Submission time: | 2021-01-23 19:31:24 +0200 |
Language: | Python3 (PyPy3) |
Status: | READY |
Result: | 100 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 29 |
#2 | ACCEPTED | 71 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.07 s | 1, 2 | details |
#2 | ACCEPTED | 0.14 s | 2 | details |
Code
def main(): t = int(input()) finalresult = "" for useless in range(t): n = int(input()) vieruslistafor = [] for i in range(n+1): vieruslistafor.append([]) for i in range(n-1): syöte = input().split(" ") vieruslistafor[int(syöte[0])].append(int(syöte[1])) vieruslistafor[int(syöte[1])].append(int(syöte[0])) # aloita jostain päästä for i in range(200): if len(vieruslistafor[i+1]) == 1: curpos = i+1 break movesleft = 3 pathfromintersection = [curpos] #index0 : intersec usednodes = [] result = "" while True: if len(vieruslistafor[curpos]) == 1: if not (curpos in usednodes): result += str(curpos) + " " movesleft = 3 usednodes.append(curpos) lastpos = curpos curpos = vieruslistafor[curpos][0] movesleft -= 1 vieruslistafor[curpos].remove(lastpos) pathfromintersection.pop() if len(pathfromintersection) == 0: pathfromintersection.append(curpos) elif len(vieruslistafor[curpos]) == 0: result += str(curpos) + " " break else: if movesleft == 0: result += str(curpos) + " " movesleft = 3 usednodes.append(curpos) for i in range(100): if not (vieruslistafor[curpos][i] in pathfromintersection): curpos = vieruslistafor[curpos][i] break movesleft -= 1 pathfromintersection.append(curpos) finalresult += result[:-1] + "\n" print(finalresult[:-1]) main()
Test details
Test 1
Group: 1, 2
Verdict: ACCEPTED
input |
---|
100 8 5 2 2 3 3 7 ... |
correct output |
---|
1 8 2 5 6 7 3 4 1 7 2 8 3 6 4 5 1 4 6 2 7 5 8 3 1 8 3 2 4 7 6 5 1 6 4 7 5 2 3 8 ... |
user output |
---|
1 4 8 5 6 2 3 7 2 8 7 3 1 6 5 4 4 1 3 6 7 2 8 5 2 3 8 4 5 1 6 7 5 2 7 3 4 8 1 6 ... Truncated |
Test 2
Group: 2
Verdict: ACCEPTED
input |
---|
100 100 37 59 81 37 44 81 ... |
correct output |
---|
1 99 82 81 59 5 71 55 17 24 13... |
user output |
---|
2 50 27 81 17 5 55 71 59 24 39... Truncated |