結果

問題 No.2664 Prime Sum
ユーザー keisuke6
提出日時 2024-03-08 22:13:00
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 871 bytes
コンパイル時間 2,120 ms
コンパイル使用メモリ 200,372 KB
最終ジャッジ日時 2025-02-20 02:30:53
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 37
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
    int N,M;
    cin>>N>>M;
    vector<vector<int>> G(N);
    for(int i=0;i<M;i++){
        int a,b;
        cin>>a>>b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    vector<int> dist(N,-1);
    for(int i=0;i<N;i++)if(dist[i] == -1){
        dist[i] = 0;
        queue<int> q;
        q.push(i);
        while(!q.empty()){
            int pos = q.front();
            q.pop();
            for(int x:G[pos]){
                if(dist[x] == -1 || dist[x]%2 != dist[pos]%2){
                    if(dist[x] == -1) q.push(x);
                    dist[x] = 1-dist[pos]%2;
                }
                else{
                    cout<<"No"<<endl;
                    return 0;
                }
            }
        }
    }
    cout<<"Yes"<<endl;
}
0