結果
| 問題 | 
                            No.2664 Prime Sum
                             | 
                    
| コンテスト | |
| ユーザー | 
                             timi
                         | 
                    
| 提出日時 | 2024-03-08 21:17:58 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 77 ms / 2,000 ms | 
| コード長 | 870 bytes | 
| コンパイル時間 | 823 ms | 
| コンパイル使用メモリ | 82,156 KB | 
| 実行使用メモリ | 68,736 KB | 
| 最終ジャッジ日時 | 2024-09-29 18:55:13 | 
| 合計ジャッジ時間 | 3,492 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 37 | 
ソースコード
#N,M=map(int, input().split())
n,w = map(int,input().split())
g = [[] for i in range(n)]
for i in range(w):
  x,y = map(int,input().split()) 
  x-=1;y-=1
  g[x].append(y)
  g[y].append(x)
color = [0] * n #color[i]:点iの色(1 or -1)。但し塗られていないときは0とする
def f(v,c):
    #頂点vに隣接する頂点全てを塗るあるいは判定する
    color[v] = c
    for i in range(len(g[v])):
        if color[ g[v][i] ] == c:
            return False
        elif color[ g[v][i] ] == 0 and not f(g[v][i],-c):
            #(g[v][i]がまだ塗られていない かつ そこを-cで塗っても問題ない) ではないなら
            return False
    return True
k = 1 #判定 1ならYes -1ならNo
for i in range(n):
    if color[i] == 0:
        if not f(i,1):
            k = -1
if k == 1:
    print('Yes')
else:
    print('No')
            
            
            
        
            
timi