This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |