이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//#pragma GCC optimize("O3", "unroll-loops")
//#pragma GCC target("avx2", "popcnt")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
const ll inf = 1e18;
vector<int> col_v;
vector<vector<int>> g;
ll ans;
int main() {
srand(time(0));
cin.tie(0)->sync_with_stdio(false);
#ifdef sunnatov
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int n, m, k;
cin >> n >> m >> k;
col_v.assign(n + 1, 0);
g.assign(n + 1, {});
for (int i = 1; i <= n; i++) cin >> col_v[i];
for (int i = 1; i <= n; i++) col_v[i] = 1 << (col_v[i] - 1);
for (int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
g[u].emplace_back(v);
g[v].emplace_back(u);
}
vector dp(1 << k, vector(n + 1, 0ll));
for (int i = 1; i <= n; i++) dp[col_v[i]][i] = 1;
for (int bt = 1; bt < (1 << k); bt++) {
for (int u = 1; u <= n; u++) {
for (int v: g[u]) {
if (bt & col_v[v]) continue;
dp[bt | col_v[v]][v] += dp[bt][u];
}
}
if (__builtin_popcount(bt) == 1) continue;
for (int u = 1; u <= n; u++) ans += dp[bt][u];
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |