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;
#define ll long long
const int N = 3e5 + 5;
ll dp[N][(1 << 5)], c[N];
vector<int> vec[N];
ll dfs(int node, int mask)
{
if((mask & (1 << c[node])) == 0)
return 0;
if(mask == (1 << c[node]))
return 1;
if(dp[node][mask] != -1)
return dp[node][mask];
dp[node][mask] = 0;
for(auto to : vec[node])
{
dp[node][mask] += dfs(to, mask ^ (1 << c[node]));
}
return dp[node][mask];
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// #ifndef ONLINE_JUDGE
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
// #endif
int n, m, k;
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;
vec[u].push_back(v);
vec[v].push_back(u);
}
memset(dp, -1, sizeof(dp));
ll cevap = 0;
for(int i = 1; i <= n; i++)
{
for(int j = 1; j < (1 << k); j++)
{
cevap += dfs(i, j);
}
}
cout << cevap - 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... |