#include <bits/stdc++.h>
using namespace std;
#define int long long
int n, m, k;
vector<int> ord;
const int MAXN = 3e5 + 10;
vector<int> adj[MAXN];
int cor[MAXN];
int dp[MAXN];
int t;
void calc(int node, int i) {
if (dp[node] != -1) return;
if (i == (t - 1)) {
dp[node] = 1;
return;
}
dp[node] = 0;
for (auto u : adj[node]) {
if (cor[u] == ord[i + 1]) {
calc(u, i + 1);
dp[node] += dp[u];
}
}
}
int32_t main() {
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;
adj[a].push_back(b);
adj[b].push_back(a);
}
int ans = 0;
for (int mask = 1; mask < (1LL << k); mask++) {
ord.clear();
for (int i = 0; i < k; i++) {
if (mask & (1LL << i)) ord.push_back(i + 1);
}
t = ord.size();
if (t == 1) continue;
do {
// do it now!!
//for (auto u : ord) cout << u << " ";
//cout << "\n";
int currans = 0;
memset(dp, -1, sizeof dp);
for (int i = 1; i <= n; i++) {
if (cor[i] == ord[0]) {
calc(i, 0);
currans += dp[i];
}
}
//cout << "ans " << currans << "\n";
ans += currans;
} while (next_permutation(ord.begin(), ord.end()));
}
cout << ans << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
9808 KB |
Output is correct |
2 |
Correct |
9 ms |
9808 KB |
Output is correct |
3 |
Correct |
8 ms |
9808 KB |
Output is correct |
4 |
Correct |
7 ms |
9808 KB |
Output is correct |
5 |
Correct |
5 ms |
7248 KB |
Output is correct |
6 |
Correct |
10 ms |
9808 KB |
Output is correct |
7 |
Correct |
12 ms |
9808 KB |
Output is correct |
8 |
Correct |
11 ms |
9808 KB |
Output is correct |
9 |
Correct |
12 ms |
9808 KB |
Output is correct |
10 |
Correct |
8 ms |
9808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
134 ms |
16968 KB |
Output is correct |
2 |
Correct |
112 ms |
16944 KB |
Output is correct |
3 |
Correct |
425 ms |
22604 KB |
Output is correct |
4 |
Correct |
195 ms |
18212 KB |
Output is correct |
5 |
Correct |
135 ms |
15680 KB |
Output is correct |
6 |
Correct |
257 ms |
20156 KB |
Output is correct |
7 |
Correct |
381 ms |
22600 KB |
Output is correct |
8 |
Correct |
388 ms |
23204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
9808 KB |
Output is correct |
2 |
Correct |
9 ms |
9808 KB |
Output is correct |
3 |
Correct |
8 ms |
9808 KB |
Output is correct |
4 |
Correct |
7 ms |
9808 KB |
Output is correct |
5 |
Correct |
5 ms |
7248 KB |
Output is correct |
6 |
Correct |
10 ms |
9808 KB |
Output is correct |
7 |
Correct |
12 ms |
9808 KB |
Output is correct |
8 |
Correct |
11 ms |
9808 KB |
Output is correct |
9 |
Correct |
12 ms |
9808 KB |
Output is correct |
10 |
Correct |
8 ms |
9808 KB |
Output is correct |
11 |
Correct |
134 ms |
16968 KB |
Output is correct |
12 |
Correct |
112 ms |
16944 KB |
Output is correct |
13 |
Correct |
425 ms |
22604 KB |
Output is correct |
14 |
Correct |
195 ms |
18212 KB |
Output is correct |
15 |
Correct |
135 ms |
15680 KB |
Output is correct |
16 |
Correct |
257 ms |
20156 KB |
Output is correct |
17 |
Correct |
381 ms |
22600 KB |
Output is correct |
18 |
Correct |
388 ms |
23204 KB |
Output is correct |
19 |
Correct |
126 ms |
16968 KB |
Output is correct |
20 |
Correct |
106 ms |
16820 KB |
Output is correct |
21 |
Correct |
425 ms |
22684 KB |
Output is correct |
22 |
Correct |
143 ms |
17984 KB |
Output is correct |
23 |
Correct |
202 ms |
15812 KB |
Output is correct |
24 |
Correct |
234 ms |
20024 KB |
Output is correct |
25 |
Correct |
364 ms |
22600 KB |
Output is correct |
26 |
Correct |
327 ms |
23216 KB |
Output is correct |
27 |
Correct |
174 ms |
16720 KB |
Output is correct |
28 |
Correct |
205 ms |
18308 KB |
Output is correct |
29 |
Correct |
865 ms |
22508 KB |
Output is correct |
30 |
Correct |
609 ms |
19448 KB |
Output is correct |
31 |
Correct |
510 ms |
19908 KB |
Output is correct |
32 |
Correct |
688 ms |
22872 KB |
Output is correct |
33 |
Correct |
10 ms |
9808 KB |
Output is correct |
34 |
Correct |
11 ms |
9808 KB |
Output is correct |
35 |
Correct |
7 ms |
9844 KB |
Output is correct |
36 |
Correct |
7 ms |
9808 KB |
Output is correct |
37 |
Correct |
5 ms |
7504 KB |
Output is correct |
38 |
Correct |
10 ms |
9808 KB |
Output is correct |
39 |
Correct |
11 ms |
9840 KB |
Output is correct |
40 |
Correct |
13 ms |
9712 KB |
Output is correct |
41 |
Correct |
10 ms |
9808 KB |
Output is correct |
42 |
Correct |
8 ms |
9808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
9808 KB |
Output is correct |
2 |
Correct |
175 ms |
11932 KB |
Output is correct |
3 |
Correct |
56 ms |
11936 KB |
Output is correct |
4 |
Correct |
105 ms |
14124 KB |
Output is correct |
5 |
Correct |
98 ms |
14524 KB |
Output is correct |
6 |
Correct |
539 ms |
13896 KB |
Output is correct |
7 |
Correct |
73 ms |
12012 KB |
Output is correct |
8 |
Correct |
231 ms |
14152 KB |
Output is correct |
9 |
Correct |
135 ms |
14524 KB |
Output is correct |
10 |
Correct |
188 ms |
14012 KB |
Output is correct |
11 |
Correct |
374 ms |
12700 KB |
Output is correct |
12 |
Correct |
258 ms |
13372 KB |
Output is correct |
13 |
Correct |
305 ms |
12804 KB |
Output is correct |
14 |
Correct |
557 ms |
14016 KB |
Output is correct |
15 |
Correct |
483 ms |
14200 KB |
Output is correct |
16 |
Correct |
11 ms |
9808 KB |
Output is correct |
17 |
Correct |
10 ms |
9808 KB |
Output is correct |
18 |
Correct |
8 ms |
9808 KB |
Output is correct |
19 |
Correct |
7 ms |
9808 KB |
Output is correct |
20 |
Correct |
6 ms |
7504 KB |
Output is correct |
21 |
Correct |
10 ms |
9760 KB |
Output is correct |
22 |
Correct |
10 ms |
9808 KB |
Output is correct |
23 |
Correct |
10 ms |
9808 KB |
Output is correct |
24 |
Correct |
10 ms |
9836 KB |
Output is correct |
25 |
Correct |
8 ms |
9844 KB |
Output is correct |