Menu

UVA 11065. A Gentlemen’s Agreement

February 16, 2017 - UVA

Language: C++

#include<bits/stdc++.h>
using namespace std;

using vi = vector<int>;
using ii = pair<int,int>;
using ll = long long;
using llu = unsigned long long;
const int INF = numeric_limits<int>::max();
const int MAX = 61;

llu M[MAX];

int vertices_count;
llu all;
llu sets_count;
int max_set_size;

void backtrack(int from, llu used, int size) {
  if (used == all) {
    sets_count++;
    max_set_size = max(max_set_size, size);
    return;
  }
  for (int i = from; i < vertices_count; i++) {
    if (used & (1llu << i)) continue;
    backtrack(i + 1, used | M[i], size + 1);
  }
}

int main() {
  int tcc;
  cin >> tcc;
  while (tcc--) {
    int edges_count;
    cin >> vertices_count >> edges_count;
    fill_n(M, MAX, 0);
    for (int i = 0; i < vertices_count; i++) M[i] = (1llu << i);
    while (edges_count--) {
      int a, b; cin >> a >> b;
      M[a] = M[a] | (1llu << b);
      M[b] = M[b] | (1llu << a);
    }
    max_set_size = 0;
    sets_count = 0;
    all = (1llu << vertices_count) - 1;
    backtrack(0, 0, 0);
    cout << sets_count << endl << max_set_size << endl;
  }
}
/*

The MIT License (MIT)

Copyright (c) 2013 Mikhail

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

*/

(82)

It's only fair to share...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInShare on VK

Author of this post : UnknownA AuthorA

Leave a Reply

Your email address will not be published. Required fields are marked *