#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
int n, m, k, c[300005];
ll dp[100005][6][6][6][6];
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][0]++;
}
for (int c1 = 1; c1 <= k; c1++) {
if (c1 == c[u]) continue;
ans += dp[u][c1][0][0][0];
}
}
if (k < 3) return ans;
for (int u = 0; u < n; u++) {
for (int v : g[u]) {
for (int c1 = 1; c1 <= k; c1++) {
dp[u][c[v]][c1][0][0] += dp[v][c1][0][0][0];
}
}
for (int c1 = 1; c1 <= k; c1++) {
if (c1 == c[u]) continue;
for (int c2 = 1; c2 <= k; c2++) {
if (c2 == c[u] or c2 == c1) continue;
ans += dp[u][c1][c2][0][0];
}
}
}
if (k < 4) return ans;
for (int u = 0; u < n; u++) {
for (int v : g[u]) {
for (int c1 = 1; c1 <= k; c1++) {
for (int c2 = 1; c2 <= k; c2++) {
dp[u][c[v]][c1][c2][0] += dp[v][c1][c2][0][0];
}
}
}
for (int c1 = 1; c1 <= k; c1++) {
if (c1 == c[u]) continue;
for (int c2 = 1; c2 <= k; c2++) {
if (c2 == c[u] or c2 == c1) continue;
for (int c3 = 1; c3 <= k; c3++) {
if (c3 == c[u] or c3 == c1 or c3 == c2) continue;
ans += dp[u][c1][c2][c3][0];
}
}
}
}
if (k < 5) return ans;
for (int u = 0; u < n; u++) {
for (int v : g[u]) {
for (int c1 = 1; c1 <= k; c1++) {
for (int c2 = 1; c2 <= k; c2++) {
for (int c3 = 1; c3 <= k; c3++) {
dp[u][c[v]][c1][c2][c3] += dp[v][c1][c2][c3][0];
}
}
}
}
for (int c1 = 1; c1 <= k; c1++) {
if (c1 == c[u]) continue;
for (int c2 = 1; c2 <= k; c2++) {
if (c2 == c[u] or c2 == c1) continue;
for (int c3 = 1; c3 <= k; c3++) {
if (c3 == c[u] or c3 == c1 or c3 == c2) continue;
for (int c4 = 1; c4 <= k; c4++) {
if (c4 == c[u] or c4 == c1 or c4 == c2 or c4 == c3) continue;
ans += dp[u][c1][c2][c3][c4];
}
}
}
}
}
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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
852 KB |
Output is correct |
3 |
Correct |
0 ms |
596 KB |
Output is correct |
4 |
Correct |
0 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
852 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
1 ms |
980 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
82 ms |
45392 KB |
Output is correct |
2 |
Correct |
52 ms |
10448 KB |
Output is correct |
3 |
Runtime error |
791 ms |
728676 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
852 KB |
Output is correct |
3 |
Correct |
0 ms |
596 KB |
Output is correct |
4 |
Correct |
0 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
852 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
1 ms |
980 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
82 ms |
45392 KB |
Output is correct |
12 |
Correct |
52 ms |
10448 KB |
Output is correct |
13 |
Runtime error |
791 ms |
728676 KB |
Execution killed with signal 11 |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
62 ms |
6328 KB |
Output is correct |
3 |
Correct |
20 ms |
6172 KB |
Output is correct |
4 |
Correct |
278 ms |
550852 KB |
Output is correct |
5 |
Correct |
246 ms |
497568 KB |
Output is correct |
6 |
Correct |
656 ms |
680720 KB |
Output is correct |
7 |
Correct |
23 ms |
6988 KB |
Output is correct |
8 |
Correct |
394 ms |
634652 KB |
Output is correct |
9 |
Correct |
357 ms |
547440 KB |
Output is correct |
10 |
Correct |
398 ms |
704424 KB |
Output is correct |
11 |
Correct |
407 ms |
412316 KB |
Output is correct |
12 |
Correct |
460 ms |
523444 KB |
Output is correct |
13 |
Correct |
406 ms |
425236 KB |
Output is correct |
14 |
Correct |
662 ms |
681412 KB |
Output is correct |
15 |
Correct |
713 ms |
717972 KB |
Output is correct |
16 |
Correct |
1 ms |
596 KB |
Output is correct |
17 |
Correct |
1 ms |
840 KB |
Output is correct |
18 |
Correct |
1 ms |
596 KB |
Output is correct |
19 |
Correct |
1 ms |
596 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
852 KB |
Output is correct |
22 |
Correct |
1 ms |
716 KB |
Output is correct |
23 |
Correct |
1 ms |
980 KB |
Output is correct |
24 |
Correct |
0 ms |
340 KB |
Output is correct |
25 |
Correct |
0 ms |
340 KB |
Output is correct |