#include <bits/stdc++.h>
using namespace std;
const int N = 100100;
int n, m, k;
vector<int> g[N];
int color[N];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m >> k;
for (int i = 1; i <= n; i++) {
cin >> color[i];
color[i]--;
}
for (int i = 1; i <= m; i++) {
int u, v;
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
vector<int> ord((1 << k) - 1);
iota(ord.begin(), ord.end(), 1);
sort(ord.begin(), ord.end(), [&](int a, int b) {
return __builtin_popcount(a) <= __builtin_popcount(b);
});
vector<vector<long long>> dp(n + 1, vector<long long>(1 << k));
for (int i = 1; i <= n; i++) {
dp[i][(1 << color[i])] = 1;
}
for (int msk : ord) {
for (int v = 1; v <= n; v++) {
for (int to : g[v]) {
if (msk >> color[to] & 1) continue;
dp[to][msk | (1 << color[to])] += dp[v][msk];
}
}
}
long long ans = 0;
for (int i = 1; i <= n; i++) {
for (int msk = 1; msk < (1 << k); msk++) {
if (__builtin_popcount(msk) < 2) continue;
ans += dp[i][msk];
}
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2904 KB |
Output is correct |
2 |
Correct |
1 ms |
2908 KB |
Output is correct |
3 |
Correct |
1 ms |
2908 KB |
Output is correct |
4 |
Correct |
1 ms |
2908 KB |
Output is correct |
5 |
Correct |
1 ms |
2908 KB |
Output is correct |
6 |
Correct |
1 ms |
2908 KB |
Output is correct |
7 |
Correct |
1 ms |
2908 KB |
Output is correct |
8 |
Correct |
1 ms |
2904 KB |
Output is correct |
9 |
Correct |
1 ms |
2908 KB |
Output is correct |
10 |
Correct |
1 ms |
2908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
58 ms |
9556 KB |
Output is correct |
2 |
Correct |
37 ms |
8784 KB |
Output is correct |
3 |
Runtime error |
10 ms |
6748 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2904 KB |
Output is correct |
2 |
Correct |
1 ms |
2908 KB |
Output is correct |
3 |
Correct |
1 ms |
2908 KB |
Output is correct |
4 |
Correct |
1 ms |
2908 KB |
Output is correct |
5 |
Correct |
1 ms |
2908 KB |
Output is correct |
6 |
Correct |
1 ms |
2908 KB |
Output is correct |
7 |
Correct |
1 ms |
2908 KB |
Output is correct |
8 |
Correct |
1 ms |
2904 KB |
Output is correct |
9 |
Correct |
1 ms |
2908 KB |
Output is correct |
10 |
Correct |
1 ms |
2908 KB |
Output is correct |
11 |
Correct |
58 ms |
9556 KB |
Output is correct |
12 |
Correct |
37 ms |
8784 KB |
Output is correct |
13 |
Runtime error |
10 ms |
6748 KB |
Execution killed with signal 11 |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2904 KB |
Output is correct |
2 |
Correct |
31 ms |
4700 KB |
Output is correct |
3 |
Correct |
14 ms |
4700 KB |
Output is correct |
4 |
Correct |
43 ms |
17492 KB |
Output is correct |
5 |
Correct |
32 ms |
18236 KB |
Output is correct |
6 |
Correct |
124 ms |
36176 KB |
Output is correct |
7 |
Correct |
19 ms |
4696 KB |
Output is correct |
8 |
Correct |
79 ms |
23580 KB |
Output is correct |
9 |
Correct |
52 ms |
24280 KB |
Output is correct |
10 |
Correct |
53 ms |
24232 KB |
Output is correct |
11 |
Correct |
65 ms |
20432 KB |
Output is correct |
12 |
Correct |
69 ms |
28744 KB |
Output is correct |
13 |
Correct |
79 ms |
20560 KB |
Output is correct |
14 |
Correct |
127 ms |
36292 KB |
Output is correct |
15 |
Correct |
124 ms |
36380 KB |
Output is correct |
16 |
Correct |
1 ms |
2904 KB |
Output is correct |
17 |
Correct |
1 ms |
2908 KB |
Output is correct |
18 |
Correct |
1 ms |
2908 KB |
Output is correct |
19 |
Correct |
1 ms |
2908 KB |
Output is correct |
20 |
Correct |
1 ms |
2908 KB |
Output is correct |
21 |
Correct |
1 ms |
2908 KB |
Output is correct |
22 |
Correct |
1 ms |
2908 KB |
Output is correct |
23 |
Correct |
1 ms |
2908 KB |
Output is correct |
24 |
Correct |
1 ms |
2908 KB |
Output is correct |
25 |
Correct |
1 ms |
3164 KB |
Output is correct |