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 oo 1e12
#define fi first
#define se second
#define sp(iiii) setprecision(iiii)
#define IO ios_base::sync_with_stdio(false); cin.tie(0)
#define ms(aaaa,xxxx) memset(aaaa,xxxx,sizeof(aaaa))
#define cntbit(xxxx) __builtin_popcount(xxxx)
#define getbit(xxxx,aaaa) ((xxxx>>(aaaa-1))&1)
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pair<int,int>,int> piii;
typedef pair<long long,long long> pll;
typedef pair<pair<long long,long long>,long long> plll;
typedef pair<pair<long long,long long>,pair<long long,long long>> pllll;
typedef pair<pair<long long,long long>,bool> pllb;
const ll base=361;
const ll mod=1e9+7;
const ld eps=1e-5;
ll n,m,k,i,j,l,ii,a[500009],f[500009][43],res,u,v;
vector<ll> g[500009],t[509];
int main(){
IO;
cin>>n>>m>>k;
for (i=1;i<=n;i++) {
cin>>a[i];
}
for (i=1;i<=m;i++) {
cin>>u>>v;
g[u].push_back(v);
g[v].push_back(u);
}
for (i=1;i<=n;i++) {
f[i][(1<<(a[i]-1))]=1;
}
//cout<<(1<<k)<<'\n';
for (i=1;i<(1<<k);i++) {
t[cntbit(i)].push_back(i);
}
for (i=2;i<=k;i++) {
for (j=0;j<t[i].size();j++) {
//cout<<i<<' '<<t[i][j]<<'\n';
for (l=1;l<=n;l++) {
if ((t[i][j]&(1<<(a[l]-1)))!=0) {
for (ii=0;ii<g[l].size();ii++) {
//cout<<i<<' '<<l<<' '<<t[i][j]<<" - "<<g[l][ii]<<' '<<(t[i][j]^(1<<(a[l]-1)))<<'\n';
f[l][t[i][j]]+=f[g[l][ii]][t[i][j]^(1<<(a[l]-1))];
}
}
}
}
}
for (i=0;i<(1<<k);i++) {
if (cntbit(i)>=2) {
for (j=1;j<=n;j++) {
res+=f[j][i];
}
}
}
cout<<res<<'\n';
}
Compilation message (stderr)
paths.cpp: In function 'int main()':
paths.cpp:49:19: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | for (j=0;j<t[i].size();j++) {
| ~^~~~~~~~~~~~
paths.cpp:53:33: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | for (ii=0;ii<g[l].size();ii++) {
| ~~^~~~~~~~~~~~
# | 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... |