#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mxN = 3e5 + 7;
const int mxK = 39;
int n, m, k, color[mxN], dp[mxN][mxK];
vector<int> graph[mxN];
bool vis[mxN];
void dfs(int u, int mask, int cnt) {
vis[u] = true;
if (cnt > 1) {
dp[u][mask] = 1;
}
for (auto v : graph[u]) {
if (!vis[v]) {
if (!(mask & (1 << color[v]))) {
dfs(v, mask & (1 << color[v]), cnt + 1);
dp[u][mask] += dp[v][mask & (1 << color[v])];
}
dfs(v, 1 << color[v], 1);
dp[u][mask] += dp[v][1 << color[v]];
}
}
vis[u] = false;
}
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m >> k;
for (int u = 1; u <= n; ++u) {
cin >> color[u];
color[u]--;
}
for (int i = 0; i < m; ++i) {
int u, v;
cin >> u >> v;
graph[u].push_back(v);
graph[v].push_back(u);
}
dfs(1, (1 << color[1]), 1);
cout << dp[1][(1 << color[1])] * 2 << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3055 ms |
7388 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3057 ms |
19392 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3055 ms |
7388 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7372 KB |
Output is correct |
2 |
Execution timed out |
3081 ms |
10452 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |