#include <bits/stdc++.h>
using namespace std ;
const int MAX = 3e5 + 10 ;
int arr[MAX] ;
int n , m , k ;
vector< vector<int> >adj(MAX) ;
long long dp[MAX][64] ;
void dfs(int node , int mask)
{
if(dp[node][mask])
return ;
dp[node][mask] = 1 ;
for(auto &child : adj[node])
{
if((mask & (1 << arr[child])))
continue ;
dfs(child , mask | (1 << arr[child])) ;
dp[node][mask] += dp[child][mask | (1 << arr[child])] ;
}
}
int main()
{
ios_base::sync_with_stdio(0) ;
cin.tie(0) ;
cin>>n>>m>>k ;
for(int i = 1 ; i <= n ; ++i)
{
cin>>arr[i] ;
arr[i]-- ;
}
for(int i = 0 ; i < m ; ++i)
{
int x , y ;
cin>>x>>y ;
adj[x].push_back(y) ;
adj[y].push_back(x) ;
}
long long ans = 0 ;
for(int i = 1 ; i <= n ; ++i)
{
dfs(i , (1 << arr[i])) ;
ans += dp[i][(1 << arr[i])] - 1 ;
}
return cout<<ans<<"\n" , 0 ;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7372 KB |
Output is correct |
2 |
Correct |
4 ms |
7372 KB |
Output is correct |
3 |
Correct |
4 ms |
7372 KB |
Output is correct |
4 |
Correct |
4 ms |
7372 KB |
Output is correct |
5 |
Correct |
4 ms |
7372 KB |
Output is correct |
6 |
Correct |
4 ms |
7372 KB |
Output is correct |
7 |
Correct |
3 ms |
7372 KB |
Output is correct |
8 |
Correct |
4 ms |
7372 KB |
Output is correct |
9 |
Correct |
4 ms |
7372 KB |
Output is correct |
10 |
Correct |
4 ms |
7372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
66 ms |
13444 KB |
Output is correct |
2 |
Correct |
57 ms |
11372 KB |
Output is correct |
3 |
Correct |
352 ms |
171312 KB |
Output is correct |
4 |
Correct |
128 ms |
30280 KB |
Output is correct |
5 |
Correct |
103 ms |
30188 KB |
Output is correct |
6 |
Correct |
236 ms |
119456 KB |
Output is correct |
7 |
Correct |
337 ms |
171616 KB |
Output is correct |
8 |
Correct |
376 ms |
172292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7372 KB |
Output is correct |
2 |
Correct |
4 ms |
7372 KB |
Output is correct |
3 |
Correct |
4 ms |
7372 KB |
Output is correct |
4 |
Correct |
4 ms |
7372 KB |
Output is correct |
5 |
Correct |
4 ms |
7372 KB |
Output is correct |
6 |
Correct |
4 ms |
7372 KB |
Output is correct |
7 |
Correct |
3 ms |
7372 KB |
Output is correct |
8 |
Correct |
4 ms |
7372 KB |
Output is correct |
9 |
Correct |
4 ms |
7372 KB |
Output is correct |
10 |
Correct |
4 ms |
7372 KB |
Output is correct |
11 |
Correct |
66 ms |
13444 KB |
Output is correct |
12 |
Correct |
57 ms |
11372 KB |
Output is correct |
13 |
Correct |
352 ms |
171312 KB |
Output is correct |
14 |
Correct |
128 ms |
30280 KB |
Output is correct |
15 |
Correct |
103 ms |
30188 KB |
Output is correct |
16 |
Correct |
236 ms |
119456 KB |
Output is correct |
17 |
Correct |
337 ms |
171616 KB |
Output is correct |
18 |
Correct |
376 ms |
172292 KB |
Output is correct |
19 |
Correct |
65 ms |
16348 KB |
Output is correct |
20 |
Correct |
52 ms |
13512 KB |
Output is correct |
21 |
Correct |
353 ms |
171596 KB |
Output is correct |
22 |
Correct |
118 ms |
30332 KB |
Output is correct |
23 |
Correct |
116 ms |
30268 KB |
Output is correct |
24 |
Correct |
221 ms |
119472 KB |
Output is correct |
25 |
Correct |
337 ms |
171616 KB |
Output is correct |
26 |
Correct |
364 ms |
172328 KB |
Output is correct |
27 |
Correct |
61 ms |
13640 KB |
Output is correct |
28 |
Correct |
93 ms |
18656 KB |
Output is correct |
29 |
Correct |
421 ms |
171652 KB |
Output is correct |
30 |
Correct |
257 ms |
92876 KB |
Output is correct |
31 |
Correct |
307 ms |
92864 KB |
Output is correct |
32 |
Correct |
395 ms |
171644 KB |
Output is correct |
33 |
Correct |
4 ms |
7300 KB |
Output is correct |
34 |
Correct |
4 ms |
7376 KB |
Output is correct |
35 |
Correct |
4 ms |
7384 KB |
Output is correct |
36 |
Correct |
5 ms |
7376 KB |
Output is correct |
37 |
Correct |
4 ms |
7376 KB |
Output is correct |
38 |
Correct |
4 ms |
7392 KB |
Output is correct |
39 |
Correct |
4 ms |
7376 KB |
Output is correct |
40 |
Correct |
4 ms |
7376 KB |
Output is correct |
41 |
Correct |
4 ms |
7376 KB |
Output is correct |
42 |
Correct |
4 ms |
7376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
7372 KB |
Output is correct |
2 |
Correct |
33 ms |
8676 KB |
Output is correct |
3 |
Correct |
21 ms |
8720 KB |
Output is correct |
4 |
Correct |
98 ms |
60528 KB |
Output is correct |
5 |
Correct |
71 ms |
61336 KB |
Output is correct |
6 |
Correct |
113 ms |
60612 KB |
Output is correct |
7 |
Correct |
23 ms |
8636 KB |
Output is correct |
8 |
Correct |
102 ms |
60536 KB |
Output is correct |
9 |
Correct |
101 ms |
61268 KB |
Output is correct |
10 |
Correct |
112 ms |
61244 KB |
Output is correct |
11 |
Correct |
84 ms |
34416 KB |
Output is correct |
12 |
Correct |
69 ms |
47972 KB |
Output is correct |
13 |
Correct |
78 ms |
34464 KB |
Output is correct |
14 |
Correct |
136 ms |
60576 KB |
Output is correct |
15 |
Correct |
119 ms |
60652 KB |
Output is correct |
16 |
Correct |
5 ms |
7372 KB |
Output is correct |
17 |
Correct |
4 ms |
7372 KB |
Output is correct |
18 |
Correct |
4 ms |
7372 KB |
Output is correct |
19 |
Correct |
4 ms |
7372 KB |
Output is correct |
20 |
Correct |
4 ms |
7372 KB |
Output is correct |
21 |
Correct |
4 ms |
7404 KB |
Output is correct |
22 |
Correct |
4 ms |
7372 KB |
Output is correct |
23 |
Correct |
4 ms |
7372 KB |
Output is correct |
24 |
Correct |
4 ms |
7372 KB |
Output is correct |
25 |
Correct |
4 ms |
7244 KB |
Output is correct |