#include<bits/stdc++.h>
using namespace std;
int color[(int)3e5+5],k4[(int)3e5+5][10];
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);
}
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];
}
}
}
cout<<ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8536 KB |
Output is correct |
2 |
Correct |
2 ms |
8540 KB |
Output is correct |
3 |
Correct |
3 ms |
8632 KB |
Output is correct |
4 |
Correct |
3 ms |
8540 KB |
Output is correct |
5 |
Correct |
2 ms |
8540 KB |
Output is correct |
6 |
Correct |
3 ms |
8540 KB |
Output is correct |
7 |
Correct |
2 ms |
8536 KB |
Output is correct |
8 |
Correct |
2 ms |
8536 KB |
Output is correct |
9 |
Correct |
2 ms |
8540 KB |
Output is correct |
10 |
Correct |
2 ms |
8540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
46 ms |
17492 KB |
Output is correct |
2 |
Correct |
38 ms |
16720 KB |
Output is correct |
3 |
Correct |
119 ms |
24660 KB |
Output is correct |
4 |
Correct |
58 ms |
18676 KB |
Output is correct |
5 |
Correct |
66 ms |
18736 KB |
Output is correct |
6 |
Correct |
82 ms |
22744 KB |
Output is correct |
7 |
Correct |
126 ms |
24756 KB |
Output is correct |
8 |
Correct |
117 ms |
25428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8536 KB |
Output is correct |
2 |
Correct |
2 ms |
8540 KB |
Output is correct |
3 |
Correct |
3 ms |
8632 KB |
Output is correct |
4 |
Correct |
3 ms |
8540 KB |
Output is correct |
5 |
Correct |
2 ms |
8540 KB |
Output is correct |
6 |
Correct |
3 ms |
8540 KB |
Output is correct |
7 |
Correct |
2 ms |
8536 KB |
Output is correct |
8 |
Correct |
2 ms |
8536 KB |
Output is correct |
9 |
Correct |
2 ms |
8540 KB |
Output is correct |
10 |
Correct |
2 ms |
8540 KB |
Output is correct |
11 |
Correct |
46 ms |
17492 KB |
Output is correct |
12 |
Correct |
38 ms |
16720 KB |
Output is correct |
13 |
Correct |
119 ms |
24660 KB |
Output is correct |
14 |
Correct |
58 ms |
18676 KB |
Output is correct |
15 |
Correct |
66 ms |
18736 KB |
Output is correct |
16 |
Correct |
82 ms |
22744 KB |
Output is correct |
17 |
Correct |
126 ms |
24756 KB |
Output is correct |
18 |
Correct |
117 ms |
25428 KB |
Output is correct |
19 |
Correct |
43 ms |
17236 KB |
Output is correct |
20 |
Correct |
37 ms |
16724 KB |
Output is correct |
21 |
Correct |
135 ms |
24652 KB |
Output is correct |
22 |
Correct |
59 ms |
18696 KB |
Output is correct |
23 |
Correct |
54 ms |
18632 KB |
Output is correct |
24 |
Correct |
91 ms |
22728 KB |
Output is correct |
25 |
Correct |
135 ms |
24916 KB |
Output is correct |
26 |
Correct |
115 ms |
25428 KB |
Output is correct |
27 |
Correct |
46 ms |
16720 KB |
Output is correct |
28 |
Correct |
62 ms |
18136 KB |
Output is correct |
29 |
Correct |
181 ms |
35704 KB |
Output is correct |
30 |
Correct |
100 ms |
27332 KB |
Output is correct |
31 |
Correct |
104 ms |
27440 KB |
Output is correct |
32 |
Correct |
149 ms |
35468 KB |
Output is correct |
33 |
Correct |
2 ms |
8540 KB |
Output is correct |
34 |
Correct |
2 ms |
8536 KB |
Output is correct |
35 |
Correct |
2 ms |
8540 KB |
Output is correct |
36 |
Correct |
2 ms |
8540 KB |
Output is correct |
37 |
Correct |
2 ms |
8540 KB |
Output is correct |
38 |
Correct |
2 ms |
8540 KB |
Output is correct |
39 |
Correct |
2 ms |
8540 KB |
Output is correct |
40 |
Correct |
4 ms |
8672 KB |
Output is correct |
41 |
Correct |
2 ms |
8540 KB |
Output is correct |
42 |
Correct |
2 ms |
8540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8540 KB |
Output is correct |
2 |
Incorrect |
19 ms |
12632 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |