結果

問題 No.2664 Prime Sum
ユーザー hiro1729hiro1729
提出日時 2024-03-08 21:02:30
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 845 bytes
コンパイル時間 3,729 ms
コンパイル使用メモリ 123,776 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-09-29 18:49:22
合計ジャッジ時間 2,786 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 37
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <queue>
using namespace std;

int main() {
    int n, m, a, b;
    cin >> n >> m;
    vector<vector<int>> graph(n);
    while (cin >> a >> b) { a--; b--; graph[a].push_back(b); graph[b].push_back(a);}
    vector<int> color(n, -1);
    for (int v = 0; v < n; v++) {
        if (color[v] != -1) continue;
        queue<int> que;
        color[v] = 0;
        que.push(v);
        while (!que.empty()) {
            int qv = que.front();
            que.pop();
            for (auto nv : graph[qv]) {
                if (color[nv] != -1) {
                    if (color[nv] == color[qv]) {cout << "No" << endl; return 0;}
                    continue;
                }
                color[nv] = 1 - color[qv];
                que.push(nv);
            }
        }
    }
    cout << "Yes" << endl;
}
0