-
Notifications
You must be signed in to change notification settings - Fork 2
/
paths.cpp
41 lines (37 loc) · 826 Bytes
/
paths.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <bits/stdc++.h>
#define int long long
using namespace std;
int N, M, K;
int c[300000];
vector<int> graph[300000];
int dp[300000][32];
int ans = 0;
int dfs(int id, int left){
if(dp[id][left] >= 0){
return dp[id][left];
}
dp[id][left] = 0;
for(int i : graph[id]){
if(!(left & (1 << c[i]))){
dp[id][left] += dfs(i, left | (1 << c[i])) + 1;
}
}
return dp[id][left];
}
signed main(){
cin >> N >> M >> K;
for(int i = 0; i < N; i++){
cin >> c[i];
c[i]--;
}
for(int i = 0; i < M; i++){
int u, v; cin >> u >> v;
graph[u-1].push_back(v-1);
graph[v-1].push_back(u-1);
}
fill(dp[0], dp[N-1]+32, -1);
for(int i = 0; i < N; i++){
ans += dfs(i, (1 << c[i]));
}
cout << ans << endl;
}