#include <bits/stdc++.h>
#define int long long
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
const int N=3e5+5;
int cl[N],cnt[N][6];
vector <int> g[N][6];
signed main(){
ios_base::sync_with_stdio();
cin.tie(0);cout.tie(0);
int n,m,k;
cin>>n>>m>>k;
for(int i=1;i<=n;i++)cin>>cl[i];
while(m--){
int u,v;
cin>>u>>v;
g[u][cl[v]].pb(v);
g[v][cl[u]].pb(u);
}
int ans=0;
if(k>=2){
for(int i=1;i<=n;i++){
for(int a=1;a<=k;a++){
if(cl[i]!=a)ans+=g[i][a].size();
}
}
}
if(k>=3){
for(int i=1;i<=n;i++){
for(int a=1;a<=k;a++){
for(int b=1;b<=k;b++){
if(a!=b && a!=cl[i] && b!=cl[i])ans+=g[i][a].size()*g[i][b].size();
}
}
}
}
if(k>=4){
for(int i=1;i<=n;i++){
for(int b=1;b<=k;b++){
for(int c=1;c<=k;c++){
for(int a=1;a<=k;a++){
if(a!=b && a!=cl[i] && b!=cl[i] && c!=b && c!=a && c!=cl[i]){
for(auto to : g[i][b])ans+=g[i][a].size()*g[to][c].size();
}
}
}
}
}
}
if(k==5){
for(int i=1;i<=n;i++){
for(int b=1;b<=k;b++){
for(int c=1;c<=k;c++){
for(int a=1;a<=k;a++){
if(a!=b && a!=cl[i] && b!=cl[i] && c!=b && c!=a && c!=cl[i]){
int x=0,y=0;
int d=15-(cl[i]+a+b+c);
for(auto to : g[i][b])x+=g[to][d].size();
for(auto to : g[i][a])y+=g[to][c].size();
ans+=x*y;
}
}
}
}
}
}
cout<<ans<<"\n";
}
/*
4 3 3
1 2 1 3
1 2
2 3
4 2
9 11 4
1 2 3 4 1 2 1 2 2
1 2
1 3
2 3
2 4
3 6
6 2
6 5
4 3
4 5
7 8
9 8
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
45660 KB |
Output is correct |
2 |
Correct |
10 ms |
45668 KB |
Output is correct |
3 |
Correct |
12 ms |
45660 KB |
Output is correct |
4 |
Correct |
10 ms |
45660 KB |
Output is correct |
5 |
Correct |
10 ms |
45728 KB |
Output is correct |
6 |
Correct |
11 ms |
45656 KB |
Output is correct |
7 |
Correct |
10 ms |
45660 KB |
Output is correct |
8 |
Correct |
10 ms |
45656 KB |
Output is correct |
9 |
Correct |
11 ms |
45660 KB |
Output is correct |
10 |
Correct |
11 ms |
45748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
125 ms |
53832 KB |
Output is correct |
2 |
Correct |
97 ms |
52560 KB |
Output is correct |
3 |
Correct |
306 ms |
60968 KB |
Output is correct |
4 |
Correct |
161 ms |
54024 KB |
Output is correct |
5 |
Correct |
158 ms |
53676 KB |
Output is correct |
6 |
Correct |
239 ms |
57752 KB |
Output is correct |
7 |
Correct |
294 ms |
60976 KB |
Output is correct |
8 |
Correct |
295 ms |
61876 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
45660 KB |
Output is correct |
2 |
Correct |
10 ms |
45668 KB |
Output is correct |
3 |
Correct |
12 ms |
45660 KB |
Output is correct |
4 |
Correct |
10 ms |
45660 KB |
Output is correct |
5 |
Correct |
10 ms |
45728 KB |
Output is correct |
6 |
Correct |
11 ms |
45656 KB |
Output is correct |
7 |
Correct |
10 ms |
45660 KB |
Output is correct |
8 |
Correct |
10 ms |
45656 KB |
Output is correct |
9 |
Correct |
11 ms |
45660 KB |
Output is correct |
10 |
Correct |
11 ms |
45748 KB |
Output is correct |
11 |
Correct |
125 ms |
53832 KB |
Output is correct |
12 |
Correct |
97 ms |
52560 KB |
Output is correct |
13 |
Correct |
306 ms |
60968 KB |
Output is correct |
14 |
Correct |
161 ms |
54024 KB |
Output is correct |
15 |
Correct |
158 ms |
53676 KB |
Output is correct |
16 |
Correct |
239 ms |
57752 KB |
Output is correct |
17 |
Correct |
294 ms |
60976 KB |
Output is correct |
18 |
Correct |
295 ms |
61876 KB |
Output is correct |
19 |
Correct |
119 ms |
53672 KB |
Output is correct |
20 |
Correct |
94 ms |
52560 KB |
Output is correct |
21 |
Correct |
314 ms |
60748 KB |
Output is correct |
22 |
Correct |
161 ms |
54096 KB |
Output is correct |
23 |
Correct |
149 ms |
53864 KB |
Output is correct |
24 |
Correct |
233 ms |
57800 KB |
Output is correct |
25 |
Correct |
302 ms |
60756 KB |
Output is correct |
26 |
Correct |
312 ms |
61996 KB |
Output is correct |
27 |
Correct |
94 ms |
52816 KB |
Output is correct |
28 |
Correct |
142 ms |
54096 KB |
Output is correct |
29 |
Correct |
436 ms |
61956 KB |
Output is correct |
30 |
Correct |
316 ms |
57508 KB |
Output is correct |
31 |
Correct |
314 ms |
58448 KB |
Output is correct |
32 |
Correct |
425 ms |
61780 KB |
Output is correct |
33 |
Correct |
10 ms |
45660 KB |
Output is correct |
34 |
Correct |
10 ms |
45656 KB |
Output is correct |
35 |
Correct |
12 ms |
45924 KB |
Output is correct |
36 |
Correct |
11 ms |
45660 KB |
Output is correct |
37 |
Correct |
11 ms |
45660 KB |
Output is correct |
38 |
Correct |
10 ms |
45772 KB |
Output is correct |
39 |
Correct |
10 ms |
45744 KB |
Output is correct |
40 |
Correct |
10 ms |
45660 KB |
Output is correct |
41 |
Correct |
10 ms |
45660 KB |
Output is correct |
42 |
Correct |
10 ms |
45660 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
45660 KB |
Output is correct |
2 |
Correct |
43 ms |
48280 KB |
Output is correct |
3 |
Correct |
38 ms |
49492 KB |
Output is correct |
4 |
Correct |
106 ms |
51844 KB |
Output is correct |
5 |
Correct |
92 ms |
51140 KB |
Output is correct |
6 |
Correct |
202 ms |
52308 KB |
Output is correct |
7 |
Correct |
39 ms |
48468 KB |
Output is correct |
8 |
Correct |
139 ms |
52500 KB |
Output is correct |
9 |
Correct |
97 ms |
51012 KB |
Output is correct |
10 |
Correct |
116 ms |
51876 KB |
Output is correct |
11 |
Correct |
110 ms |
50516 KB |
Output is correct |
12 |
Correct |
133 ms |
50888 KB |
Output is correct |
13 |
Correct |
110 ms |
51156 KB |
Output is correct |
14 |
Correct |
208 ms |
52232 KB |
Output is correct |
15 |
Correct |
200 ms |
52308 KB |
Output is correct |
16 |
Correct |
11 ms |
45916 KB |
Output is correct |
17 |
Correct |
10 ms |
45660 KB |
Output is correct |
18 |
Correct |
10 ms |
45660 KB |
Output is correct |
19 |
Correct |
11 ms |
45760 KB |
Output is correct |
20 |
Correct |
11 ms |
45660 KB |
Output is correct |
21 |
Correct |
11 ms |
45760 KB |
Output is correct |
22 |
Correct |
10 ms |
45660 KB |
Output is correct |
23 |
Correct |
10 ms |
45656 KB |
Output is correct |
24 |
Correct |
10 ms |
45660 KB |
Output is correct |
25 |
Correct |
10 ms |
45660 KB |
Output is correct |