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;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m, K;
cin >> n >> m >> K;
vector<int> cols;
for (int i = 0; i < n; i++)
{
int x;
cin >> x;
x--;
cols.push_back(x);
}
vector<vector<int>> graph(n);
for (int i = 0; i < m; i++)
{
int a, b;
cin >> a >> b;
a--; b--;
graph[a].push_back(b);
graph[b].push_back(a);
}
vector<vector<long long>> dp(n+1, vector<long long> ((1 << K) +1));
for (int i = 0; i < n; i++)
{
dp[i][1 << cols[i]] = 1;
}
for (int k = 1; k < (1 << K); k++)
{
for (int i = 0; i < n; i++)
{
if (!(k & (1 << cols[i])))
{
continue;
}
for (int v: graph[i])
{
if (!(k & (1 << cols[v])))
{
dp[v][k ^ (1 << cols[v])] += dp[i][k];
}
}
}
}
long long res = 0;
for(auto i: dp)
{
for (auto j: i)
{
res += j;
}
}
cout << res - n<< "\n";
return 0;
}
# | 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... |