結果

問題 No.1610 She Loves Me, She Loves Me Not, ...
ユーザー brthyyjpbrthyyjp
提出日時 2021-07-22 18:01:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 78 ms / 2,000 ms
コード長 963 bytes
コンパイル時間 319 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 71,296 KB
最終ジャッジ日時 2024-07-17 21:17:50
合計ジャッジ時間 3,259 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

n, m = map(int, input().split())
g = [[] for i in range(n)]
ind = [0]*n
for i in range(m):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    g[a].append(b)
    g[b].append(a)
    ind[a] += 1
    ind[b] += 1

from collections import deque
def cycle_detectable_topological_sort(g, ind):
    V = len(g)
    order = []
    depth = [-1]*V
    q = deque([])
    for i in range(V):
        if ind[i] == 1:
            depth[i] = 0
            q.append(i)
    while q:
        v = q.popleft()
        if ind[v] == 1:
            order.append(v)
        cur_depth = depth[v]
        for u in g[v]:
            ind[u] -= 1
            if ind[u] == 1:
                depth[u] = max(depth[u], cur_depth+1)
                q.append(u)
    return order, depth

order, depth = cycle_detectable_topological_sort(g, ind)
if len(order)%2 == 1:
    print('Yes')
else:
    print('No')
0