Submission #1011395

# Submission time Handle Problem Language Result Execution time Memory
1011395 2024-06-30T13:04:48 Z MilosMilutinovic Newspapers (CEOI21_newspapers) C++14
12 / 100
197 ms 524288 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;
    }
  }
  if (!ok) {
    assert(dist[0] == inf);
  }
  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;
}
# Verdict Execution time Memory 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 344 KB Output is correct
9 Correct 0 ms 424 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 0 ms 600 KB Output is correct
32 Correct 0 ms 604 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 0 ms 604 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 0 ms 860 KB Output is correct
37 Correct 1 ms 860 KB Output is correct
38 Correct 0 ms 604 KB Output is correct
39 Correct 1 ms 1116 KB Output is correct
40 Correct 1 ms 1116 KB Output is correct
41 Correct 1 ms 1116 KB Output is correct
42 Correct 1 ms 1116 KB Output is correct
43 Correct 1 ms 1884 KB Output is correct
44 Correct 1 ms 1884 KB Output is correct
45 Correct 1 ms 1884 KB Output is correct
46 Correct 1 ms 1880 KB Output is correct
47 Correct 1 ms 3420 KB Output is correct
48 Correct 2 ms 3420 KB Output is correct
49 Correct 2 ms 3416 KB Output is correct
50 Correct 2 ms 3420 KB Output is correct
51 Correct 3 ms 6488 KB Output is correct
52 Correct 3 ms 6492 KB Output is correct
53 Correct 3 ms 6588 KB Output is correct
54 Correct 2 ms 6492 KB Output is correct
55 Correct 3 ms 12636 KB Output is correct
56 Correct 3 ms 12636 KB Output is correct
57 Correct 4 ms 12636 KB Output is correct
58 Correct 3 ms 12636 KB Output is correct
59 Correct 4 ms 12632 KB Output is correct
60 Correct 3 ms 12636 KB Output is correct
61 Correct 3 ms 12636 KB Output is correct
62 Correct 5 ms 12888 KB Output is correct
63 Correct 3 ms 12720 KB Output is correct
64 Correct 4 ms 12636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 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 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Runtime error 3 ms 2140 KB Execution killed with signal 11
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 344 KB Output is correct
9 Correct 0 ms 424 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 0 ms 600 KB Output is correct
32 Correct 0 ms 604 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 0 ms 604 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 0 ms 860 KB Output is correct
37 Correct 1 ms 860 KB Output is correct
38 Correct 0 ms 604 KB Output is correct
39 Correct 1 ms 1116 KB Output is correct
40 Correct 1 ms 1116 KB Output is correct
41 Correct 1 ms 1116 KB Output is correct
42 Correct 1 ms 1116 KB Output is correct
43 Correct 1 ms 1884 KB Output is correct
44 Correct 1 ms 1884 KB Output is correct
45 Correct 1 ms 1884 KB Output is correct
46 Correct 1 ms 1880 KB Output is correct
47 Correct 1 ms 3420 KB Output is correct
48 Correct 2 ms 3420 KB Output is correct
49 Correct 2 ms 3416 KB Output is correct
50 Correct 2 ms 3420 KB Output is correct
51 Correct 3 ms 6488 KB Output is correct
52 Correct 3 ms 6492 KB Output is correct
53 Correct 3 ms 6588 KB Output is correct
54 Correct 2 ms 6492 KB Output is correct
55 Correct 3 ms 12636 KB Output is correct
56 Correct 3 ms 12636 KB Output is correct
57 Correct 4 ms 12636 KB Output is correct
58 Correct 3 ms 12636 KB Output is correct
59 Correct 4 ms 12632 KB Output is correct
60 Correct 3 ms 12636 KB Output is correct
61 Correct 3 ms 12636 KB Output is correct
62 Correct 5 ms 12888 KB Output is correct
63 Correct 3 ms 12720 KB Output is correct
64 Correct 4 ms 12636 KB Output is correct
65 Correct 1 ms 344 KB Output is correct
66 Correct 1 ms 348 KB Output is correct
67 Correct 1 ms 348 KB Output is correct
68 Correct 0 ms 348 KB Output is correct
69 Correct 0 ms 348 KB Output is correct
70 Correct 0 ms 348 KB Output is correct
71 Correct 1 ms 348 KB Output is correct
72 Correct 0 ms 348 KB Output is correct
73 Correct 0 ms 348 KB Output is correct
74 Correct 1 ms 344 KB Output is correct
75 Correct 0 ms 348 KB Output is correct
76 Correct 0 ms 348 KB Output is correct
77 Correct 0 ms 344 KB Output is correct
78 Correct 0 ms 348 KB Output is correct
79 Runtime error 197 ms 524288 KB Execution killed with signal 9
80 Halted 0 ms 0 KB -