UVA274 톰과 제리
입출력은 안짰다
뭔가 설명을 쓰고 올려야되는데
커찮
집에가서
미녀니를 볼 것이다ㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏ
뭔가 설명을 쓰고 올려야되는데
커찮
집에가서
미녀니를 볼 것이다ㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏ
def read_joggaton_file(file_name): return [(5, 2, 4, {0:[1], 1:[0], 2:[0], 3:[2], 4:[1]},{0:[2], 1:[4], 2:[3], 3:[0,1,4], 4:[3]})] def print_flag(f1, f2): print(f1, f2) def BFS_tom(room, dic, reach): my_que = [] my_que.append(room) reach[room]=True while my_que: now = my_que.pop(0) reach_rooms = dic[now] if now in dic else [] for r in reach_rooms: if reach[r]: continue reach[r] = True my_que.append(r) def BFS_jerry(room, dic, reach_t, reach_j): flag_join = False flag_path = False if reach_t[room]: return f_join, flag_path #이제 room은 톰이 못감 my_que = [] my_que.append(room) reach_j[room] = 1 while my_que: now = my_que.pop(0) reach_rooms = dic[now] for r in reach_rooms: if r==room and reach_j[now]==1: flag_path=True if reach_j[r] != 0: continue if reach_t[r]: flag_join = True reach_j[r] = -1 else: reach_j[r] = reach_j[now] my_que.append(r) if flag_join and flag_path: break return flag_join, flag_path test_cases=read_joggaton_file("sf") for test_case in test_cases: n_rooms, room_tom, room_jerry, dict_tom, dict_jerry = test_case reachable_tom = [False for r in range(n_rooms)] reachable_jerry = [0 for r in range(n_rooms)] BFS_tom(room_tom, dict_tom, reachable_tom) f_join, f_path=BFS_jerry(room_jerry, dict_jerry, reachable_tom,reachable_jerry) print_flag(f_join, f_path)
댓글
댓글 쓰기