Submission #19136068


Source Code Expand

Copy
#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
#define SZ(x) (int)((x).size())
template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> e(1 << n);
  for (int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    --x; --y;
    for (int S = 0; S < (1 << n); ++S) {
      if (((S >> x) & 1) && ((S >> y) & 1)) {
        e[S]++;
      }
    }
  }
  vector<bool> valid(1 << n);
  for (int S = 0; S < (1 << n); ++S) {
    int cnt = __builtin_popcount(S);
    valid[S] = (cnt * (cnt - 1) / 2 == e[S]);
  }
  vector<int> dp(1 << n);
  for (int S = 1; S < (1 << n); ++S) {
    dp[S] = inf<int>;
    int k = -1;
    for (int i = 0; i < n; ++i) {
      if ((S >> i) & 1) {
        k = i;
        break;
      }
    }
    int U = S ^ (1 << k);
    for (int T = U; ; T = (T - 1) & U) {
      if (!valid[T ^ (1 << k)]) continue;
      dp[S] = min(dp[S], dp[U ^ T] + 1);
      if (T == 0) break;
    }
  }
  cout << dp[(1 << n) - 1] << '\n';
  return 0;
}

Submission Info

Submission Time
Task F - Close Group
User cuiaoxiang
Language C++ (Clang 10.0.0)
Score 600
Code Size 3439 Byte
Status AC
Exec Time 346 ms
Memory 4992 KB

Compile Error

./Main.cpp:79:11: warning: unused variable 'MOD' [-Wunused-const-variable]
const int MOD = 1e9 + 7;
          ^
1 warning generated.

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status AC
AC × 44
Set Name Test Cases
Sample
All 01_sample.txt, 02_sample.txt, 03_sample.txt, 04_sample.txt, 05_tiny.txt, 06_tiny.txt, 07_tiny.txt, 08_tiny.txt, 09_tiny.txt, 10_tiny.txt, 11_tiny.txt, 12_small.txt, 13_small.txt, 14_small.txt, 15_small.txt, 16_small.txt, 17_small.txt, 18_small.txt, 19_small.txt, 20_small.txt, 21_small.txt, 22_small.txt, 23_small.txt, 24_small.txt, 25_small.txt, 26_small.txt, 27_large.txt, 28_large.txt, 29_large.txt, 30_large.txt, 31_large.txt, 32_large.txt, 33_large.txt, 34_large.txt, 35_large.txt, 36_large.txt, 37_large.txt, 38_large.txt, 39_large.txt, 40_large.txt, 41_large.txt, 42_max.txt, 43_max.txt, 44_max.txt
Case Name Status Exec Time Memory
01_sample.txt AC 4 ms 3028 KB
02_sample.txt AC 4 ms 3148 KB
03_sample.txt AC 2 ms 3072 KB
04_sample.txt AC 160 ms 4932 KB
05_tiny.txt AC 2 ms 3200 KB
06_tiny.txt AC 2 ms 3172 KB
07_tiny.txt AC 2 ms 3200 KB
08_tiny.txt AC 3 ms 3156 KB
09_tiny.txt AC 2 ms 3168 KB
10_tiny.txt AC 3 ms 3016 KB
11_tiny.txt AC 2 ms 3008 KB
12_small.txt AC 2 ms 3028 KB
13_small.txt AC 2 ms 3200 KB
14_small.txt AC 2 ms 3156 KB
15_small.txt AC 4 ms 3200 KB
16_small.txt AC 3 ms 3068 KB
17_small.txt AC 2 ms 3164 KB
18_small.txt AC 2 ms 3108 KB
19_small.txt AC 2 ms 3052 KB
20_small.txt AC 2 ms 3156 KB
21_small.txt AC 2 ms 3096 KB
22_small.txt AC 2 ms 3012 KB
23_small.txt AC 2 ms 3172 KB
24_small.txt AC 3 ms 3168 KB
25_small.txt AC 2 ms 3116 KB
26_small.txt AC 2 ms 3172 KB
27_large.txt AC 217 ms 4828 KB
28_large.txt AC 25 ms 3116 KB
29_large.txt AC 47 ms 3292 KB
30_large.txt AC 8 ms 3096 KB
31_large.txt AC 106 ms 3820 KB
32_large.txt AC 164 ms 4892 KB
33_large.txt AC 218 ms 4828 KB
34_large.txt AC 171 ms 4992 KB
35_large.txt AC 287 ms 4764 KB
36_large.txt AC 243 ms 4892 KB
37_large.txt AC 78 ms 3780 KB
38_large.txt AC 2 ms 3176 KB
39_large.txt AC 3 ms 3164 KB
40_large.txt AC 3 ms 3176 KB
41_large.txt AC 3 ms 3184 KB
42_max.txt AC 180 ms 4824 KB
43_max.txt AC 283 ms 4764 KB
44_max.txt AC 346 ms 4880 KB