#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MAXN (300005)
ll N,M,K;
vector<ll> v[MAXN];
ll colour[MAXN], dp[MAXN][(1ll<<5) + 1];
bool visited[MAXN][(1ll<<5) + 1];
int main() {
ios_base::sync_with_stdio(false);cin.tie(0);
cin>>N>>M>>K;
for(ll i = 0;i < N;i++){
cin>>colour[i];
dp[i][1ll<<colour[i]] = 1;
}
for(ll i = 0;i < M;i++){
ll a,b;
cin>>a>>b;
a--, b--;
v[a].push_back(b);
v[b].push_back(a);
}
for(ll bitmask = 0;bitmask < (1ll<<5);bitmask++){
for(ll x = 0;x < N;x++){
for(auto u : v[x]){
if((bitmask & (1ll<<colour[u])) == 0){
dp[u][bitmask | (1ll<<colour[u])] += dp[x][bitmask];
}
}
}
}
ll ans = 0;
for(ll bitmask = 0;bitmask < (1ll<<5);bitmask++){
for(ll x = 0;x < N;x++){
ans += dp[x][bitmask];
}
}
cout<<ans - N<<'\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
12636 KB |
Output is correct |
2 |
Correct |
3 ms |
12636 KB |
Output is correct |
3 |
Correct |
4 ms |
12636 KB |
Output is correct |
4 |
Correct |
3 ms |
12636 KB |
Output is correct |
5 |
Correct |
3 ms |
12636 KB |
Output is correct |
6 |
Correct |
3 ms |
12636 KB |
Output is correct |
7 |
Correct |
4 ms |
12636 KB |
Output is correct |
8 |
Correct |
3 ms |
12636 KB |
Output is correct |
9 |
Correct |
4 ms |
12636 KB |
Output is correct |
10 |
Correct |
4 ms |
12636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
134 ms |
21892 KB |
Output is correct |
2 |
Correct |
110 ms |
22100 KB |
Output is correct |
3 |
Correct |
880 ms |
103768 KB |
Output is correct |
4 |
Correct |
194 ms |
32340 KB |
Output is correct |
5 |
Correct |
147 ms |
32340 KB |
Output is correct |
6 |
Correct |
587 ms |
76736 KB |
Output is correct |
7 |
Correct |
875 ms |
103660 KB |
Output is correct |
8 |
Correct |
900 ms |
104172 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
12636 KB |
Output is correct |
2 |
Correct |
3 ms |
12636 KB |
Output is correct |
3 |
Correct |
4 ms |
12636 KB |
Output is correct |
4 |
Correct |
3 ms |
12636 KB |
Output is correct |
5 |
Correct |
3 ms |
12636 KB |
Output is correct |
6 |
Correct |
3 ms |
12636 KB |
Output is correct |
7 |
Correct |
4 ms |
12636 KB |
Output is correct |
8 |
Correct |
3 ms |
12636 KB |
Output is correct |
9 |
Correct |
4 ms |
12636 KB |
Output is correct |
10 |
Correct |
4 ms |
12636 KB |
Output is correct |
11 |
Correct |
134 ms |
21892 KB |
Output is correct |
12 |
Correct |
110 ms |
22100 KB |
Output is correct |
13 |
Correct |
880 ms |
103768 KB |
Output is correct |
14 |
Correct |
194 ms |
32340 KB |
Output is correct |
15 |
Correct |
147 ms |
32340 KB |
Output is correct |
16 |
Correct |
587 ms |
76736 KB |
Output is correct |
17 |
Correct |
875 ms |
103660 KB |
Output is correct |
18 |
Correct |
900 ms |
104172 KB |
Output is correct |
19 |
Correct |
125 ms |
24736 KB |
Output is correct |
20 |
Correct |
106 ms |
22108 KB |
Output is correct |
21 |
Correct |
843 ms |
103800 KB |
Output is correct |
22 |
Correct |
241 ms |
32340 KB |
Output is correct |
23 |
Correct |
152 ms |
32340 KB |
Output is correct |
24 |
Correct |
591 ms |
76728 KB |
Output is correct |
25 |
Correct |
908 ms |
103764 KB |
Output is correct |
26 |
Correct |
887 ms |
104336 KB |
Output is correct |
27 |
Correct |
114 ms |
22084 KB |
Output is correct |
28 |
Correct |
140 ms |
26220 KB |
Output is correct |
29 |
Correct |
932 ms |
103736 KB |
Output is correct |
30 |
Correct |
522 ms |
64452 KB |
Output is correct |
31 |
Correct |
559 ms |
64456 KB |
Output is correct |
32 |
Correct |
923 ms |
103656 KB |
Output is correct |
33 |
Correct |
3 ms |
12636 KB |
Output is correct |
34 |
Correct |
5 ms |
12708 KB |
Output is correct |
35 |
Correct |
3 ms |
12636 KB |
Output is correct |
36 |
Correct |
4 ms |
12636 KB |
Output is correct |
37 |
Correct |
3 ms |
12636 KB |
Output is correct |
38 |
Correct |
3 ms |
12636 KB |
Output is correct |
39 |
Correct |
4 ms |
12636 KB |
Output is correct |
40 |
Correct |
3 ms |
12636 KB |
Output is correct |
41 |
Correct |
4 ms |
12636 KB |
Output is correct |
42 |
Correct |
3 ms |
12636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
12632 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |