Buggy python submission (verdict: Time Limit Exceeded):
# ABC068C - Cat Snuke and a Voyage (ARC079C)
# DFS O(N + M)
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)


def dfs(v: int) -> None:
    for u in G[v]:  # search vertices available from v recursively
        if dist[u] > dist[v] + 1:
            dist[u] = dist[v] + 1
            dfs(u)


def main():
    global G, dist
    N, M = tuple(map(int, input().split()))  # vertices and edges
    E = tuple(tuple(map(int, input().split())) for _ in range(M))
    G = [[] for _ in range(N + 1)]  # graph, N+1: 1-idx
    for v, u in E:  # construct a graph according to edges' info
        G[v] += [u]
        G[u] += [v]
    dist = [float("inf")] * (N + 1)  # distance from vertex 1
    dist[1] = 0
    dfs(1)  # search from vertex 1
    flg = dist[-1] <= 2
    print("POSSIBLE" if flg else "IMPOSSIBLE")


if __name__ == "__main__":
    main()

Fixed submission:
# ARC079C - Cat Snuke and a Voyage (ABC068C)
import sys
input = sys.stdin.readline

def main():
    n, m = list(map(int, input().rstrip().split()))
    s, d = set(), set()
    for _ in range(m):
        a, b = list(map(int, input().rstrip().split()))
        if a == 1:
            s.add(b)
        elif b == n:
            d.add(a)
    ans = len(s & d)
    print("POSSIBLE" if ans else "IMPOSSIBLE")


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
# ABC068C - Cat Snuke and a Voyage (ARC079C)
import sys
input = sys.stdin.readline

def dijkstra(s: int) -> int:
    D = [float("inf")] * (N + 1)  # distance
    D[s] = 0
    used = [0] * (N + 1)
    while True:
        v = -1
        for i in range(1, N + 1):
            if not used[i] and (v == -1 or D[i] < D[v]):
                v = i
        if v == -1:
            break
        used[v] = 1
        for j in range(1, N + 1):
            D[j] = min(D[j], D[v] + cost[v][j])
    return D[-1]


def main():
    global N, cost
    N, M = tuple(map(int, input().split()))
    E = tuple(tuple(map(int, input().split())) for _ in range(M))
    # cost[v][u] := cost from vertex v to u
    cost = [[float("inf")] * (N + 1) for _ in range(N + 1)]
    for v, u in E:
        cost[v][u] = 1
        cost[u][v] = 1
    flg = dijkstra(1) <= 2
    print("POSSIBLE" if flg else "IMPOSSIBLE")


if __name__ == "__main__":
    main()

Fixed submission:
# ARC079C - Cat Snuke and a Voyage (ABC068C)
import sys
input = sys.stdin.readline

def main():
    n, m = list(map(int, input().rstrip().split()))
    s, d = set(), set()
    for _ in range(m):
        a, b = list(map(int, input().rstrip().split()))
        if a == 1:
            s.add(b)
        elif b == n:
            d.add(a)
    ans = len(s & d)
    print("POSSIBLE" if ans else "IMPOSSIBLE")


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
# ABC068C - Cat Snuke and a Voyage (ARC079C)
import sys
input = sys.stdin.readline

def dijkstra(s: int) -> int:
    D = [float("inf")] * (N + 1)  # distance
    D[s] = 0
    used = [0] * (N + 1)
    while True:
        v = -1
        for i in range(1, N + 1):
            if not used[i] and (v == -1 or D[i] < D[v]):
                v = i
        if v == -1:
            break
        used[v] = 1
        for j in range(1, N + 1):
            D[j] = min(D[j], D[v] + cost[v][j])
    return D[-1]


def main():
    global N, cost
    N, M = tuple(map(int, input().split()))
    E = tuple(tuple(map(int, input().split())) for _ in range(M))
    # cost[v][u] := cost from vertex v to u
    cost = [[float("inf")] * (N + 1) for _ in range(N + 1)]
    for v, u in E:
        cost[v][u] = 1
        cost[u][v] = 1
    flg = dijkstra(1) <= 2
    print("POSSIBLE" if flg else "IMPOSSIBLE")


if __name__ == "__main__":
    main()

Fixed submission:
# ARC079C - Cat Snuke and a Voyage (ABC068C)
import sys
input = sys.stdin.readline

def main():
    n, m = list(map(int, input().rstrip().split()))
    s, d = set(), set()
    for _ in range(m):
        a, b = list(map(int, input().rstrip().split()))
        if a == 1:
            s.add(b)
        elif b == n:
            d.add(a)
    ans = len(s & d)
    print("POSSIBLE" if ans else "IMPOSSIBLE")


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
# ABC068C - Cat Snuke and a Voyage (ARC079C)
def main():
    N, M = tuple(map(int, input().split()))
    A = tuple(tuple(map(int, input().split())) for _ in range(M))
    S, D = set(), set()  # start, destination
    for a, b in E:
        if a == 1:
            S |= {b}
        if b == N:
            D |= {a}
    flg = S & D  # if the same X in both S & D -> possible
    print("POSSIBLE" if flg else "IMPOSSIBLE")


if __name__ == "__main__":
    main()

Fixed submission:
# ARC079C - Cat Snuke and a Voyage (ABC068C)
import sys
input = sys.stdin.readline

def main():
    n, m = list(map(int, input().rstrip().split()))
    s, d = set(), set()
    for _ in range(m):
        a, b = list(map(int, input().rstrip().split()))
        if a == 1:
            s.add(b)
        elif b == n:
            d.add(a)
    ans = len(s & d)
    print("POSSIBLE" if ans else "IMPOSSIBLE")


if __name__ == "__main__":
    main()