結果

問題 No.2664 Prime Sum
ユーザー ripityripity
提出日時 2024-03-08 21:12:03
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 648 bytes
コンパイル時間 1,936 ms
コンパイル使用メモリ 208,136 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-09-29 18:52:38
合計ジャッジ時間 2,802 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 37
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int 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);
  }
  string ans = "Yes";
  vector<int> c(n, -1);
  auto dfs = [&](auto dfs, int cur) -> void {
    for( int &nxt : G[cur] ) {
      if( c[nxt] == -1 ) {
        c[nxt] = 1-c[cur];
        dfs(dfs, nxt);
      }else if( c[nxt] == c[cur] ) {
        ans = "No";
      }
    }
  };
  for( int i = 0; i < n; i++ ) {
    if( c[i] == -1 ) {
      c[i] = 0;
      dfs(dfs, i);
    }
  }
  cout << ans << endl;
}
0