#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=a; i<=b; ++i)
#define eb emplace_back
#define ll long long
#define V vector
const int maxn=3e5+7, maxk=5;
ll dp[maxn][1<<maxk];
int n, m, k;
V<int> A;
V<V<int>> con;
int main() {
cin.tie(0) -> ios_base::sync_with_stdio(0);
cin >> n >> m >> k;
A.resize(n+1);
con.resize(n+1);
FOR(i, 1, n) {
cin >> A[i];
--A[i];
dp[i][1<<A[i]]=1;
}
int a, b;
FOR(i, 1, m) {
cin >> a >> b;
con[a].eb(b);
con[b].eb(a);
}
ll odp=0;
FOR(m, 1, (1<<k)-1) {
FOR(v, 1, n) {
int gr = A[v];
if(m&(1<<gr)==0) continue;
if(__builtin_popcount(m)>=2) odp+=dp[v][m];
for(int u : con[v]) {
int sgr = A[u];
if(m&(1<<sgr)!=0) continue;
dp[u][m^(1<<sgr)]+=dp[v][m];
}
}
}
cout << odp << '\n';
}
Compilation message
paths.cpp: In function 'int main()':
paths.cpp:35:19: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
35 | if(m&(1<<gr)==0) continue;
| ~~~~~~~^~~
paths.cpp:39:22: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
39 | if(m&(1<<sgr)!=0) continue;
| ~~~~~~~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
52 ms |
6480 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
16 ms |
1680 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |