#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF 9223372036854775807
int memo[1<<5][300009];
int n, m, k;
vector<int> Graph[300009];
vector<int> v;
int dp(int mask, int node){
if(memo[mask][node] != -1) return memo[mask][node];
int ans = 0;
bool verif = false;
for(int i = 4; i >= 0; i--){
if(1<<i & mask){
if(verif) ans = 1;
else verif = true;
}
}
for(int a : Graph[node]){
if(!(mask & (1<<v[a]))){
ans+=dp(mask | (1<<v[a]), a);
}
}
//cout << mask << ' ' << node << ' ' << ans << endl;
return memo[mask][node] = ans;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m >> k;
for(int i = 0; i < (1<<5); i++){
for(int j = 0; j < 300009; j++){
memo[i][j] = -1;
}
}
v.resize(n);
for(int i = 0; i < n; i++){
cin >> v[i];
v[i]--;
}
for(int i = 0; i < m; i++){
int a, b;
cin >>a >> b;
a--;
b--;
Graph[a].push_back(b);
Graph[b].push_back(a);
}
int ans = 0;
for(int i = 0; i < n; i++){
ans+=dp(1<<v[i], i);
}
cout << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
65 ms |
82552 KB |
Output is correct |
2 |
Correct |
66 ms |
82540 KB |
Output is correct |
3 |
Correct |
66 ms |
82524 KB |
Output is correct |
4 |
Correct |
67 ms |
82484 KB |
Output is correct |
5 |
Correct |
67 ms |
82552 KB |
Output is correct |
6 |
Correct |
66 ms |
82552 KB |
Output is correct |
7 |
Correct |
66 ms |
82568 KB |
Output is correct |
8 |
Correct |
66 ms |
82552 KB |
Output is correct |
9 |
Correct |
65 ms |
82552 KB |
Output is correct |
10 |
Correct |
66 ms |
82552 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
157 ms |
92504 KB |
Output is correct |
2 |
Correct |
125 ms |
91748 KB |
Output is correct |
3 |
Correct |
409 ms |
99952 KB |
Output is correct |
4 |
Correct |
212 ms |
94180 KB |
Output is correct |
5 |
Correct |
165 ms |
94200 KB |
Output is correct |
6 |
Correct |
317 ms |
97212 KB |
Output is correct |
7 |
Correct |
546 ms |
100016 KB |
Output is correct |
8 |
Correct |
438 ms |
100424 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
65 ms |
82552 KB |
Output is correct |
2 |
Correct |
66 ms |
82540 KB |
Output is correct |
3 |
Correct |
66 ms |
82524 KB |
Output is correct |
4 |
Correct |
67 ms |
82484 KB |
Output is correct |
5 |
Correct |
67 ms |
82552 KB |
Output is correct |
6 |
Correct |
66 ms |
82552 KB |
Output is correct |
7 |
Correct |
66 ms |
82568 KB |
Output is correct |
8 |
Correct |
66 ms |
82552 KB |
Output is correct |
9 |
Correct |
65 ms |
82552 KB |
Output is correct |
10 |
Correct |
66 ms |
82552 KB |
Output is correct |
11 |
Correct |
157 ms |
92504 KB |
Output is correct |
12 |
Correct |
125 ms |
91748 KB |
Output is correct |
13 |
Correct |
409 ms |
99952 KB |
Output is correct |
14 |
Correct |
212 ms |
94180 KB |
Output is correct |
15 |
Correct |
165 ms |
94200 KB |
Output is correct |
16 |
Correct |
317 ms |
97212 KB |
Output is correct |
17 |
Correct |
546 ms |
100016 KB |
Output is correct |
18 |
Correct |
438 ms |
100424 KB |
Output is correct |
19 |
Correct |
165 ms |
92536 KB |
Output is correct |
20 |
Correct |
136 ms |
91748 KB |
Output is correct |
21 |
Correct |
517 ms |
100092 KB |
Output is correct |
22 |
Correct |
230 ms |
94200 KB |
Output is correct |
23 |
Correct |
210 ms |
94428 KB |
Output is correct |
24 |
Correct |
393 ms |
97256 KB |
Output is correct |
25 |
Correct |
557 ms |
100088 KB |
Output is correct |
26 |
Correct |
507 ms |
100420 KB |
Output is correct |
27 |
Correct |
150 ms |
92032 KB |
Output is correct |
28 |
Correct |
226 ms |
94060 KB |
Output is correct |
29 |
Correct |
606 ms |
100088 KB |
Output is correct |
30 |
Correct |
683 ms |
96460 KB |
Output is correct |
31 |
Correct |
459 ms |
96620 KB |
Output is correct |
32 |
Correct |
623 ms |
100088 KB |
Output is correct |
33 |
Correct |
68 ms |
82552 KB |
Output is correct |
34 |
Correct |
66 ms |
82552 KB |
Output is correct |
35 |
Correct |
67 ms |
82552 KB |
Output is correct |
36 |
Correct |
66 ms |
82552 KB |
Output is correct |
37 |
Correct |
65 ms |
82552 KB |
Output is correct |
38 |
Correct |
66 ms |
82552 KB |
Output is correct |
39 |
Correct |
65 ms |
82552 KB |
Output is correct |
40 |
Correct |
66 ms |
82552 KB |
Output is correct |
41 |
Correct |
65 ms |
82552 KB |
Output is correct |
42 |
Correct |
68 ms |
82532 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
65 ms |
82552 KB |
Output is correct |
2 |
Correct |
100 ms |
85420 KB |
Output is correct |
3 |
Correct |
89 ms |
85368 KB |
Output is correct |
4 |
Correct |
166 ms |
88204 KB |
Output is correct |
5 |
Correct |
120 ms |
88684 KB |
Output is correct |
6 |
Correct |
166 ms |
88312 KB |
Output is correct |
7 |
Correct |
85 ms |
85336 KB |
Output is correct |
8 |
Correct |
149 ms |
88172 KB |
Output is correct |
9 |
Correct |
121 ms |
88684 KB |
Output is correct |
10 |
Correct |
159 ms |
88916 KB |
Output is correct |
11 |
Correct |
140 ms |
86684 KB |
Output is correct |
12 |
Correct |
110 ms |
87528 KB |
Output is correct |
13 |
Correct |
137 ms |
87104 KB |
Output is correct |
14 |
Correct |
217 ms |
88256 KB |
Output is correct |
15 |
Correct |
201 ms |
88412 KB |
Output is correct |
16 |
Correct |
65 ms |
82552 KB |
Output is correct |
17 |
Correct |
66 ms |
82552 KB |
Output is correct |
18 |
Correct |
56 ms |
82552 KB |
Output is correct |
19 |
Correct |
56 ms |
82524 KB |
Output is correct |
20 |
Correct |
57 ms |
82552 KB |
Output is correct |
21 |
Correct |
56 ms |
82552 KB |
Output is correct |
22 |
Correct |
66 ms |
82552 KB |
Output is correct |
23 |
Correct |
65 ms |
82552 KB |
Output is correct |
24 |
Correct |
66 ms |
82524 KB |
Output is correct |
25 |
Correct |
56 ms |
82552 KB |
Output is correct |