Submission #679670

#TimeUsernameProblemLanguageResultExecution timeMemory
679670peijarPaths (BOI18_paths)C++17
100 / 100
622 ms74056 KiB
#include <bits/stdc++.h>
#define int long long
using namespace std;

namespace std {
template <typename T> ostream &operator<<(ostream &out, const vector<T> &vec) {
  out << "[";
  for (int i = 0; i < (int)vec.size(); ++i) {
    out << vec[i];
    if (i + 1 < (int)vec.size())
      out << ", ";
  }
  return out << "]";
}
} // namespace std

void dbg_out() { cout << endl; }
template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) {
  cout << ' ' << H;
  dbg_out(T...);
}

#ifdef DEBUG
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

signed main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int nbSommet, nbAretes, nbCouleurs;
  cin >> nbSommet >> nbAretes >> nbCouleurs;
  vector<vector<int>> dp(nbSommet, vector<int>(1 << nbCouleurs));
  vector<int> col(nbSommet);
  for (int &c : col) {
    cin >> c;
    --c;
  }
  vector<vector<int>> adj(nbSommet);
  for (int i = 0; i < nbAretes; ++i) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  for (int dejaVu = (1 << nbCouleurs) - 1; dejaVu >= 0; --dejaVu) {
    for (int u = 0; u < nbSommet; ++u) {
      int &cur = dp[u][dejaVu];
      cur = 1;
      for (int v : adj[u])
        if (!((1 << col[v]) & dejaVu))
          cur += dp[v][dejaVu | (1 << col[v])];
    }
  }
  int sol = 0;
  for (int u = 0; u < nbSommet; ++u)
    sol += dp[u][1 << col[u]] - 1;
  cout << sol << endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...