結果

問題 No.2664 Prime Sum
ユーザー eve__fuyuki
提出日時 2024-04-01 09:55:14
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 1,001 bytes
コンパイル時間 2,302 ms
コンパイル使用メモリ 199,888 KB
最終ジャッジ日時 2025-02-20 18:45:39
ジャッジサーバーID
(参考情報)
judge1 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 37
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
void fast_io() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
}

int main() {
    fast_io();
    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> color(n, -1);
    deque<int> q;

    for (int i = 0; i < n; i++) {
        if (color[i] != -1) {
            continue;
        }
        q.push_back(i);
        color[i] = 0;
        while (!q.empty()) {
            int v = q.front();
            q.pop_front();
            for (int u : g[v]) {
                if (color[u] == -1) {
                    color[u] = 1 - color[v];
                    q.push_back(u);
                } else if (color[u] == color[v]) {
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "Yes" << endl;
}
0