# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
213442 | MKopchev | Paths (BOI18_paths) | C++14 | 420 ms | 54392 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;
const int nmax=3e5+42;
long long dp[32][nmax];
int colour[nmax];
vector<int> adj[nmax];
int n,m,k;
long long rec(int remain,int pos)
{
if(remain==0)return 1;
if(dp[remain][pos])return dp[remain][pos];
long long ret=1;//alone
for(auto nxt:adj[pos])
if((remain&(1<<colour[nxt])))ret=ret+rec(remain-(1<<colour[nxt]),nxt);
dp[remain][pos]=ret;
return ret;
}
int main()
{
scanf("%i%i%i",&n,&m,&k);
for(int i=1;i<=n;i++)
{
scanf("%i",&colour[i]);
colour[i]--;
}
int u,v;
for(int i=1;i<=m;i++)
{
scanf("%i%i",&u,&v);
adj[u].push_back(v);
adj[v].push_back(u);
}
long long ret=0;
for(int i=1;i<=n;i++)
ret=ret+rec((1<<k)-1-(1<<colour[i]),i)-1;
printf("%lld\n",ret);
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... |