]> Skullheadx's Git Forge - CCC.git/commitdiff
2021 S4 attempt 2
authorSkullheadx <admonty1@gmail.com>
Wed, 8 Feb 2023 21:40:52 +0000 (16:40 -0500)
committerSkullheadx <admonty1@gmail.com>
Wed, 8 Feb 2023 21:40:52 +0000 (16:40 -0500)
Main/Python/2021/S4.py
Main/Python/2021/all_data/junior_data.zip [new file with mode: 0644]
Main/Python/2021/all_data/senior_data.zip [new file with mode: 0644]

index dec7ef2c110ffe01a52b195688a3d1145c567838..21c7901034081f2239b0a34104f2eb3abaa9d381 100644 (file)
@@ -1,20 +1,42 @@
-from queue import Queue
-"""
-start at station 1 then go to station N
+# """
+# start at station 1 then go to station N
+#
+# There are W one way walkways between stations
+# A, B = stations connected by walkway
+# time = 1 min
+#
+# Every day (D is total days), station X and Y swap
+#
+#
+#
+# """
 
-There are W one way walkways between stations
-A, B = stations connected by walkway
-time = 1 min
 
-Every day (D is total days), station X and Y swap
+def swap(i, j):
+       stations[i], stations[j] = stations[j], stations[i]
 
 
+def get_next_station(m, station):
+       if m > len(stations) and station != N:
+               return False
 
-"""
+       if station == N:
+               outputs.append(m)
+               return True
+       # take a walkway
+       if station in walkways:
+               for destination in walkways[station]:
+                       get_next_station(m + 1, destination)
 
+       if m < len(stations):
+               train = stations[m]
+               # take a train
+               if train == station:
+                       if m < len(stations) - 1:
+                               get_next_station(m + 1, stations[m + 1])
+               # wait at the station
+               get_next_station(m + 1, station)
 
-def swap(i, j):
-       stations[i], stations[j] = stations[j], stations[i]
 
 
 N, W, D = tuple(map(int, input().split()))
@@ -23,31 +45,13 @@ for i in range(W):
        A, B = tuple(map(int, input().split()))
        walkways[A] = walkways.get(A, list()) + [B]
 
+outputs = []
+test = []
+
 stations = list(map(int, input().split()))
 for i in range(D):
        X, Y = tuple(map(int, input().split()))
-       swap(X-1, Y-1)
-
-       q = Queue()
-       visited = set()
-
-       q.put((stations[0], 0))
-       if stations[0] in walkways:
-               for neighbor in walkways[stations[0]]:
-                       q.put((neighbor, 1))
-
-       while not q.empty():
-               curr, time = q.get()
-               if curr in visited:
-                       continue
-               else:
-                       visited.add(curr)
-               if curr == N:
-                       print(time)
-                       break
-               for neighbor in walkways.get(curr, list()):
-                       if neighbor not in visited:
-                               q.put((neighbor, time + 1))
-               q.put((stations[stations.index(curr) + 1], time + 1))
-
-
+       swap(X - 1, Y - 1)
+       outputs.clear()
+       get_next_station(0, 1)
+       print(min(outputs))
\ No newline at end of file
diff --git a/Main/Python/2021/all_data/junior_data.zip b/Main/Python/2021/all_data/junior_data.zip
new file mode 100644 (file)
index 0000000..a8d4314
Binary files /dev/null and b/Main/Python/2021/all_data/junior_data.zip differ
diff --git a/Main/Python/2021/all_data/senior_data.zip b/Main/Python/2021/all_data/senior_data.zip
new file mode 100644 (file)
index 0000000..4feaa50
Binary files /dev/null and b/Main/Python/2021/all_data/senior_data.zip differ