#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];
}
}
}
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 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
68 ms |
8912 KB |
Output is correct |
2 |
Correct |
56 ms |
6892 KB |
Output is correct |
3 |
Correct |
409 ms |
315048 KB |
Output is correct |
4 |
Correct |
93 ms |
38284 KB |
Output is correct |
5 |
Correct |
79 ms |
8964 KB |
Output is correct |
6 |
Correct |
260 ms |
212672 KB |
Output is correct |
7 |
Correct |
375 ms |
314800 KB |
Output is correct |
8 |
Correct |
391 ms |
315660 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |