結果
| 問題 | 
                            No.2664 Prime Sum
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2024-03-08 21:33:58 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 44 ms / 2,000 ms | 
| コード長 | 1,034 bytes | 
| コンパイル時間 | 2,101 ms | 
| コンパイル使用メモリ | 200,592 KB | 
| 最終ジャッジ日時 | 2025-02-20 02:12:55 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 37 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
void solve() {
  ll n, m;
  cin >> n >> m;
  vector g(n, vector<ll>());
  rep(i, m) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  vector<ll> color(n, -1);
  auto dfs = [&](auto self, ll u, ll p) -> bool {
    for (const auto v : g[u]) {
      if (v == p)
        continue;
      if (color[v] >= 0) {
        if (color[u] == color[v]) {
          return false;
        }
      } else {
        color[v] = 1 - color[u];
        if (!self(self, v, u)) {
          return false;
        }
      }
    }
    return true;
  };
  rep(i, n) {
    if (color[i] >= 0)
      continue;
    color[i] = 0;
    if (!dfs(dfs, i, -1)) {
      cout << "No" << '\n';
      return;
    }
  }
  cout << "Yes" << '\n';
}
int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  int T = 1;
  for (int t = 0; t < T; t++) {
    solve();
  }
  return 0;
}