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<bits/stdc++.h>
#define int long long
using namespace std;
typedef long long ll;
const int N = 3e5 + 10;
vector<int> Adj[N];
int n, m, k, ans, C[N], dp[N][1 << 5];
signed main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> n >> m >> k;
for (int i = 1; i <= n; i++) {
cin >> C[i]; C[i]--;
dp[i][(1 << C[i])] = 1;
}
for (int i = 0; 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 << 5); mask++) {
if (__builtin_popcount(mask) != 1) {
for (int i = 1; i <= n; i++) {
if (mask & (1 << C[i])) {
for (int u : Adj[i]) {
dp[i][mask] += dp[u][mask ^ (1 << C[i])];
}
ans += dp[i][mask];
}
}
}
}
cout << ans << '\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... |