이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
int c[300010];
int f[300010][1 << 5];
vector <int> adj[300010];
long long res;
int main() {
ios_base :: sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n >> m >> k;
for (int i = 1; i <= n; ++i) {
cin >> c[i];
--c[i];
}
for (int i = 1; i <= m; ++i) {
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
for (int mask = 1; mask < (1 << k); ++mask) {
if (__builtin_popcount(mask) == 1) {
int cl = __builtin_ctz(mask);
for (int u = 1; u <= n; ++u)
if (cl == c[u]) f[u][mask] = 1;
} else {
for (int u = 1; u <= n; ++u) {
if (!((mask >> c[u]) & 1)) continue;
for (auto v: adj[u]) {
if (c[u] == c[v]) continue;
f[u][mask] += f[v][mask ^ (1 << c[u])];
}
}
}
}
for (int mask = 1; mask < (1 << k); ++mask) {
if (__builtin_popcount(mask) == 1) continue;
for (int u = 1; u <= n; ++u) res += f[u][mask];
}
cout << res;
}
# | 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... |