#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define xx first
#define yy second
#define pb push_back
#define MAXN 300010
#define MAXK 6
using namespace std;
int n, m, k, a[MAXN];
ll cnt[MAXN][MAXK], ress;
vector<pii> grane;
int main() {
cin>>n>>m>>k;
for (int i=1; i<=n; i++)
cin>>a[i];
for (int i=0; i<m; i++)
{
int u, v; cin>>u>>v;
grane.pb({u, v});
cnt[u][a[v]]++;
cnt[v][a[u]]++;
}
for (auto par:grane)
{
int u=par.xx, v=par.yy;
if (a[u]==a[v]) continue;
ress+=2;
vector<int> boje;
for (int i=1; i<=4; i++) if (a[u]!=i && a[v]!=i) boje.pb(i);
int c1, c2;
c1=boje[0]; c2=boje[1];
ress+=2*((cnt[u][c1]*cnt[v][c2])+(cnt[u][c2]*cnt[v][c1]))+cnt[u][c1]+cnt[u][c2]+cnt[v][c1]+cnt[v][c2];
//cout<<u<<" "<<v<<" "<<ress<<endl;
}
cout<<ress;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2488 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
118 ms |
12132 KB |
Output is correct |
2 |
Correct |
117 ms |
10420 KB |
Output is correct |
3 |
Correct |
201 ms |
24900 KB |
Output is correct |
4 |
Correct |
125 ms |
12784 KB |
Output is correct |
5 |
Correct |
124 ms |
13936 KB |
Output is correct |
6 |
Correct |
168 ms |
21952 KB |
Output is correct |
7 |
Correct |
204 ms |
25796 KB |
Output is correct |
8 |
Correct |
260 ms |
25668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2488 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
118 ms |
12132 KB |
Output is correct |
12 |
Correct |
117 ms |
10420 KB |
Output is correct |
13 |
Correct |
201 ms |
24900 KB |
Output is correct |
14 |
Correct |
125 ms |
12784 KB |
Output is correct |
15 |
Correct |
124 ms |
13936 KB |
Output is correct |
16 |
Correct |
168 ms |
21952 KB |
Output is correct |
17 |
Correct |
204 ms |
25796 KB |
Output is correct |
18 |
Correct |
260 ms |
25668 KB |
Output is correct |
19 |
Correct |
117 ms |
13508 KB |
Output is correct |
20 |
Correct |
97 ms |
10104 KB |
Output is correct |
21 |
Correct |
206 ms |
24224 KB |
Output is correct |
22 |
Correct |
122 ms |
12748 KB |
Output is correct |
23 |
Correct |
115 ms |
13380 KB |
Output is correct |
24 |
Correct |
183 ms |
22964 KB |
Output is correct |
25 |
Correct |
237 ms |
25640 KB |
Output is correct |
26 |
Correct |
208 ms |
25064 KB |
Output is correct |
27 |
Correct |
106 ms |
10928 KB |
Output is correct |
28 |
Correct |
117 ms |
12188 KB |
Output is correct |
29 |
Correct |
210 ms |
25948 KB |
Output is correct |
30 |
Correct |
166 ms |
20500 KB |
Output is correct |
31 |
Correct |
172 ms |
20736 KB |
Output is correct |
32 |
Correct |
222 ms |
24876 KB |
Output is correct |
33 |
Correct |
1 ms |
2396 KB |
Output is correct |
34 |
Correct |
1 ms |
2496 KB |
Output is correct |
35 |
Correct |
1 ms |
2396 KB |
Output is correct |
36 |
Correct |
1 ms |
2396 KB |
Output is correct |
37 |
Correct |
1 ms |
2396 KB |
Output is correct |
38 |
Correct |
1 ms |
2396 KB |
Output is correct |
39 |
Correct |
1 ms |
2396 KB |
Output is correct |
40 |
Correct |
1 ms |
2396 KB |
Output is correct |
41 |
Correct |
1 ms |
2396 KB |
Output is correct |
42 |
Correct |
1 ms |
2648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Incorrect |
34 ms |
4208 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |