#include <bits/stdc++.h>
using namespace std;
int n, m, k;
const int maxn = 3e5+1;
vector <int> adj[maxn];
int col[maxn];
int cnt;
bool vis[maxn];
void solve(int s, int p, int x, int len, int has) {
if (vis[s] || len > k)
return;
vis[s] = true;
if (len > 1)
cnt++;
for (auto i : adj[s]) {
if (i == p)
continue;
if (has & (1 << col[i]))
continue;
solve(i, s, x + (1 << len) * col[i], len + 1, has + (1 << col[i]));
}
vis[s] = false;
}
int main() {
cin >> n >> m >> k;
for (int i = 1; i <= n; i++)
cin >> col[i];
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
}
for (int i = 1; i <= n; i++)
solve(i, i, col[i], 1, (1 << col[i]));
cout << cnt << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8784 KB |
Output is correct |
2 |
Correct |
2 ms |
8784 KB |
Output is correct |
3 |
Correct |
2 ms |
8784 KB |
Output is correct |
4 |
Correct |
3 ms |
8528 KB |
Output is correct |
5 |
Correct |
3 ms |
8784 KB |
Output is correct |
6 |
Correct |
2 ms |
8784 KB |
Output is correct |
7 |
Correct |
2 ms |
8952 KB |
Output is correct |
8 |
Correct |
2 ms |
8784 KB |
Output is correct |
9 |
Correct |
2 ms |
8528 KB |
Output is correct |
10 |
Correct |
2 ms |
8784 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2369 ms |
15188 KB |
Output is correct |
2 |
Execution timed out |
3060 ms |
14404 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8784 KB |
Output is correct |
2 |
Correct |
2 ms |
8784 KB |
Output is correct |
3 |
Correct |
2 ms |
8784 KB |
Output is correct |
4 |
Correct |
3 ms |
8528 KB |
Output is correct |
5 |
Correct |
3 ms |
8784 KB |
Output is correct |
6 |
Correct |
2 ms |
8784 KB |
Output is correct |
7 |
Correct |
2 ms |
8952 KB |
Output is correct |
8 |
Correct |
2 ms |
8784 KB |
Output is correct |
9 |
Correct |
2 ms |
8528 KB |
Output is correct |
10 |
Correct |
2 ms |
8784 KB |
Output is correct |
11 |
Correct |
2369 ms |
15188 KB |
Output is correct |
12 |
Execution timed out |
3060 ms |
14404 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8528 KB |
Output is correct |
2 |
Execution timed out |
3067 ms |
10580 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |