#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
int n, m, k, c[300005];
ll dp[300005][5][5][5];
vector<vector<int>> g;
ll solve() {
ll ans = 0;
if (k < 2) return ans;
for (int u = 0; u < n; u++) {
for (int v : g[u]) {
dp[u][c[v]][0][0]++;
}
for (int x = 1; x <= k; x++) {
if (x == c[u]) continue;
ans += dp[u][x][0][0];
}
}
if (k < 3) return ans;
for (int u = 0; u < n; u++) {
for (int v : g[u]) {
for (int x = 1; x <= k; x++) {
dp[u][c[v]][x][0] += dp[v][x][0][0];
}
}
for (int x = 1; x <= k; x++) {
if (x == c[u]) continue;
for (int y = 1; y <= k; y++) {
if (y == c[u] or y == x) continue;
ans += dp[u][x][y][0];
}
}
}
if (k < 4) return ans;
for (int u = 0; u < n; u++) {
for (int v : g[u]) {
for (int x = 1; x <= k; x++) {
for (int y = 1; y <= k; y++) {
dp[u][c[v]][x][y] += dp[v][x][y][0];
}
}
}
for (int x = 1; x <= k; x++) {
if (x == c[u]) continue;
for (int y = 1; y <= k; y++) {
if (y == c[u] or y == x) continue;
for (int z = 1; z <= k; z++) {
if (z == c[u] or z == x or z == y) continue;
ans += dp[u][x][y][z];
}
}
}
}
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m >> k;
g.resize(n);
for (int i = 0; i < n; i++) {
cin >> c[i];
}
while (m--) {
int u, v;
cin >> u >> v;
u--, v--;
g[u].push_back(v);
g[v].push_back(u);
}
cout << solve() << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 ms |
8908 KB |
Output is correct |
2 |
Correct |
50 ms |
4708 KB |
Output is correct |
3 |
Correct |
378 ms |
310484 KB |
Output is correct |
4 |
Correct |
93 ms |
34892 KB |
Output is correct |
5 |
Correct |
82 ms |
5584 KB |
Output is correct |
6 |
Correct |
245 ms |
208704 KB |
Output is correct |
7 |
Correct |
370 ms |
310352 KB |
Output is correct |
8 |
Correct |
378 ms |
310992 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
63 ms |
8908 KB |
Output is correct |
12 |
Correct |
50 ms |
4708 KB |
Output is correct |
13 |
Correct |
378 ms |
310484 KB |
Output is correct |
14 |
Correct |
93 ms |
34892 KB |
Output is correct |
15 |
Correct |
82 ms |
5584 KB |
Output is correct |
16 |
Correct |
245 ms |
208704 KB |
Output is correct |
17 |
Correct |
370 ms |
310352 KB |
Output is correct |
18 |
Correct |
378 ms |
310992 KB |
Output is correct |
19 |
Correct |
66 ms |
11728 KB |
Output is correct |
20 |
Correct |
52 ms |
6900 KB |
Output is correct |
21 |
Correct |
376 ms |
314888 KB |
Output is correct |
22 |
Correct |
94 ms |
38184 KB |
Output is correct |
23 |
Correct |
89 ms |
8860 KB |
Output is correct |
24 |
Correct |
253 ms |
212580 KB |
Output is correct |
25 |
Correct |
381 ms |
314940 KB |
Output is correct |
26 |
Correct |
383 ms |
315588 KB |
Output is correct |
27 |
Correct |
63 ms |
6992 KB |
Output is correct |
28 |
Correct |
100 ms |
15740 KB |
Output is correct |
29 |
Correct |
539 ms |
314876 KB |
Output is correct |
30 |
Correct |
334 ms |
161000 KB |
Output is correct |
31 |
Correct |
334 ms |
161092 KB |
Output is correct |
32 |
Correct |
532 ms |
314868 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
41 |
Correct |
1 ms |
332 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |