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>
using namespace std;
typedef long long ll;
const int mxN = 3e5+10;
/*
9 11 4
1 2 3 4 1 2 1 2 2
1 2
1 3
2 3
2 4
3 6
6 2
6 5
4 3
4 5
7 8
9 8
*/
ll dp[mxN][1<<5];
int color[mxN];
vector<int> adj[mxN];
int N, M, K;
ll dfs(int node, int msk) {
if (~dp[node][msk]) return dp[node][msk];
dp[node][msk] = 1;
int nmsk = msk | (1 << (color[node]-1));
for (auto c : adj[node]) {
if ((1<<(color[c]-1)) & nmsk) continue;
dp[node][msk] += dfs(c, nmsk);
}
return dp[node][msk];
}
void solve() {
memset(dp, -1, sizeof dp);
cin >> N >> M >> K;
for (int i = 1; i <= N; i++)
cin >> color[i];
for (int i = 0; i < M; i++) {
int u, v;
cin >> u >>v;
adj[u].push_back(v);
adj[v].push_back(u);
}
ll ans = 0;
for (int i = 1; i <= N; i++)
ans += dfs(i, 0);
cout << ans - N;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
solve();
}
# | 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... |