# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
968709 | raphaelp | Paths (BOI18_paths) | C++14 | 499 ms | 41600 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long N, M, K;
cin >> N >> M >> K;
vector<long long> C(N);
for (long long i = 0; i < N; i++)
{
cin >> C[i];
C[i]--;
}
vector<vector<long long>> AR(N);
vector<vector<long long>> voisins(N, vector<long long>(K));
for (long long i = 0; i < M; i++)
{
long long a, b;
cin >> a >> b;
a--, b--;
AR[a].push_back(b);
AR[b].push_back(a);
voisins[a][C[b]]++;
voisins[b][C[a]]++;
}
long long tot = 0, half = 0;
for (long long i = 0; i < N; i++)
{
vector<long long> count((1 << K));
for (long long j = 0; j < AR[i].size(); j++)
{
count[(1 << C[AR[i][j]])]++;
for (long long k = 0; k < K; k++)
{
if (k == C[AR[i][j]])
continue;
count[((1 << C[AR[i][j]]) | (1 << k))] += voisins[AR[i][j]][k];
}
}
for (long long j = 1; j < (1 << K); j++)
{
if (j & (1 << C[i]))
continue;
if (__builtin_popcount(j) > 2)
continue;
if (__builtin_popcount(j) == 1 && K >= 2)
half += count[j];
if (__builtin_popcount(j) == 1 && K >= 3)
{
for (long long k = 0; k < K; k++)
{
if ((j & (1 << k)) || k == C[i])
continue;
half += count[(1 << k)] * count[j];
}
}
if (__builtin_popcount(j) == 2 && K >= 4)
{
for (long long k = 0; k < K; k++)
{
if ((j & (1 << k)) || k == C[i])
continue;
half += count[(1 << k)] * count[j];
}
}
if (__builtin_popcount(j) == 2 && K >= 5)
{
half += count[j] * count[((1 << K) - 1 - j - (1 << C[i]))];
}
}
}
cout << tot * 2 + half;
}
Compilation message (stderr)
# | 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... |