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 <fstream>
using namespace std;
const int nmax=300005;
long long dp[32][nmax];
int c[nmax],a[nmax],b[nmax];
int n,m,k,i,j,x,y;
long long ans;
int main()
{
//freopen("data.in","r",stdin);
cin>>n>>m>>k;
for(i=1;i<=n;i++)
{
cin>>c[i];
c[i]--;
}
for(i=1;i<=m;i++)
{
cin>>a[i]>>b[i];
}
for(j=1;j<=n;j++)
dp[(1<<c[j])][j]=1;
for(i=1;i<(1<<k);i++)
{
if((i&(i-1)))
for(j=1;j<=n;j++)
ans+=dp[i][j];
for(j=1;j<=m;j++)
{
x=a[j];y=b[j];
if(((1<<c[x])&i)&&(!((1<<c[y])&i)))
dp[i+(1<<c[y])][y]+=dp[i][x];
if((!((1<<c[x])&i))&&((1<<c[y])&i))
dp[i+(1<<c[x])][x]+=dp[i][y];
}
}
cout<<ans;
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... |