이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using cd = complex <double>;
typedef pair <int, int> pii;
const int N = 3e3 + 5;
const long long INF = 1e18;
const int mod = 998244353;//786433;//998244353;
const double Pi = acos(-1);
void Fastio()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
int n, m, k;
int c[300005];
long long dp[300005][32];
vector <int> Adj[300005];
int main()
{
cin >> n >> m >> k;
for(int i = 1; i <= n; i++)
{
cin >> c[i];
c[i]--;
dp[i][1 << c[i]] = 1;
}
for(int i = 1; i <= m; i++)
{
int u, v;
cin >> u >> v;
Adj[u].eb(v);
Adj[v].eb(u);
}
for(int i = 2; i <= k; i++)
{
for(int j = 1; j <= n; j++)
{
for(int t = 1; t <= 31; t++)
{
if(__builtin_popcount(t) != i - 1)
{
continue;
}
for(auto x : Adj[j])
{
if((t & (1 << c[x])) == 0)
{
dp[x][t ^ (1 << c[x])] += dp[j][t];
}
}
}
}
}
long long ans = 0;
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= 31; j++)
{
ans += dp[i][j];
}
}
cout << ans - (long long)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... |