#include<bits/stdc++.h>
using namespace std;
const int MX = 3e5 + 5;
vector<int>g[MX];
int n, m, k;
int tag[MX];
long long ans = 0;
long long dp[MX][32];
int bit(int x) {
return __builtin_popcount(x);
}
long long solve(int v, int mask) {
long long &ret = dp[v][mask];
if(ret!=-1) return ret;
ret = 0;
if(bit(mask)>1) {
ret = 1;
}
for(int u : g[v]) if(~mask>>tag[u]&1) {
ret += solve(u, mask|(1<<tag[u]));
}
return ret;
}
void PlayGround() {
cin>>n>>m>>k;
for(int i=1; i<=n; ++i) {
cin>>tag[i];
--tag[i];
}
for(int i=0; i<m; ++i) {
int u, v;
cin>>u>>v;
g[u].push_back(v);
g[v].push_back(u);
}
if(k==1) {
cout<<0<<'\n';
return;
}
memset(dp, -1, sizeof dp);
for(int i=1; i<=n; ++i) {
ans += solve(i, (1<<tag[i]));
}
cout<<ans<<'\n';
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
PlayGround();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
82508 KB |
Output is correct |
2 |
Correct |
32 ms |
82380 KB |
Output is correct |
3 |
Correct |
32 ms |
82404 KB |
Output is correct |
4 |
Correct |
32 ms |
82436 KB |
Output is correct |
5 |
Correct |
4 ms |
7372 KB |
Output is correct |
6 |
Correct |
32 ms |
82380 KB |
Output is correct |
7 |
Correct |
33 ms |
82504 KB |
Output is correct |
8 |
Correct |
33 ms |
82452 KB |
Output is correct |
9 |
Correct |
31 ms |
82516 KB |
Output is correct |
10 |
Correct |
31 ms |
82428 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
96 ms |
89004 KB |
Output is correct |
2 |
Correct |
87 ms |
88368 KB |
Output is correct |
3 |
Correct |
294 ms |
96576 KB |
Output is correct |
4 |
Correct |
113 ms |
90316 KB |
Output is correct |
5 |
Correct |
76 ms |
15180 KB |
Output is correct |
6 |
Correct |
209 ms |
94472 KB |
Output is correct |
7 |
Correct |
311 ms |
96540 KB |
Output is correct |
8 |
Correct |
306 ms |
97092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
82508 KB |
Output is correct |
2 |
Correct |
32 ms |
82380 KB |
Output is correct |
3 |
Correct |
32 ms |
82404 KB |
Output is correct |
4 |
Correct |
32 ms |
82436 KB |
Output is correct |
5 |
Correct |
4 ms |
7372 KB |
Output is correct |
6 |
Correct |
32 ms |
82380 KB |
Output is correct |
7 |
Correct |
33 ms |
82504 KB |
Output is correct |
8 |
Correct |
33 ms |
82452 KB |
Output is correct |
9 |
Correct |
31 ms |
82516 KB |
Output is correct |
10 |
Correct |
31 ms |
82428 KB |
Output is correct |
11 |
Correct |
96 ms |
89004 KB |
Output is correct |
12 |
Correct |
87 ms |
88368 KB |
Output is correct |
13 |
Correct |
294 ms |
96576 KB |
Output is correct |
14 |
Correct |
113 ms |
90316 KB |
Output is correct |
15 |
Correct |
76 ms |
15180 KB |
Output is correct |
16 |
Correct |
209 ms |
94472 KB |
Output is correct |
17 |
Correct |
311 ms |
96540 KB |
Output is correct |
18 |
Correct |
306 ms |
97092 KB |
Output is correct |
19 |
Correct |
98 ms |
88908 KB |
Output is correct |
20 |
Correct |
94 ms |
88288 KB |
Output is correct |
21 |
Correct |
287 ms |
96464 KB |
Output is correct |
22 |
Correct |
117 ms |
90332 KB |
Output is correct |
23 |
Correct |
78 ms |
15184 KB |
Output is correct |
24 |
Correct |
217 ms |
94452 KB |
Output is correct |
25 |
Correct |
289 ms |
96512 KB |
Output is correct |
26 |
Correct |
279 ms |
97164 KB |
Output is correct |
27 |
Correct |
99 ms |
88336 KB |
Output is correct |
28 |
Correct |
116 ms |
89692 KB |
Output is correct |
29 |
Correct |
341 ms |
96520 KB |
Output is correct |
30 |
Correct |
269 ms |
92872 KB |
Output is correct |
31 |
Correct |
274 ms |
92960 KB |
Output is correct |
32 |
Correct |
354 ms |
96588 KB |
Output is correct |
33 |
Correct |
31 ms |
82496 KB |
Output is correct |
34 |
Correct |
31 ms |
82444 KB |
Output is correct |
35 |
Correct |
31 ms |
82484 KB |
Output is correct |
36 |
Correct |
31 ms |
82508 KB |
Output is correct |
37 |
Correct |
4 ms |
7380 KB |
Output is correct |
38 |
Correct |
31 ms |
82516 KB |
Output is correct |
39 |
Correct |
32 ms |
82484 KB |
Output is correct |
40 |
Correct |
36 ms |
82508 KB |
Output is correct |
41 |
Correct |
35 ms |
82448 KB |
Output is correct |
42 |
Correct |
32 ms |
82380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
82476 KB |
Output is correct |
2 |
Correct |
63 ms |
84268 KB |
Output is correct |
3 |
Correct |
51 ms |
84300 KB |
Output is correct |
4 |
Correct |
93 ms |
87008 KB |
Output is correct |
5 |
Correct |
74 ms |
87716 KB |
Output is correct |
6 |
Correct |
121 ms |
87116 KB |
Output is correct |
7 |
Correct |
52 ms |
84352 KB |
Output is correct |
8 |
Correct |
105 ms |
87028 KB |
Output is correct |
9 |
Correct |
89 ms |
87676 KB |
Output is correct |
10 |
Correct |
96 ms |
87572 KB |
Output is correct |
11 |
Correct |
104 ms |
85604 KB |
Output is correct |
12 |
Correct |
85 ms |
86804 KB |
Output is correct |
13 |
Correct |
92 ms |
85700 KB |
Output is correct |
14 |
Correct |
120 ms |
87132 KB |
Output is correct |
15 |
Correct |
106 ms |
87092 KB |
Output is correct |
16 |
Correct |
32 ms |
82508 KB |
Output is correct |
17 |
Correct |
31 ms |
82380 KB |
Output is correct |
18 |
Correct |
31 ms |
82516 KB |
Output is correct |
19 |
Correct |
31 ms |
82488 KB |
Output is correct |
20 |
Correct |
4 ms |
7268 KB |
Output is correct |
21 |
Correct |
32 ms |
82380 KB |
Output is correct |
22 |
Correct |
32 ms |
82460 KB |
Output is correct |
23 |
Correct |
31 ms |
82488 KB |
Output is correct |
24 |
Correct |
31 ms |
82496 KB |
Output is correct |
25 |
Correct |
32 ms |
82512 KB |
Output is correct |