#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, k;
cin >> n >> m >> k;
int colors[n];
for(int i = 0; i < n; i++){
cin >> colors[i];
colors[i]--;
}
vector<int> adj[n];
for(int i = 0; i < m; i++){
int a, b;
cin >> a >> b;
a--;
b--;
adj[a].push_back(b);
adj[b].push_back(a);
}
vector<int> order(k);
for(int i = 0; i < k; i++){
order[i] = i;
}
long long res = 0;
vector<long long> dp(n);
vector<long long> next(n);
do {
for(int i = 0; i < n; i++){
if(colors[i] == order[0]){
dp[i] = 1;
}
else{
dp[i] = 0;
}
}
for(int i = 1; i < k; i++){
for(int j = 0; j < n; j++){
long long x = 0;
if(colors[j] == order[i]){
for(int y : adj[j]){
x += dp[y];
}
}
next[j] = x;
}
swap(dp, next);
if(is_sorted(order.begin() + i + 1, order.end())){
for(int j = 0; j < n; j++){
res += dp[j];
}
}
}
} while (next_permutation(order.begin(), order.end()));
cout << res << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
300 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
161 ms |
6860 KB |
Output is correct |
2 |
Correct |
125 ms |
6064 KB |
Output is correct |
3 |
Correct |
381 ms |
26140 KB |
Output is correct |
4 |
Correct |
208 ms |
9344 KB |
Output is correct |
5 |
Correct |
193 ms |
9424 KB |
Output is correct |
6 |
Correct |
290 ms |
20064 KB |
Output is correct |
7 |
Correct |
396 ms |
25936 KB |
Output is correct |
8 |
Correct |
377 ms |
26688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
300 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
161 ms |
6860 KB |
Output is correct |
12 |
Correct |
125 ms |
6064 KB |
Output is correct |
13 |
Correct |
381 ms |
26140 KB |
Output is correct |
14 |
Correct |
208 ms |
9344 KB |
Output is correct |
15 |
Correct |
193 ms |
9424 KB |
Output is correct |
16 |
Correct |
290 ms |
20064 KB |
Output is correct |
17 |
Correct |
396 ms |
25936 KB |
Output is correct |
18 |
Correct |
377 ms |
26688 KB |
Output is correct |
19 |
Correct |
146 ms |
6848 KB |
Output is correct |
20 |
Correct |
122 ms |
6140 KB |
Output is correct |
21 |
Correct |
391 ms |
26060 KB |
Output is correct |
22 |
Correct |
185 ms |
9312 KB |
Output is correct |
23 |
Correct |
185 ms |
9420 KB |
Output is correct |
24 |
Correct |
305 ms |
20028 KB |
Output is correct |
25 |
Correct |
362 ms |
26164 KB |
Output is correct |
26 |
Correct |
382 ms |
26700 KB |
Output is correct |
27 |
Correct |
159 ms |
6120 KB |
Output is correct |
28 |
Correct |
175 ms |
7800 KB |
Output is correct |
29 |
Correct |
594 ms |
26060 KB |
Output is correct |
30 |
Correct |
408 ms |
16572 KB |
Output is correct |
31 |
Correct |
366 ms |
16612 KB |
Output is correct |
32 |
Correct |
585 ms |
26060 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
1 ms |
300 KB |
Output is correct |
37 |
Correct |
1 ms |
212 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
300 KB |
Output is correct |
41 |
Correct |
1 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
296 KB |
Output is correct |
2 |
Correct |
60 ms |
2152 KB |
Output is correct |
3 |
Correct |
39 ms |
2144 KB |
Output is correct |
4 |
Correct |
94 ms |
8676 KB |
Output is correct |
5 |
Correct |
119 ms |
9412 KB |
Output is correct |
6 |
Correct |
355 ms |
8652 KB |
Output is correct |
7 |
Correct |
45 ms |
2064 KB |
Output is correct |
8 |
Correct |
156 ms |
8920 KB |
Output is correct |
9 |
Correct |
115 ms |
9416 KB |
Output is correct |
10 |
Correct |
135 ms |
9360 KB |
Output is correct |
11 |
Correct |
188 ms |
5404 KB |
Output is correct |
12 |
Correct |
232 ms |
7544 KB |
Output is correct |
13 |
Correct |
190 ms |
5496 KB |
Output is correct |
14 |
Correct |
392 ms |
8748 KB |
Output is correct |
15 |
Correct |
355 ms |
8832 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
296 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
296 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |