답안 #1011393

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1011393 2024-06-30T13:04:15 Z MilosMilutinovic Newspapers (CEOI21_newspapers) C++14
0 / 100
2 ms 2140 KB
#include <bits/stdc++.h>

using namespace std;

class dsu {
 public:
  vector<int> p;
  int n;

  dsu(int _n) : n(_n) {
    p.resize(n);
    iota(p.begin(), p.end(), 0);
  }

  inline int get(int x) {
    return (x == p[x] ? x : (p[x] = get(p[x])));
  }

  inline bool unite(int x, int y) {
    x = get(x);
    y = get(y);
    if (x != y) {
      p[x] = y;
      return true;
    }
    return false;
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> g(n);
  vector<pair<int, int>> e;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    --u; --v;
    g[u].push_back(v);
    g[v].push_back(u);
    e.emplace_back(u, v);
  }
  const int inf = (int) 1e9;
  vector<int> dist(1 << n, inf);
  vector<int> que(1, (1 << n) - 1);
  dist[que.back()] = 0;
  vector<pair<int, int>> prv(1 << n, {-1, -1});
  for (int b = 0; b < (int) que.size(); b++) {
    int mask = que[b];
    for (int i = 0; i < n; i++) {
      if (!(mask >> i & 1)) {
        continue;
      }
      int nmask = 0;
      for (int j = 0; j < n; j++) {
        if (i == j) {
          continue;
        }
        if (!(mask >> j & 1)) {
          continue;
        }
        for (int v : g[j]) {
          nmask |= (1 << v);
        }
      }
      if (dist[nmask] > dist[mask] + 1) {
        dist[nmask] = dist[mask] + 1;
        prv[nmask] = {mask, i};
        que.push_back(nmask);
      }
    }
  }
  bool ok = true;
  dsu d(n);
  for (auto& p : e) {
    if (!d.unite(p.first, p.second)) {
      ok = false;
    }
  }
  assert((dist[0] == inf) == !ok);
  if (dist[0] == inf) {
    cout << "NO" << '\n';
    return 0;
  }
  int c = 0;
  vector<int> res;
  while (c != (1 << n) - 1) {
    int nc = prv[c].first;
    res.push_back(prv[c].second);
    c = nc;
  }
  cout << "YES" << '\n';
  cout << (int) res.size() << '\n';
  for (int i : res) {
    cout << i + 1 << " ";
  }
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Runtime error 1 ms 604 KB Execution killed with signal 6
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Runtime error 2 ms 2140 KB Execution killed with signal 11
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Runtime error 1 ms 604 KB Execution killed with signal 6
10 Halted 0 ms 0 KB -