結果

問題 No.2664 Prime Sum
ユーザー るこーそー
提出日時 2024-10-02 00:31:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 75 ms / 2,000 ms
コード長 687 bytes
コンパイル時間 343 ms
コンパイル使用メモリ 82,372 KB
実行使用メモリ 69,888 KB
最終ジャッジ日時 2024-10-02 00:32:22
合計ジャッジ時間 3,349 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 37
権限があれば一括ダウンロードができます

ソースコード

diff #

n,m=map(int,input().split())
graph=[[] for _ in range(n)]
for _ in range(m):
    u,v=map(lambda x:int(x)-1,input().split())
    graph[u].append(v)
    graph[v].append(u)
    
color=[0]*n
def bipartite(v,c):
    res=[0,0]
    color[v]=c
    if c==1:res[0]+=1
    else:res[1]+=1
    
    for nv in graph[v]:
        if color[nv]==c:return [-1,-1]
        elif color[nv]==-c:continue
        else:
            black,white=bipartite(nv,-c)
            if black==-1 or white==-1:return [-1,-1]
            res[0]+=black
            res[1]+=white
    
    return res

for v in range(n):
    if color[v]:continue
    if bipartite(v,1)==[-1,-1]:
        print('No')
        exit()

print('Yes')
0