結果

問題 No.3694 犬猿の仲
コンテスト
ユーザー tnakao0123
提出日時 2026-09-10 14:05:24
言語 C++17
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 35 ms / 2,000 ms
+ 832µs
コード長 975 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 452 ms
コンパイル使用メモリ 75,252 KB
実行使用メモリ 15,616 KB
最終ジャッジ日時 2026-09-10 14:05:27
合計ジャッジ時間 2,162 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 11
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

/* -*- coding: utf-8 -*-
 *
 * 3694.cc:  No.3694 迥ャ迪ソ縺ョ莉イ - yukicoder
 */

#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>

using namespace std;

/* constant */

const int MAX_N = 200000;
const int MAX_M = 200000;

/* typedef */

using vi = vector<int>;
using qi = queue<int>;

/* global variables */

vi nbrs[MAX_N];
int ds[MAX_N];

/* subroutines */

/* main */

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    u--, v--;
    nbrs[u].push_back(v);
    nbrs[v].push_back(u);
  }

  fill(ds, ds + n, -1);
  for (int rt = 0; rt < n; rt++)
    if (ds[rt] < 0) {
      ds[rt] = 0;
      qi q;
      q.push(rt);

      while (! q.empty()) {
	int u = q.front(); q.pop();
	for (auto v: nbrs[u]) {
	  if (ds[v] < 0)
	    ds[v] = ds[u] ^ 1, q.push(v);
	  else if (ds[v] == ds[u]) {
	    puts("No");
	    return 0;
	  }
	}
      }
    }

  puts("Yes");
  return 0;
}

0