이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
typedef long long ll;
int n, m, k;
int cor[maxn];
int dp[maxn][129];
bool vis[maxn];
vector<int> G[maxn];
inline ll dfs(int x, int mask)
{
//if(mask == (1 << (k + 1)) - 1) return 1;
if(dp[x][mask] != -1) return dp[x][mask];
ll cont = 0;
for(auto u : G[x])
{
if((mask & (1 << cor[u])) == 0)
{
cont += 1 + dfs(u, (mask | (1 << cor[u])));
}
//cont += dfs(u, (1 << cor[u]));
}
return dp[x][mask] = cont;
}
int main()
{
ios::sync_with_stdio(false), cin.tie(nullptr);
cin >> n >> m >> k;
for(int i = 1; i <= n; i++)
cin >> cor[i];
for(int i = 0; i < m; i++)
{
int a, b;
cin >> a >> b;
G[a].push_back(b);
G[b].push_back(a);
}
memset(dp, -1, sizeof(dp));
ll ans = 0;
for(int i = 1; i <= n; i++)
{
ans += dfs(i, 1 << cor[i]);
}
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... |