//Dedicated to my love, ivaziva
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define int long long
using pii = pair<int, int>;
using ll = int64_t;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define dbg(x) cerr<<#x<<": "<<x<<'\n';
#define dbga(A,l_,r_){for(int i_=l_;i_<=r_;i_++)cerr<<A[i_]<<' ';cerr<<'\n';}
#define dbgv(a_){for(auto x_:a_) cerr<<x_<<' ';cerr<<'\n';}
const int N = 3e5 + 20;
int n, m, k, a[N], ans;
vector<int> g[N];
int32_t main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cout.tie(nullptr); cerr.tie(nullptr);
cin >> n >> m >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
ans = 0;
if (k >= 2) {
for (int i = 1; i <= n; i++) {
for (int u : g[i]) {
if (a[u] != a[i]) {
ans++;
}
}
}
}
if (k >= 3) {
for (int i = 1; i <= n; i++) {
vector<int> cnt(k + 1, 0);
for (int u : g[i]) {
cnt[a[u]]++;
}
for (int x = 1; x <= k; x++) {
for (int y = 1; y <= k; y++) {
if (x != y && x != a[i] && y != a[i]) {
ans += cnt[x] * cnt[y];
}
}
}
}
}
dbg(ans);
if (k >= 4) {
vector<vector<int>> cnt(n + 1, vector<int>(k + 1, 0));
for (int i = 1; i <= n; i++) {
for (int u : g[i]) {
cnt[i][a[u]]++;
}
}
for (int i = 1; i <= n; i++) {
for (int u : g[i]) {
int uk = 0;
for (int x = 1; x <= k; x++) {
for (int y = 1; y <= k; y++) {
if (x != y && a[i] != a[u] && x != a[i] && x != a[u] && y != a[i] && y != a[u]) {
ans += cnt[i][x] * cnt[u][y];
}
}
}
}
}
}
dbg(ans);
if (k >= 5) {
vector<vector<int>> cnt(n + 1, vector<int>(k + 1, 0));
int f[n + 1][k + 1][k + 1];
for (int x = 1; x <= n; x++) {
for (int y = 1; y <= k; y++) {
for (int z = 1; z <= k; z++) {
f[x][y][z] = 0;
}
}
}
for (int i = 1; i <= n; i++) {
for (int u : g[i]) {
cnt[i][a[u]]++;
}
}
for (int i = 1; i <= n; i++) {
for (int u : g[i]) {
for (int j = 1; j <= k; j++) {
f[i][a[u]][j] += cnt[u][j];
}
}
}
for (int i = 1; i <= n; i++) {
for (int p = 1; p <= k; p++) {
for (int q = 1; q <= k; q++) {
for (int r = 1; r <= k; r++) {
for (int s = 1; s <= k; s++) {
if (p != q && p != r && p != s && q != r && q != s && r != s && a[i] != p && a[i] != q && a[i] != r && a[i] != s) {
ans += f[i][p][q] * f[i][r][s];
ans += f[i][p][r] * f[i][q][s];
ans += f[i][p][s] * f[i][q][r];
}
}
}
}
}
}
}
cout << ans << '\n';
return 0;
}
Compilation message
paths.cpp: In function 'int32_t main()':
paths.cpp:69:21: warning: unused variable 'uk' [-Wunused-variable]
69 | int uk = 0;
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7516 KB |
Output is correct |
2 |
Correct |
4 ms |
7516 KB |
Output is correct |
3 |
Correct |
4 ms |
7516 KB |
Output is correct |
4 |
Correct |
4 ms |
7516 KB |
Output is correct |
5 |
Correct |
4 ms |
7516 KB |
Output is correct |
6 |
Correct |
4 ms |
7516 KB |
Output is correct |
7 |
Correct |
4 ms |
7516 KB |
Output is correct |
8 |
Correct |
4 ms |
7516 KB |
Output is correct |
9 |
Correct |
4 ms |
7516 KB |
Output is correct |
10 |
Correct |
4 ms |
7516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
17492 KB |
Output is correct |
2 |
Correct |
36 ms |
16732 KB |
Output is correct |
3 |
Correct |
123 ms |
24656 KB |
Output is correct |
4 |
Correct |
58 ms |
19024 KB |
Output is correct |
5 |
Correct |
56 ms |
19024 KB |
Output is correct |
6 |
Correct |
86 ms |
21952 KB |
Output is correct |
7 |
Correct |
117 ms |
24652 KB |
Output is correct |
8 |
Correct |
117 ms |
25172 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7516 KB |
Output is correct |
2 |
Correct |
4 ms |
7516 KB |
Output is correct |
3 |
Correct |
4 ms |
7516 KB |
Output is correct |
4 |
Correct |
4 ms |
7516 KB |
Output is correct |
5 |
Correct |
4 ms |
7516 KB |
Output is correct |
6 |
Correct |
4 ms |
7516 KB |
Output is correct |
7 |
Correct |
4 ms |
7516 KB |
Output is correct |
8 |
Correct |
4 ms |
7516 KB |
Output is correct |
9 |
Correct |
4 ms |
7516 KB |
Output is correct |
10 |
Correct |
4 ms |
7516 KB |
Output is correct |
11 |
Correct |
44 ms |
17492 KB |
Output is correct |
12 |
Correct |
36 ms |
16732 KB |
Output is correct |
13 |
Correct |
123 ms |
24656 KB |
Output is correct |
14 |
Correct |
58 ms |
19024 KB |
Output is correct |
15 |
Correct |
56 ms |
19024 KB |
Output is correct |
16 |
Correct |
86 ms |
21952 KB |
Output is correct |
17 |
Correct |
117 ms |
24652 KB |
Output is correct |
18 |
Correct |
117 ms |
25172 KB |
Output is correct |
19 |
Correct |
44 ms |
17500 KB |
Output is correct |
20 |
Correct |
36 ms |
16732 KB |
Output is correct |
21 |
Correct |
123 ms |
24764 KB |
Output is correct |
22 |
Correct |
64 ms |
19024 KB |
Output is correct |
23 |
Correct |
59 ms |
19184 KB |
Output is correct |
24 |
Correct |
92 ms |
21836 KB |
Output is correct |
25 |
Correct |
130 ms |
24916 KB |
Output is correct |
26 |
Correct |
122 ms |
25168 KB |
Output is correct |
27 |
Correct |
55 ms |
16732 KB |
Output is correct |
28 |
Correct |
69 ms |
19028 KB |
Output is correct |
29 |
Correct |
244 ms |
45904 KB |
Output is correct |
30 |
Correct |
141 ms |
31932 KB |
Output is correct |
31 |
Correct |
142 ms |
31940 KB |
Output is correct |
32 |
Correct |
231 ms |
45976 KB |
Output is correct |
33 |
Correct |
4 ms |
7512 KB |
Output is correct |
34 |
Correct |
4 ms |
7516 KB |
Output is correct |
35 |
Correct |
4 ms |
7512 KB |
Output is correct |
36 |
Correct |
4 ms |
7512 KB |
Output is correct |
37 |
Correct |
4 ms |
7516 KB |
Output is correct |
38 |
Correct |
4 ms |
7516 KB |
Output is correct |
39 |
Correct |
4 ms |
7516 KB |
Output is correct |
40 |
Correct |
4 ms |
7516 KB |
Output is correct |
41 |
Correct |
4 ms |
7260 KB |
Output is correct |
42 |
Correct |
3 ms |
7512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7260 KB |
Output is correct |
2 |
Incorrect |
24 ms |
10448 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |