Task: | Distances |
Sender: | ziihrs |
Submission time: | 2021-01-31 18:30:25 +0200 |
Language: | Python3 (PyPy3) |
Status: | READY |
Result: | 29 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 29 |
#2 | TIME LIMIT EXCEEDED | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.08 s | 1, 2 | details |
#2 | TIME LIMIT EXCEEDED | -- | 2 | details |
Code
import sys input = sys.stdin.readline for _ in range(int(input())): N = int(input()) adj = [[] for _ in range(N)] for _ in range(N-1): a, b = map(lambda s: int(s)-1, input().split()) adj[a].append(b) adj[b].append(a) D = [[-1] * N for _ in range(N)] A = [[] for _ in range(N)] for s in range(N): Q = [s] MD = D[s] MD[s] = 0 for i in Q: for j in adj[i]: if MD[j] == -1: MD[j] = MD[i] + 1 Q.append(j) for i in range(N): if 1 <= MD[i] <= 3: A[s].append(i) V = [False] * N V[0] = True order = [0] def f(i): if len(order) == N: return True for j in A[i]: if not V[j]: V[j] = True order.append(j) if f(j): return True V[j] = False order.pop() return False f(0) print(' '.join(str(v+1) for v in order))
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 3 2 4 7 5 6 8 1 3 2 8 7 5 4 6 1 3 2 5 7 8 6 4 1 2 3 4 5 6 7 8 1 3 2 4 6 8 7 5 ... Truncated |
Test 2
Group: 2
Verdict: TIME LIMIT EXCEEDED
input |
---|
100 100 37 59 81 37 44 81 ... |
correct output |
---|
1 99 82 81 59 5 71 55 17 24 13... |
user output |
---|
(empty) |