#include<iostream>
#include<stdio.h>
#include<math.h>
#include<map>
#include<string>
#include<algorithm>
#include<vector>
#include<string.h>
#include<utility>
#include<set>
#include<cmath>
#include<queue>
#include<deque>
#include<functional>
#include<stack>
#include<limits.h>
#include<iomanip>
#include<unordered_map>
#include<numeric>
#include<tuple>
#include<bitset>
using namespace std;
#define MOD 1000000007
#define int long long
#define ss second
#define ff first
#define endl '\n'
typedef pair<int,int> pp;
signed main(){
// freopen("file.in", "r", stdin);
// freopen("file.out", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,m,k; cin>>n>>m>>k;
vector<int> v[n],c(n);
for(int i=0; i<n; i++) cin>>c[i],c[i]--;
for(int i=0; i<m; i++){
int a,b; cin>>a>>b,a--,b--;
v[a].push_back(b);
v[b].push_back(a);
}
vector<vector<int> > dp(n,vector<int>(1<<k));
for(int i=0; i<n; i++) dp[i][(1<<c[i])]=1;
for(int l=2; l<=k; l++){
for(int i=0; i<n; i++){
for(int z=0; z<(1<<k); z++){
if(__builtin_popcount(z)==l&&(z&(1<<c[i]))!=0){
for(auto node: v[i]) dp[i][z]+=dp[node][z^(1<<c[i])];
}
}
}
}
int ans=0;
for(int i=0; i<n; i++){
for(int z=0; z<(1<<k); z++){
ans+=dp[i][z];
}
}
cout<<ans-n;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
600 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
460 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
60 ms |
10660 KB |
Output is correct |
2 |
Correct |
39 ms |
9600 KB |
Output is correct |
3 |
Correct |
341 ms |
55312 KB |
Output is correct |
4 |
Correct |
71 ms |
14176 KB |
Output is correct |
5 |
Correct |
63 ms |
13652 KB |
Output is correct |
6 |
Correct |
225 ms |
40016 KB |
Output is correct |
7 |
Correct |
348 ms |
55368 KB |
Output is correct |
8 |
Correct |
364 ms |
56044 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
600 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
460 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
60 ms |
10660 KB |
Output is correct |
12 |
Correct |
39 ms |
9600 KB |
Output is correct |
13 |
Correct |
341 ms |
55312 KB |
Output is correct |
14 |
Correct |
71 ms |
14176 KB |
Output is correct |
15 |
Correct |
63 ms |
13652 KB |
Output is correct |
16 |
Correct |
225 ms |
40016 KB |
Output is correct |
17 |
Correct |
348 ms |
55368 KB |
Output is correct |
18 |
Correct |
364 ms |
56044 KB |
Output is correct |
19 |
Correct |
55 ms |
10576 KB |
Output is correct |
20 |
Correct |
45 ms |
9820 KB |
Output is correct |
21 |
Correct |
393 ms |
55396 KB |
Output is correct |
22 |
Correct |
65 ms |
14164 KB |
Output is correct |
23 |
Correct |
61 ms |
13584 KB |
Output is correct |
24 |
Correct |
208 ms |
40056 KB |
Output is correct |
25 |
Correct |
366 ms |
55120 KB |
Output is correct |
26 |
Correct |
368 ms |
55984 KB |
Output is correct |
27 |
Correct |
53 ms |
9808 KB |
Output is correct |
28 |
Correct |
65 ms |
12624 KB |
Output is correct |
29 |
Correct |
504 ms |
74324 KB |
Output is correct |
30 |
Correct |
267 ms |
42560 KB |
Output is correct |
31 |
Correct |
289 ms |
42648 KB |
Output is correct |
32 |
Correct |
555 ms |
74180 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
600 KB |
Output is correct |
35 |
Correct |
1 ms |
456 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
344 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
456 KB |
Output is correct |
2 |
Correct |
16 ms |
3420 KB |
Output is correct |
3 |
Correct |
12 ms |
3160 KB |
Output is correct |
4 |
Correct |
74 ms |
18680 KB |
Output is correct |
5 |
Correct |
48 ms |
18896 KB |
Output is correct |
6 |
Correct |
184 ms |
37400 KB |
Output is correct |
7 |
Correct |
14 ms |
3360 KB |
Output is correct |
8 |
Correct |
112 ms |
24656 KB |
Output is correct |
9 |
Correct |
83 ms |
25068 KB |
Output is correct |
10 |
Correct |
113 ms |
25028 KB |
Output is correct |
11 |
Correct |
95 ms |
20268 KB |
Output is correct |
12 |
Correct |
97 ms |
28720 KB |
Output is correct |
13 |
Correct |
100 ms |
20388 KB |
Output is correct |
14 |
Correct |
214 ms |
37412 KB |
Output is correct |
15 |
Correct |
205 ms |
37468 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |