結果

問題 No.3275 Minesweeper on Graph
コンテスト
ユーザー tnakao0123
提出日時 2025-09-20 13:12:13
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 1 ms / 2,000 ms
+ 981µs
コード長 996 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 263 ms
コンパイル使用メモリ 68,656 KB
実行使用メモリ 5,888 KB
最終ジャッジ日時 2026-07-15 04:19:37
合計ジャッジ時間 5,087 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

/* -*- coding: utf-8 -*-
 *
 * 3275.cc:  No.3275 Minesweeper on Graph - yukicoder
 */

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

using namespace std;

/* constant */

const int MAX_N = 16;

/* typedef */

using vi = vector<int>;

/* global variables */

int as[MAX_N];
vi nbrs[MAX_N];

/* subroutines */

/* main */

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%d", as + i);
  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);
  }

  int nbits = 1 << n;
  for (int bits = 0; bits < nbits; bits++) {
    bool ok = true;
    for (int u = 0; ok && u < n; u++) {
      int sum = 0;
      for (auto v: nbrs[u]) sum += ((bits >> v) & 1);
      ok = (sum == as[u]);
    }

    if (ok) {
      puts("Yes");
      for (int i = 0; i < n; i++)
	printf("%d%c", (bits >> i) & 1, (i + 1 < n) ? ' ' : '\n');
      return 0;
    }
  }
  
  puts("No");
  
  return 0;
}
0