#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>
const int mxn = 3e5+10;
ll dp[33][mxn];
ll N,M,K;
int col[mxn];
vector<int> paths[mxn];
inline ll calc(int mask){
ll re = 0;
for(int i = 1;i<=N;i++){
re += dp[mask][i];
for(auto &nxt:paths[i]){
if(mask&(1<<col[nxt]))continue;
dp[mask^(1<<col[nxt])][nxt] += dp[mask][i];
}
}
return re;
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>N>>M>>K;
for(int i = 1;i<=N;i++){
cin>>col[i];
col[i]--;
dp[1<<col[i]][i] = 1;
}
for(int i = 0;i<M;i++){
int a,b;
cin>>a>>b;
paths[a].push_back(b);
paths[b].push_back(a);
}
ll ans = 0;
for(int i = 1;i<(1<<K);i++){
ll re = calc(i);
if(__builtin_popcount(i)>1)ans += re;
}
cout<<ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
39512 KB |
Output is correct |
2 |
Correct |
6 ms |
39516 KB |
Output is correct |
3 |
Correct |
4 ms |
23132 KB |
Output is correct |
4 |
Correct |
3 ms |
14936 KB |
Output is correct |
5 |
Correct |
2 ms |
10844 KB |
Output is correct |
6 |
Correct |
5 ms |
39512 KB |
Output is correct |
7 |
Correct |
5 ms |
39516 KB |
Output is correct |
8 |
Correct |
5 ms |
39516 KB |
Output is correct |
9 |
Correct |
4 ms |
33368 KB |
Output is correct |
10 |
Correct |
4 ms |
23132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
29576 KB |
Output is correct |
2 |
Correct |
50 ms |
29048 KB |
Output is correct |
3 |
Correct |
188 ms |
40016 KB |
Output is correct |
4 |
Correct |
64 ms |
22608 KB |
Output is correct |
5 |
Correct |
60 ms |
18648 KB |
Output is correct |
6 |
Correct |
173 ms |
36204 KB |
Output is correct |
7 |
Correct |
213 ms |
40164 KB |
Output is correct |
8 |
Correct |
251 ms |
40796 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
39512 KB |
Output is correct |
2 |
Correct |
6 ms |
39516 KB |
Output is correct |
3 |
Correct |
4 ms |
23132 KB |
Output is correct |
4 |
Correct |
3 ms |
14936 KB |
Output is correct |
5 |
Correct |
2 ms |
10844 KB |
Output is correct |
6 |
Correct |
5 ms |
39512 KB |
Output is correct |
7 |
Correct |
5 ms |
39516 KB |
Output is correct |
8 |
Correct |
5 ms |
39516 KB |
Output is correct |
9 |
Correct |
4 ms |
33368 KB |
Output is correct |
10 |
Correct |
4 ms |
23132 KB |
Output is correct |
11 |
Correct |
59 ms |
29576 KB |
Output is correct |
12 |
Correct |
50 ms |
29048 KB |
Output is correct |
13 |
Correct |
188 ms |
40016 KB |
Output is correct |
14 |
Correct |
64 ms |
22608 KB |
Output is correct |
15 |
Correct |
60 ms |
18648 KB |
Output is correct |
16 |
Correct |
173 ms |
36204 KB |
Output is correct |
17 |
Correct |
213 ms |
40164 KB |
Output is correct |
18 |
Correct |
251 ms |
40796 KB |
Output is correct |
19 |
Correct |
58 ms |
29524 KB |
Output is correct |
20 |
Correct |
52 ms |
29012 KB |
Output is correct |
21 |
Correct |
185 ms |
40016 KB |
Output is correct |
22 |
Correct |
76 ms |
22876 KB |
Output is correct |
23 |
Correct |
58 ms |
18512 KB |
Output is correct |
24 |
Correct |
117 ms |
36408 KB |
Output is correct |
25 |
Correct |
169 ms |
40020 KB |
Output is correct |
26 |
Correct |
213 ms |
41044 KB |
Output is correct |
27 |
Correct |
72 ms |
45476 KB |
Output is correct |
28 |
Correct |
86 ms |
46868 KB |
Output is correct |
29 |
Correct |
323 ms |
58708 KB |
Output is correct |
30 |
Correct |
173 ms |
53504 KB |
Output is correct |
31 |
Correct |
164 ms |
53456 KB |
Output is correct |
32 |
Correct |
310 ms |
58616 KB |
Output is correct |
33 |
Correct |
6 ms |
39516 KB |
Output is correct |
34 |
Correct |
5 ms |
39512 KB |
Output is correct |
35 |
Correct |
4 ms |
23132 KB |
Output is correct |
36 |
Correct |
3 ms |
14940 KB |
Output is correct |
37 |
Correct |
2 ms |
10844 KB |
Output is correct |
38 |
Correct |
5 ms |
39516 KB |
Output is correct |
39 |
Correct |
5 ms |
39516 KB |
Output is correct |
40 |
Correct |
5 ms |
39516 KB |
Output is correct |
41 |
Correct |
5 ms |
33372 KB |
Output is correct |
42 |
Correct |
4 ms |
23132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
57948 KB |
Output is correct |
2 |
Correct |
47 ms |
74312 KB |
Output is correct |
3 |
Correct |
19 ms |
24912 KB |
Output is correct |
4 |
Correct |
44 ms |
29384 KB |
Output is correct |
5 |
Correct |
33 ms |
29896 KB |
Output is correct |
6 |
Correct |
110 ms |
84744 KB |
Output is correct |
7 |
Correct |
27 ms |
41304 KB |
Output is correct |
8 |
Correct |
72 ms |
47820 KB |
Output is correct |
9 |
Correct |
48 ms |
48596 KB |
Output is correct |
10 |
Correct |
53 ms |
48288 KB |
Output is correct |
11 |
Correct |
77 ms |
83408 KB |
Output is correct |
12 |
Correct |
81 ms |
84476 KB |
Output is correct |
13 |
Correct |
75 ms |
83536 KB |
Output is correct |
14 |
Correct |
117 ms |
84768 KB |
Output is correct |
15 |
Correct |
107 ms |
84820 KB |
Output is correct |
16 |
Correct |
5 ms |
39512 KB |
Output is correct |
17 |
Correct |
5 ms |
39516 KB |
Output is correct |
18 |
Correct |
4 ms |
23132 KB |
Output is correct |
19 |
Correct |
2 ms |
14940 KB |
Output is correct |
20 |
Correct |
2 ms |
10844 KB |
Output is correct |
21 |
Correct |
5 ms |
39516 KB |
Output is correct |
22 |
Correct |
6 ms |
39516 KB |
Output is correct |
23 |
Correct |
6 ms |
39580 KB |
Output is correct |
24 |
Correct |
5 ms |
33368 KB |
Output is correct |
25 |
Correct |
4 ms |
23128 KB |
Output is correct |