Cod sursa(job #1838217)

Utilizator lflorin29Florin Laiu lflorin29 Data 31 decembrie 2016 14:46:16
Problema Colorare3 Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.78 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("colorare3.in");
ofstream fout("colorare3.out");

const int nmax = 1e5;
int n, k;
vector<int>g[nmax + 1];
const int mod = 1e9 + 7;
vector<pair<int, int>>mc;
bitset < nmax + 1 > in[nmax + 1];
int sol;
void backT(int lv) {
  if (lv >= mc.size()) {
    sol++;
    return;
  }

  for (int c = 1; c <= k; ++c) {
    if (!in[mc[lv].first][c] && !in[mc[lv].second][c]) {
      in[mc[lv].first][c] = 1;
      in[mc[lv].second][c] = 1;
      backT(lv + 1);
      in[mc[lv].first][c] = 0;
      in[mc[lv].second][c] = 0;
    }
  }
}

int main() {
  fin >> n >> k;

  for (int i = 0; i < n - 1; ++i) {
    int x, y;
    fin >> x >> y;
    mc.push_back(make_pair(x, y));
  }

  backT(0);
  cerr << sol;
}