#include<bits/stdc++.h>
using namespace std;
#define int long long
int n , m , k , ans = 0;
vector<int> visited , color;
vector<vector<int>> g , dp , ndp;
void dfs(int u , int len){
visited[u] = 1;
for(int i = 0;i < g[u].size();i ++){
for(int msk = 0;msk < (1 << k);msk ++){
if(msk & (1 << color[u]) && __builtin_popcount(msk) == len){
dp[u][msk] += ndp[g[u][i]][msk ^ (1 << color[u])];
}
}
if(!visited[g[u][i]]){
dfs(g[u][i] , len);
}
}
}
main(){
cin >> n >> m >> k;
color = vector<int>(n + 1);
g = vector<vector<int>>(n + 1);
dp = vector<vector<int>>(n + 1 , vector<int>(1 << k));
for(int i = 1;i <= n;i ++){
cin >> color[i];
--color[i];
dp[i][1 << color[i]] = 1;
}
for(int i = 1;i <= m;i ++){
int u , v;
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
for(int i = 1;i < k;i ++){
ndp = dp;
visited = vector<int>(n + 1);
dp = vector<vector<int>>(n + 1 , vector<int>(1 << k));
for(int j = 1;j <= n;j ++){
if(!visited[j]){
dfs(j , i + 1);
}
for(int msk = 0;msk < (1 << k);msk ++){
ans += dp[j][msk];
}
}
}
cout << ans << endl;
}
Compilation message
paths.cpp: In function 'void dfs(long long int, long long int)':
paths.cpp:9:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
9 | for(int i = 0;i < g[u].size();i ++){
| ~~^~~~~~~~~~~~~
paths.cpp: At global scope:
paths.cpp:20:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
20 | main(){
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
145 ms |
11872 KB |
Output is correct |
2 |
Correct |
115 ms |
9812 KB |
Output is correct |
3 |
Correct |
740 ms |
128556 KB |
Output is correct |
4 |
Correct |
166 ms |
21136 KB |
Output is correct |
5 |
Correct |
136 ms |
14424 KB |
Output is correct |
6 |
Correct |
544 ms |
82152 KB |
Output is correct |
7 |
Correct |
619 ms |
118708 KB |
Output is correct |
8 |
Correct |
630 ms |
119216 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
145 ms |
11872 KB |
Output is correct |
12 |
Correct |
115 ms |
9812 KB |
Output is correct |
13 |
Correct |
740 ms |
128556 KB |
Output is correct |
14 |
Correct |
166 ms |
21136 KB |
Output is correct |
15 |
Correct |
136 ms |
14424 KB |
Output is correct |
16 |
Correct |
544 ms |
82152 KB |
Output is correct |
17 |
Correct |
619 ms |
118708 KB |
Output is correct |
18 |
Correct |
630 ms |
119216 KB |
Output is correct |
19 |
Correct |
147 ms |
11852 KB |
Output is correct |
20 |
Correct |
112 ms |
9976 KB |
Output is correct |
21 |
Correct |
695 ms |
128688 KB |
Output is correct |
22 |
Correct |
171 ms |
21640 KB |
Output is correct |
23 |
Correct |
150 ms |
14312 KB |
Output is correct |
24 |
Correct |
555 ms |
82172 KB |
Output is correct |
25 |
Correct |
665 ms |
118628 KB |
Output is correct |
26 |
Correct |
689 ms |
119208 KB |
Output is correct |
27 |
Correct |
148 ms |
10164 KB |
Output is correct |
28 |
Correct |
208 ms |
16292 KB |
Output is correct |
29 |
Correct |
1123 ms |
184904 KB |
Output is correct |
30 |
Correct |
818 ms |
98236 KB |
Output is correct |
31 |
Correct |
878 ms |
101300 KB |
Output is correct |
32 |
Correct |
985 ms |
175284 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
1 ms |
348 KB |
Output is correct |
41 |
Correct |
1 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
84 ms |
3616 KB |
Output is correct |
3 |
Correct |
36 ms |
3404 KB |
Output is correct |
4 |
Correct |
191 ms |
42900 KB |
Output is correct |
5 |
Correct |
181 ms |
40136 KB |
Output is correct |
6 |
Correct |
487 ms |
99352 KB |
Output is correct |
7 |
Correct |
49 ms |
3408 KB |
Output is correct |
8 |
Correct |
309 ms |
61808 KB |
Output is correct |
9 |
Correct |
276 ms |
58820 KB |
Output is correct |
10 |
Correct |
285 ms |
58888 KB |
Output is correct |
11 |
Correct |
276 ms |
50452 KB |
Output is correct |
12 |
Correct |
359 ms |
72936 KB |
Output is correct |
13 |
Correct |
285 ms |
49808 KB |
Output is correct |
14 |
Correct |
403 ms |
96108 KB |
Output is correct |
15 |
Correct |
409 ms |
96140 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
436 KB |
Output is correct |
22 |
Correct |
0 ms |
440 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
436 KB |
Output is correct |
25 |
Correct |
0 ms |
344 KB |
Output is correct |