#define here cerr<<"===========================================\n"
#include <bits/stdc++.h>
#define ld double
#define ll long long
#define llinf 100000000000000000LL // 10^17
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define sz(a) (ll)(a.size())
#define all(a) a.begin(),a.end()
#define ceri(a,l,r) {for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
#define daj_mi_malo_vremena ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);
using namespace std;
#define maxn 300005
#define maxk 6
ll n,m,k;
ll ans = 0;
vector<ll> g[maxn];
ll a[maxn];
ll dp[maxn][maxk][maxk];
ll cnt[maxn][maxk];
vector<pll> edg;
void kraj(){
cout<<ans<<endl;
exit(0);
}
int main(){
daj_mi_malo_vremena
cin >> n >> m >> k;
for(ll i = 1;i<=n;i++) cin >> a[i];
for(ll i = 1;i<=m;i++){
ll x,y; cin >> x >> y;
edg.pb({x,y});
g[x].pb(y);
g[y].pb(x);
}
if(k==1) kraj();
ll cur = 0;
for(ll i = 1;i<=n;i++){
for(ll j : g[i]){
if(a[i]==a[j]) continue;
cnt[i][a[j]]++;
cur++;
}
}
ans+=cur;
if(k==2) kraj();
cur = 0;
for(ll i = 1;i<=n;i++){
vector<ll> v(k+1);
for(ll j : g[i]){
v[a[j]]++;
}
ll coli = a[i];
for(ll e = 1;e<=k;e++){
for(ll r = e+1;r<=k;r++){
if(e==coli||r==coli) continue;
cur+=v[e]*v[r];
}
}
}
ans+=2*cur;
cerr<<"k = 3: "<<ans<<endl;
if(k==3) kraj();
cur = 0;
for(pll p : edg){
ll x = p.fi;
ll y = p.sc;
ll colx = a[x];
ll coly = a[y];
if(colx==coly) continue;
for(ll e = 1;e<=k;e++){
if(e==colx||e==coly) continue;
for(ll r = e+1;r<=k;r++){
if(r==colx||r==coly) continue;
cur+=cnt[x][e]*cnt[y][r];
cur+=cnt[x][r]*cnt[y][e];
}
}
}
cur*=2;
ans+=cur;
if(k==4) kraj();
for(ll i = 1;i<=n;i++){
for(ll j : g[i]){
ll coli = a[i];
ll colj = a[j];
for(ll e = 1;e<=k;e++){
dp[i][colj][e] += cnt[j][e];
if(e==coli) dp[i][colj][e]--;
}
}
}
return 0;
}
/*
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 |
3 ms |
7380 KB |
Output is correct |
2 |
Correct |
5 ms |
7380 KB |
Output is correct |
3 |
Correct |
3 ms |
7380 KB |
Output is correct |
4 |
Correct |
4 ms |
7368 KB |
Output is correct |
5 |
Correct |
4 ms |
7372 KB |
Output is correct |
6 |
Correct |
5 ms |
7380 KB |
Output is correct |
7 |
Correct |
4 ms |
7380 KB |
Output is correct |
8 |
Correct |
5 ms |
7316 KB |
Output is correct |
9 |
Correct |
5 ms |
7380 KB |
Output is correct |
10 |
Correct |
4 ms |
7380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
68 ms |
21276 KB |
Output is correct |
2 |
Correct |
56 ms |
22712 KB |
Output is correct |
3 |
Correct |
258 ms |
39028 KB |
Output is correct |
4 |
Correct |
93 ms |
23216 KB |
Output is correct |
5 |
Correct |
85 ms |
23220 KB |
Output is correct |
6 |
Correct |
177 ms |
31776 KB |
Output is correct |
7 |
Correct |
277 ms |
38940 KB |
Output is correct |
8 |
Correct |
279 ms |
39668 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
7380 KB |
Output is correct |
2 |
Correct |
5 ms |
7380 KB |
Output is correct |
3 |
Correct |
3 ms |
7380 KB |
Output is correct |
4 |
Correct |
4 ms |
7368 KB |
Output is correct |
5 |
Correct |
4 ms |
7372 KB |
Output is correct |
6 |
Correct |
5 ms |
7380 KB |
Output is correct |
7 |
Correct |
4 ms |
7380 KB |
Output is correct |
8 |
Correct |
5 ms |
7316 KB |
Output is correct |
9 |
Correct |
5 ms |
7380 KB |
Output is correct |
10 |
Correct |
4 ms |
7380 KB |
Output is correct |
11 |
Correct |
68 ms |
21276 KB |
Output is correct |
12 |
Correct |
56 ms |
22712 KB |
Output is correct |
13 |
Correct |
258 ms |
39028 KB |
Output is correct |
14 |
Correct |
93 ms |
23216 KB |
Output is correct |
15 |
Correct |
85 ms |
23220 KB |
Output is correct |
16 |
Correct |
177 ms |
31776 KB |
Output is correct |
17 |
Correct |
277 ms |
38940 KB |
Output is correct |
18 |
Correct |
279 ms |
39668 KB |
Output is correct |
19 |
Correct |
70 ms |
23992 KB |
Output is correct |
20 |
Correct |
59 ms |
24852 KB |
Output is correct |
21 |
Correct |
261 ms |
43512 KB |
Output is correct |
22 |
Correct |
111 ms |
26308 KB |
Output is correct |
23 |
Correct |
88 ms |
26292 KB |
Output is correct |
24 |
Correct |
184 ms |
35876 KB |
Output is correct |
25 |
Correct |
260 ms |
43480 KB |
Output is correct |
26 |
Correct |
285 ms |
43980 KB |
Output is correct |
27 |
Correct |
68 ms |
24856 KB |
Output is correct |
28 |
Correct |
90 ms |
25596 KB |
Output is correct |
29 |
Correct |
301 ms |
43568 KB |
Output is correct |
30 |
Correct |
184 ms |
33188 KB |
Output is correct |
31 |
Correct |
198 ms |
33032 KB |
Output is correct |
32 |
Correct |
297 ms |
43536 KB |
Output is correct |
33 |
Correct |
4 ms |
7380 KB |
Output is correct |
34 |
Correct |
5 ms |
7324 KB |
Output is correct |
35 |
Correct |
4 ms |
7380 KB |
Output is correct |
36 |
Correct |
4 ms |
7380 KB |
Output is correct |
37 |
Correct |
4 ms |
7372 KB |
Output is correct |
38 |
Correct |
4 ms |
7380 KB |
Output is correct |
39 |
Correct |
4 ms |
7380 KB |
Output is correct |
40 |
Correct |
4 ms |
7380 KB |
Output is correct |
41 |
Correct |
4 ms |
7368 KB |
Output is correct |
42 |
Correct |
4 ms |
7368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
7380 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |