#include<bits/stdc++.h>
using namespace std;
int color[(int)3e5+5],k4[(int)3e5+5][10],k5[(int)1e5+5][35];
vector<int>cnt[(int)3e5+5];
pair<int,int>e[(int)3e5+5];
int main(){
cin.tie(0)->sync_with_stdio(0);
int n,m,k;
cin>>n>>m>>k;
for(int i=1;i<=n;i++)cin>>color[i];
for(int i=0;i<m;i++){
cin>>e[i].first>>e[i].second;
cnt[e[i].first].push_back(e[i].second),cnt[e[i].second].push_back(e[i].first);
if(k>=5)k5[e[i].first][color[e[i].first]*5+color[e[i].second]]++,k5[e[i].second][color[e[i].second]*5+color[e[i].first]]++;
}
long long int ans=0;
if(k>=2){
for(int i=0;i<m;i++)if(color[e[i].first]!=color[e[i].second])ans+=2;
}
if(k>=3){
for(int i=1;i<=n;i++){
int c[10];
for(int j=1;j<=k;j++)c[j]=0;
for(int j:cnt[i])c[color[j]]++;
for(int x=1;x<=k;x++)for(int y=1;y<=k;y++){
if(x==y||x==color[i]||y==color[i])continue;
ans+=1ll*c[x]*c[y];
}
}
}
if(k>=4){
for(int i=1;i<=n;i++){
for(int j=1;j<=k;j++)k4[i][j]=0;
}
for(int i=1;i<=n;i++){
for(int j:cnt[i])k4[i][color[j]]++;
}
for(int i=0;i<m;i++){
if(color[e[i].first]==color[e[i].second])continue;
for(int x=1;x<=k;x++)for(int y=1;y<=k;y++){
if(x==y||x==color[e[i].first]||x==color[e[i].second]||y==color[e[i].first]||y==color[e[i].second])continue;
ans+=2ll*k4[e[i].first][x]*k4[e[i].second][y];
}
}
}
if(k>=5){
for(int i=1;i<=n;i++){
int c[35];
for(int j=6;j<=30;j++)c[j]=0;
for(int j:cnt[i]){
for(int x=6;x<=30;x++)c[x]+=k5[j][x];
}
for(int x=1;x<=k;x++)for(int y=1;y<=k;y++)for(int u=1;u<=k;u++)for(int v=1;v<=k;v++){
if(color[i]==x||color[i]==y||color[i]==u||color[i]==v
||x==y||x==u||x==v||y==u||y==v||u==v)continue;
ans+=1ll*c[x*5+y]*c[u*5+v];
}
}
}
cout<<ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
12636 KB |
Output is correct |
2 |
Correct |
2 ms |
12636 KB |
Output is correct |
3 |
Correct |
2 ms |
10588 KB |
Output is correct |
4 |
Correct |
3 ms |
10932 KB |
Output is correct |
5 |
Correct |
4 ms |
10588 KB |
Output is correct |
6 |
Correct |
3 ms |
12636 KB |
Output is correct |
7 |
Correct |
2 ms |
12636 KB |
Output is correct |
8 |
Correct |
2 ms |
12636 KB |
Output is correct |
9 |
Correct |
2 ms |
12636 KB |
Output is correct |
10 |
Correct |
2 ms |
10588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
19280 KB |
Output is correct |
2 |
Correct |
38 ms |
18724 KB |
Output is correct |
3 |
Correct |
166 ms |
26680 KB |
Output is correct |
4 |
Correct |
63 ms |
20560 KB |
Output is correct |
5 |
Correct |
59 ms |
20564 KB |
Output is correct |
6 |
Correct |
86 ms |
24608 KB |
Output is correct |
7 |
Correct |
117 ms |
26628 KB |
Output is correct |
8 |
Correct |
138 ms |
27368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
12636 KB |
Output is correct |
2 |
Correct |
2 ms |
12636 KB |
Output is correct |
3 |
Correct |
2 ms |
10588 KB |
Output is correct |
4 |
Correct |
3 ms |
10932 KB |
Output is correct |
5 |
Correct |
4 ms |
10588 KB |
Output is correct |
6 |
Correct |
3 ms |
12636 KB |
Output is correct |
7 |
Correct |
2 ms |
12636 KB |
Output is correct |
8 |
Correct |
2 ms |
12636 KB |
Output is correct |
9 |
Correct |
2 ms |
12636 KB |
Output is correct |
10 |
Correct |
2 ms |
10588 KB |
Output is correct |
11 |
Correct |
47 ms |
19280 KB |
Output is correct |
12 |
Correct |
38 ms |
18724 KB |
Output is correct |
13 |
Correct |
166 ms |
26680 KB |
Output is correct |
14 |
Correct |
63 ms |
20560 KB |
Output is correct |
15 |
Correct |
59 ms |
20564 KB |
Output is correct |
16 |
Correct |
86 ms |
24608 KB |
Output is correct |
17 |
Correct |
117 ms |
26628 KB |
Output is correct |
18 |
Correct |
138 ms |
27368 KB |
Output is correct |
19 |
Correct |
47 ms |
19268 KB |
Output is correct |
20 |
Correct |
37 ms |
18680 KB |
Output is correct |
21 |
Correct |
149 ms |
26584 KB |
Output is correct |
22 |
Correct |
63 ms |
20560 KB |
Output is correct |
23 |
Correct |
59 ms |
20680 KB |
Output is correct |
24 |
Correct |
105 ms |
24628 KB |
Output is correct |
25 |
Correct |
149 ms |
26596 KB |
Output is correct |
26 |
Correct |
117 ms |
27264 KB |
Output is correct |
27 |
Correct |
46 ms |
20832 KB |
Output is correct |
28 |
Correct |
63 ms |
22160 KB |
Output is correct |
29 |
Correct |
159 ms |
36948 KB |
Output is correct |
30 |
Correct |
102 ms |
31252 KB |
Output is correct |
31 |
Correct |
113 ms |
31372 KB |
Output is correct |
32 |
Correct |
169 ms |
36944 KB |
Output is correct |
33 |
Correct |
5 ms |
12632 KB |
Output is correct |
34 |
Correct |
2 ms |
12636 KB |
Output is correct |
35 |
Correct |
2 ms |
10732 KB |
Output is correct |
36 |
Correct |
2 ms |
10588 KB |
Output is correct |
37 |
Correct |
2 ms |
10588 KB |
Output is correct |
38 |
Correct |
2 ms |
12636 KB |
Output is correct |
39 |
Correct |
3 ms |
12636 KB |
Output is correct |
40 |
Correct |
3 ms |
12728 KB |
Output is correct |
41 |
Correct |
3 ms |
12636 KB |
Output is correct |
42 |
Correct |
2 ms |
10584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
12632 KB |
Output is correct |
2 |
Correct |
23 ms |
16732 KB |
Output is correct |
3 |
Correct |
13 ms |
14680 KB |
Output is correct |
4 |
Correct |
32 ms |
17244 KB |
Output is correct |
5 |
Correct |
28 ms |
17864 KB |
Output is correct |
6 |
Correct |
237 ms |
35924 KB |
Output is correct |
7 |
Correct |
17 ms |
16732 KB |
Output is correct |
8 |
Correct |
39 ms |
23376 KB |
Output is correct |
9 |
Correct |
36 ms |
24020 KB |
Output is correct |
10 |
Correct |
38 ms |
23756 KB |
Output is correct |
11 |
Correct |
124 ms |
26120 KB |
Output is correct |
12 |
Correct |
157 ms |
31420 KB |
Output is correct |
13 |
Correct |
118 ms |
26188 KB |
Output is correct |
14 |
Correct |
232 ms |
35700 KB |
Output is correct |
15 |
Correct |
227 ms |
35664 KB |
Output is correct |
16 |
Correct |
3 ms |
12636 KB |
Output is correct |
17 |
Correct |
3 ms |
12636 KB |
Output is correct |
18 |
Correct |
2 ms |
10588 KB |
Output is correct |
19 |
Correct |
3 ms |
10588 KB |
Output is correct |
20 |
Correct |
2 ms |
10584 KB |
Output is correct |
21 |
Correct |
3 ms |
12636 KB |
Output is correct |
22 |
Correct |
2 ms |
12636 KB |
Output is correct |
23 |
Correct |
3 ms |
12776 KB |
Output is correct |
24 |
Correct |
2 ms |
12636 KB |
Output is correct |
25 |
Correct |
2 ms |
10720 KB |
Output is correct |