| Task: | Road network |
| Sender: | megachainmail |
| Submission time: | 2020-10-03 15:38:17 +0300 |
| Language: | Python3 (CPython3) |
| Status: | READY |
| Result: | WRONG ANSWER |
| test | verdict | time | |
|---|---|---|---|
| #1 | WRONG ANSWER | 0.04 s | details |
| #2 | WRONG ANSWER | 0.04 s | details |
| #3 | WRONG ANSWER | 0.04 s | details |
| #4 | WRONG ANSWER | 0.04 s | details |
| #5 | ACCEPTED | 0.04 s | details |
| #6 | TIME LIMIT EXCEEDED | -- | details |
| #7 | TIME LIMIT EXCEEDED | -- | details |
| #8 | TIME LIMIT EXCEEDED | -- | details |
| #9 | TIME LIMIT EXCEEDED | -- | details |
| #10 | TIME LIMIT EXCEEDED | -- | details |
| #11 | WRONG ANSWER | 0.04 s | details |
Code
import queue
#Read input
n, m = [int(i) for i in input().split()]
#Read edge inputs and initialize edges
connections = {i: [] for i in range(1,n+1)}
#print(connections)
for i in range(m):
a,b = [int(i) for i in input().split()]
#print(a,b)
connections[a].append(b)
connections[b].append(a)
#Search with Breadth-first-search
def bfs(start):
#Initialize a queue for BFS with starting vertex
left = queue.Queue()
left.put(start)
found = [False] * n
#print(found)
found[start-1] = True
num_found = 1
#Continue until no unvisited neighbors left
while not left.empty():
#Take first vertex from the "waiting line"
current = left.get()
#print("CURRENT: {}, found: {}".format(current, found))
#Go trough every neighbor
for neighbor in connections[current]:
#If was not found
if not found[neighbor-1]:
left.put(neighbor) #Add neighbor to visit-list
found[neighbor-1] = True #Mark as found
num_found += 1
if num_found == n:
return "YES"
else:
for i in range(n):
if not found[n-1]:
return "NO\n{} {}".format(start, n)
#Print answer:
print(bfs(1))
Test details
Test 1
Verdict: WRONG ANSWER
| input |
|---|
| 10 20 8 1 9 5 6 10 6 1 ... |
| correct output |
|---|
| NO 7 1 |
| user output |
|---|
| YES |
Test 2
Verdict: WRONG ANSWER
| input |
|---|
| 10 20 2 10 10 6 8 5 3 8 ... |
| correct output |
|---|
| NO 1 2 |
| user output |
|---|
| YES |
Test 3
Verdict: WRONG ANSWER
| input |
|---|
| 10 20 10 2 1 5 8 3 5 6 ... |
| correct output |
|---|
| NO 9 1 |
| user output |
|---|
| YES |
Test 4
Verdict: WRONG ANSWER
| input |
|---|
| 10 20 9 6 10 4 7 2 10 5 ... |
| correct output |
|---|
| NO 6 1 |
| user output |
|---|
| YES |
Test 5
Verdict: ACCEPTED
| input |
|---|
| 10 20 5 9 10 2 3 5 7 4 ... |
| correct output |
|---|
| YES |
| user output |
|---|
| YES |
Test 6
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 100000 200000 64780 62469 32706 84268 37795 14893 23995 68041 ... |
| correct output |
|---|
| NO 40590 1 |
| user output |
|---|
| (empty) |
Test 7
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 100000 200000 74725 92399 25141 53472 70762 85785 47091 71621 ... |
| correct output |
|---|
| NO 96983 1 |
| user output |
|---|
| (empty) |
Test 8
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 100000 200000 50342 88741 55031 42206 24989 54546 666 39964 ... |
| correct output |
|---|
| NO 1 68638 |
| user output |
|---|
| (empty) |
Test 9
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 100000 200000 51243 54643 90493 3012 62110 9430 5809 45601 ... |
| correct output |
|---|
| NO 48024 1 |
| user output |
|---|
| (empty) |
Test 10
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 100000 200000 5524 49109 87052 72192 46434 18442 67624 38661 ... |
| correct output |
|---|
| YES |
| user output |
|---|
| (empty) |
Test 11
Verdict: WRONG ANSWER
| input |
|---|
| 7 10 1 2 2 1 1 4 5 4 ... |
| correct output |
|---|
| NO 2 3 |
| user output |
|---|
| YES |
