結果

問題 No.2948 move move rotti
ユーザー LyricalMaestro
提出日時 2025-04-19 13:13:06
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,069 bytes
コンパイル時間 209 ms
コンパイル使用メモリ 82,760 KB
実行使用メモリ 62,240 KB
最終ジャッジ日時 2025-04-19 13:13:30
合計ジャッジ時間 2,720 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20 WA * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

## https://yukicoder.me/problems/no/2948


def main():
    N, M, K = map(int, input().split())
    X = list(map(int, input().split()))
    next_nodes = [[] for _ in range(N)]
    for _ in range(M):
        u, v = map(int, input().split())
        next_nodes[u - 1].append(v - 1)
        next_nodes[v - 1].append(u - 1)
    
    x_set = set(X)
    answer_list = [[0] * N for _ in range(N + 1)]
    for x in x_set:
        current_pos = [0] * N
        current_pos[x - 1] = 1

        for n in range(N):
            for i in range(N):
                answer_list[n][i] += current_pos[i]

            next_pos = [0] * N            
            for i in range(N):
                if current_pos[i] == 1:
                    for j in next_nodes[i]:
                        next_pos[j] = 1
            current_pos = next_pos
        

    for i in range(N + 1):
        for j in range(N):
            if answer_list[i][j] == len(x_set):
                print("Yes")
                return
    print("No")
                        








if __name__ == "__main__":
    main()
0