#include<bits/stdc++.h>
using namespace std;
const int N = (int)3e5+3;
const int MOD = (int)1e6+3;
const int B1 = 450;
const int B2 = 450;
int n, m, k, a[N], kol[6];
vector<int> g[N];
bool used[6];
long long ans;
void dfs(int v) {
used[a[v]] = 1;
ans++;
for(auto to : g[v]) {
if(!used[a[to]]) {
dfs(to);
}
}
used[a[v]] = 0;
}
int cnt[N][32];
int bb[N][6];
int oo[6][32];
int cc[6][6];
int main() {
ios_base::sync_with_stdio(NULL);
cin.tie(0);
cin >> n >> m >> k;
for(int i = 1; i <= n; ++i) {
cin >> a[i];
a[i]--;
}
for(int i = 1; i <= m; ++i) {
int u, v;
cin >> u >> v;
if(a[u] == a[v]) {
continue;
}
ans += 2;
bb[u][a[v]]++;
bb[v][a[u]]++;
g[u].push_back(v);
g[v].push_back(u);
}
for(int i = 1; i <= n; ++i) {
int cur = 0;
memset(kol, 0, sizeof(kol));
for(auto x : g[i]) {
ans += 2*(cur-kol[a[x]]);
cur++;
kol[a[x]]++;
}
}
for(int i = 1; i <= n; ++i) {
for(int mask = 0; mask < (1 << k); ++mask) {
for(int j : g[i]) {
if(!(mask >> a[j] & 1)) {
continue;
}
cnt[i][mask]++;
}
}
}
for(int i = 1; i <= n; ++i) {
memset(oo, 0, sizeof(oo));
memset(kol, 0, sizeof(kol));
for(int j : g[i]) {
kol[a[j]]++;
for(int mask = 0; mask < (1 << k); ++mask) {
oo[a[j]][mask] += cnt[j][mask];
}
}
for(int c = 0; c < k; ++c) {
if(c == a[i]) {
continue;
}
for(int d = 0; d < k; ++d) {
if(d == a[i] || d == c) {
continue;
}
int can = (1 << k)-1;
can ^= (1 << a[i]);
can ^= (1 << c);
can ^= (1 << d);
ans += 1ll*oo[c][can]*kol[d];
}
}
}
for(int i = 1; i <= n; ++i) {
memset(oo, 0, sizeof(oo));
memset(kol, 0, sizeof(kol));
memset(cc, 0, sizeof(cc));
for(int j : g[i]) {
kol[a[j]]++;
for(int c = 0; c < k; ++c) {
cc[a[j]][c] += bb[j][c];
}
for(int mask = 0; mask < (1 << k); ++mask) {
oo[a[j]][mask] += cnt[j][mask];
}
}
for(int c = 0; c < k; ++c) {
if(c == a[i]) {
continue;
}
for(int d = 0; d < k; ++d) {
if(d == a[i] || d == c) {
continue;
}
for(int e = 0; e < k; ++e) {
if(e == d || e == c || e == a[i]) {
continue;
}
for(int f = 0; f < k; ++f) {
if(f == e || f == d || f == c || f == a[i]) {
continue;
}
ans += 1ll*cc[c][e]*cc[d][f];
}
}
}
}
}
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10844 KB |
Output is correct |
2 |
Correct |
2 ms |
10844 KB |
Output is correct |
3 |
Correct |
2 ms |
10844 KB |
Output is correct |
4 |
Correct |
2 ms |
10844 KB |
Output is correct |
5 |
Correct |
2 ms |
8796 KB |
Output is correct |
6 |
Correct |
2 ms |
10844 KB |
Output is correct |
7 |
Correct |
2 ms |
10844 KB |
Output is correct |
8 |
Correct |
2 ms |
10844 KB |
Output is correct |
9 |
Correct |
2 ms |
10844 KB |
Output is correct |
10 |
Correct |
2 ms |
10844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
13828 KB |
Output is correct |
2 |
Correct |
48 ms |
12880 KB |
Output is correct |
3 |
Correct |
277 ms |
60220 KB |
Output is correct |
4 |
Correct |
61 ms |
19644 KB |
Output is correct |
5 |
Correct |
39 ms |
8792 KB |
Output is correct |
6 |
Correct |
191 ms |
48460 KB |
Output is correct |
7 |
Correct |
278 ms |
60248 KB |
Output is correct |
8 |
Correct |
290 ms |
61264 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10844 KB |
Output is correct |
2 |
Correct |
2 ms |
10844 KB |
Output is correct |
3 |
Correct |
2 ms |
10844 KB |
Output is correct |
4 |
Correct |
2 ms |
10844 KB |
Output is correct |
5 |
Correct |
2 ms |
8796 KB |
Output is correct |
6 |
Correct |
2 ms |
10844 KB |
Output is correct |
7 |
Correct |
2 ms |
10844 KB |
Output is correct |
8 |
Correct |
2 ms |
10844 KB |
Output is correct |
9 |
Correct |
2 ms |
10844 KB |
Output is correct |
10 |
Correct |
2 ms |
10844 KB |
Output is correct |
11 |
Correct |
59 ms |
13828 KB |
Output is correct |
12 |
Correct |
48 ms |
12880 KB |
Output is correct |
13 |
Correct |
277 ms |
60220 KB |
Output is correct |
14 |
Correct |
61 ms |
19644 KB |
Output is correct |
15 |
Correct |
39 ms |
8792 KB |
Output is correct |
16 |
Correct |
191 ms |
48460 KB |
Output is correct |
17 |
Correct |
278 ms |
60248 KB |
Output is correct |
18 |
Correct |
290 ms |
61264 KB |
Output is correct |
19 |
Correct |
58 ms |
13652 KB |
Output is correct |
20 |
Correct |
50 ms |
12892 KB |
Output is correct |
21 |
Correct |
290 ms |
60140 KB |
Output is correct |
22 |
Correct |
65 ms |
19540 KB |
Output is correct |
23 |
Correct |
40 ms |
8796 KB |
Output is correct |
24 |
Correct |
184 ms |
48204 KB |
Output is correct |
25 |
Correct |
280 ms |
60240 KB |
Output is correct |
26 |
Correct |
301 ms |
61276 KB |
Output is correct |
27 |
Correct |
74 ms |
14516 KB |
Output is correct |
28 |
Correct |
83 ms |
15748 KB |
Output is correct |
29 |
Correct |
359 ms |
60752 KB |
Output is correct |
30 |
Correct |
210 ms |
39116 KB |
Output is correct |
31 |
Correct |
238 ms |
39516 KB |
Output is correct |
32 |
Correct |
355 ms |
60756 KB |
Output is correct |
33 |
Correct |
2 ms |
11096 KB |
Output is correct |
34 |
Correct |
2 ms |
10844 KB |
Output is correct |
35 |
Correct |
2 ms |
10840 KB |
Output is correct |
36 |
Correct |
2 ms |
10840 KB |
Output is correct |
37 |
Correct |
2 ms |
8796 KB |
Output is correct |
38 |
Correct |
2 ms |
10844 KB |
Output is correct |
39 |
Correct |
2 ms |
10844 KB |
Output is correct |
40 |
Correct |
2 ms |
10844 KB |
Output is correct |
41 |
Correct |
2 ms |
10844 KB |
Output is correct |
42 |
Correct |
2 ms |
10844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10844 KB |
Output is correct |
2 |
Correct |
40 ms |
11868 KB |
Output is correct |
3 |
Correct |
18 ms |
11868 KB |
Output is correct |
4 |
Correct |
67 ms |
30160 KB |
Output is correct |
5 |
Correct |
50 ms |
30164 KB |
Output is correct |
6 |
Correct |
125 ms |
30404 KB |
Output is correct |
7 |
Correct |
25 ms |
11868 KB |
Output is correct |
8 |
Correct |
82 ms |
30324 KB |
Output is correct |
9 |
Correct |
81 ms |
30412 KB |
Output is correct |
10 |
Correct |
88 ms |
31028 KB |
Output is correct |
11 |
Correct |
72 ms |
20940 KB |
Output is correct |
12 |
Correct |
100 ms |
24372 KB |
Output is correct |
13 |
Correct |
71 ms |
21132 KB |
Output is correct |
14 |
Correct |
137 ms |
30288 KB |
Output is correct |
15 |
Correct |
123 ms |
30308 KB |
Output is correct |
16 |
Correct |
2 ms |
10844 KB |
Output is correct |
17 |
Correct |
2 ms |
10844 KB |
Output is correct |
18 |
Correct |
2 ms |
10844 KB |
Output is correct |
19 |
Correct |
2 ms |
10844 KB |
Output is correct |
20 |
Correct |
2 ms |
8796 KB |
Output is correct |
21 |
Correct |
2 ms |
10844 KB |
Output is correct |
22 |
Correct |
2 ms |
11096 KB |
Output is correct |
23 |
Correct |
2 ms |
10844 KB |
Output is correct |
24 |
Correct |
2 ms |
10844 KB |
Output is correct |
25 |
Correct |
2 ms |
10844 KB |
Output is correct |