# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
62820 | SpaimaCarpatilor | Paths (BOI18_paths) | C++17 | 688 ms | 102932 KiB |
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 N, M, K, c[300009];
long long *dp[32];
vector < int > v[300009];
int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);
scanf ("%d %d %d", &N, &M, &K);
for (int i=1; i<=N; i++)
scanf ("%d", &c[i]), c[i] --;
while (M --)
{
int x, y;
scanf ("%d %d", &x, &y);
v[x].push_back (y);
v[y].push_back (x);
}
for (int i=0; i<(1 << K); i++)
dp[i] = new long long[N + 1] ();
long long ans = 0;
for (int msk = 1; msk < (1 << K); msk ++)
for (int i=1; i<=N; i++)
if ((msk >> c[i]) & 1)
{
if (msk == (1 << c[i])) dp[msk][i] = 1;
else
{
for (auto j : v[i])
dp[msk][i] += dp[msk ^ (1 << c[i])][j];
}
ans += dp[msk][i];
/* if (dp[msk][i] > 0)
printf ("(%d, %d) -> %lld\n", msk, i, dp[msk][i]);*/
}
printf ("%lld\n", ans - N);
return 0;
}
Compilation message (stderr)
# | 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... |