이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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';
}
# | 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... |