#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define F first
#define S second
using namespace std;
ll N, M, K, color[300005], adj[300005][5];
pii edge[300005];
ll ans;
signed main()
{
ios::sync_with_stdio(0), cin.tie(0);
cin >> N >> M >> K;
for (int i = 1; i <= N; i++)
cin >> color[i];
for (int i = 1; i <= M; i++)
cin >> edge[i].F >> edge[i].S;
if (K >= 2)
{
for (int i = 1; i <= M; i++)
if (color[edge[i].F] != color[edge[i].S])
ans += 2;
}
cerr << ans << '\n';
if (K >= 3)
{
for (int i = 1; i <= M; i++)
if (color[edge[i].F] != color[edge[i].S])
{
adj[edge[i].F][color[edge[i].S]]++;
adj[edge[i].S][color[edge[i].F]]++;
}
for (int i = 1; i <= N; i++)
for (int j = 1; j <= K; j++)
for (int k = j + 1; k <= K; k++)
ans += adj[i][j] * adj[i][k] * 2;
}
cerr << ans << '\n';
if (K >= 4)
{
for (int i = 1; i <= M; i++)
if (color[edge[i].F] != color[edge[i].S])
for (int j = 1; j <= K; j++)
for (int k = 1; k <= K; k++)
if (j != k && color[edge[i].F] != k && color[edge[i].S] != j)
ans += adj[edge[i].F][j] * adj[edge[i].S][k] * 2;
}
cout << ans << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
67 ms |
2824 KB |
Output is correct |
2 |
Correct |
56 ms |
2700 KB |
Output is correct |
3 |
Correct |
86 ms |
16724 KB |
Output is correct |
4 |
Correct |
47 ms |
2816 KB |
Output is correct |
5 |
Correct |
53 ms |
2832 KB |
Output is correct |
6 |
Correct |
67 ms |
12048 KB |
Output is correct |
7 |
Correct |
86 ms |
21200 KB |
Output is correct |
8 |
Correct |
79 ms |
21196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
67 ms |
2824 KB |
Output is correct |
12 |
Correct |
56 ms |
2700 KB |
Output is correct |
13 |
Correct |
86 ms |
16724 KB |
Output is correct |
14 |
Correct |
47 ms |
2816 KB |
Output is correct |
15 |
Correct |
53 ms |
2832 KB |
Output is correct |
16 |
Correct |
67 ms |
12048 KB |
Output is correct |
17 |
Correct |
86 ms |
21200 KB |
Output is correct |
18 |
Correct |
79 ms |
21196 KB |
Output is correct |
19 |
Correct |
50 ms |
5704 KB |
Output is correct |
20 |
Correct |
40 ms |
4936 KB |
Output is correct |
21 |
Correct |
83 ms |
21136 KB |
Output is correct |
22 |
Correct |
59 ms |
6236 KB |
Output is correct |
23 |
Correct |
46 ms |
6188 KB |
Output is correct |
24 |
Correct |
75 ms |
16072 KB |
Output is correct |
25 |
Correct |
93 ms |
21204 KB |
Output is correct |
26 |
Correct |
84 ms |
21192 KB |
Output is correct |
27 |
Correct |
59 ms |
4932 KB |
Output is correct |
28 |
Correct |
69 ms |
5900 KB |
Output is correct |
29 |
Correct |
129 ms |
21208 KB |
Output is correct |
30 |
Correct |
108 ms |
13668 KB |
Output is correct |
31 |
Correct |
93 ms |
13556 KB |
Output is correct |
32 |
Correct |
140 ms |
21336 KB |
Output is correct |
33 |
Correct |
1 ms |
324 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
1 ms |
336 KB |
Output is correct |
36 |
Correct |
1 ms |
336 KB |
Output is correct |
37 |
Correct |
1 ms |
208 KB |
Output is correct |
38 |
Correct |
0 ms |
328 KB |
Output is correct |
39 |
Correct |
0 ms |
336 KB |
Output is correct |
40 |
Correct |
0 ms |
336 KB |
Output is correct |
41 |
Correct |
1 ms |
324 KB |
Output is correct |
42 |
Correct |
1 ms |
324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Incorrect |
18 ms |
1148 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |