#include <bits/stdc++.h>
using namespace std;
long long solve(vector<vector<int>> &adj, int current, int colsUsed, int K, vector<int> &colors)
{
int cnt = 0;
for (auto u : adj[current])
{
if ((colsUsed & (1 << colors[u])) == 0)
{
cnt += solve(adj, u, colsUsed ^ (1 << colors[u]), K, colors) + 1;
}
}
return cnt;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m, K;
cin >> n >> m >> K;
vector<int> cols;
for (int i = 0; i < n; i++)
{
int x;
cin >> x;
x--;
cols.push_back(x);
}
vector<vector<int>> graph(n);
for (int i = 0; i < m; i++)
{
int a, b;
cin >> a >> b;
a--; b--;
graph[a].push_back(b);
graph[b].push_back(a);
}
int res = 0;
for (int i = 0; i < n; i++)
{
res += solve(graph, i, (1 << cols[i]), K, cols);
}
cout << res;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3094 ms |
6932 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Execution timed out |
3094 ms |
6932 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Execution timed out |
3065 ms |
2148 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |