This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n, m, k, colours[300005], dp[300005][35], ans;
vector<int> adj[300005];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m >> k;
for (int i = 1; i <= n; i++) {
cin >> colours[i];
colours[i]--;
dp[i][1 << colours[i]] = 1;
}
for (int i = 0, a, b; i < m; i++) {
cin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
}
for (int i = 2; i <= 5; i++) {
vector<int> nxt;
for (int j = 1; j < 32; j++) {
if (__builtin_popcount(j) == i) {
nxt.push_back(j);
}
}
for (int j = 1; i <= n; j++) {
for (int k : adj[j]) {
for (int m : nxt) {
if (m >> colours[j] & 1) {
dp[j][m] += dp[k][m ^ (1 << colours[j])];
}
}
}
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j < 32; j++) {
ans += dp[i][j];
}
}
cout << ans - n << "\n";
}
# | 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... |