#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];
vector <int> g[N];
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].pb(v);
g[v].pb(u);
}
int res=0;
queue <pair <set <int>,int > > q;
for(int i=1;i<=n;i++){
q.push({{cl[i]},i});
while(!q.empty()){
set <int> st=q.front().ff;
int v=q.front().ss;
q.pop();
for(auto to : g[v]){
if(st.find(cl[to])==st.end()){
st.insert(cl[to]);
res++;
q.push({st,to});
st.erase(cl[to]);
}
}
}
}
cout<<res<<"\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 |
Incorrect |
2 ms |
8796 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
8796 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
8796 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |