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>
using namespace std;
#define ll long long
const int nmax = 3e5 + 5;
int color[nmax];
vector<vector<ll>> dp;
vector <int> g[nmax];
///dp[nod][msk] -> din nodul nod un lant care are culorile din msk o sg data
ll dfs(ll nod, ll msk = 0)
{
if (dp[nod][msk] != -1)
return dp[nod][msk];
if (msk & (1 << color[nod]))
{
dp[nod][msk] = 0;
return 0;
}
dp[nod][msk] = 1;
for (auto x : g[nod])
dp[nod][msk] += dfs(x, msk + (1 << color[nod]));
return dp[nod][msk];
}
int main()
{
int n, m, k, i;
ll ans = 0;
cin >> n >> m >> k;
for (i = 0; i < n; i++)
cin >> color[i], color[i]--;
while(m--)
{
int a, b;
cin >> a >> b;
a--; b--;
g[a].push_back(b);
g[b].push_back(a);
}
dp.resize(n);
for (i = 0; i < n; i++)
dp[i].resize((1 << k), -1);
for (i = 0; i < n; i++)
ans += dfs(i);
cout << ans - 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... |