#include <algorithm>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> plli;
typedef vector<vector<ll>> matrix;
int n, m, k;
vector<int> edges[300005];
int colors[300005];
ll dp[300005][32];
void solve() {
cin >> n >> m >> k;
for(int i = 0; i < n; i++) {
cin >> colors[i];
colors[i]--;
}
while(m--) {
int a, b;
cin >> a >> b;
edges[--a].push_back(--b);
edges[b].push_back(a);
}
for(int i = 0; i < n; i++) {
for(int out: edges[i]) {
if(colors[i] != colors[out]) {
dp[out][(1 << colors[i]) | (1 << colors[out])]++;
}
}
}
ll ret = 0;
for(int mask = 1; mask < (1<<k); mask++) {
for(int i = 0; i < n; i++) {
if(dp[i][mask] == 0) continue;
ret += dp[i][mask];
for(int out: edges[i]) {
if(mask&(1<<colors[out])) continue;
dp[out][mask | (1 << colors[out])] += dp[i][mask];
}
}
}
cout << ret << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
/*
int t;
cin >> t;
for(int i = 1; i <= t; i++) {
cout << "Case #" << i << ": ";
solve();
}
*/
solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
7424 KB |
Output is correct |
2 |
Correct |
8 ms |
7424 KB |
Output is correct |
3 |
Correct |
7 ms |
7424 KB |
Output is correct |
4 |
Correct |
7 ms |
7424 KB |
Output is correct |
5 |
Correct |
8 ms |
7424 KB |
Output is correct |
6 |
Correct |
7 ms |
7424 KB |
Output is correct |
7 |
Correct |
7 ms |
7424 KB |
Output is correct |
8 |
Correct |
8 ms |
7424 KB |
Output is correct |
9 |
Correct |
9 ms |
7424 KB |
Output is correct |
10 |
Correct |
9 ms |
7424 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
110 ms |
15144 KB |
Output is correct |
2 |
Correct |
81 ms |
13304 KB |
Output is correct |
3 |
Correct |
499 ms |
96468 KB |
Output is correct |
4 |
Correct |
175 ms |
22824 KB |
Output is correct |
5 |
Correct |
150 ms |
15220 KB |
Output is correct |
6 |
Correct |
354 ms |
69556 KB |
Output is correct |
7 |
Correct |
480 ms |
96632 KB |
Output is correct |
8 |
Correct |
473 ms |
97272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
7424 KB |
Output is correct |
2 |
Correct |
8 ms |
7424 KB |
Output is correct |
3 |
Correct |
7 ms |
7424 KB |
Output is correct |
4 |
Correct |
7 ms |
7424 KB |
Output is correct |
5 |
Correct |
8 ms |
7424 KB |
Output is correct |
6 |
Correct |
7 ms |
7424 KB |
Output is correct |
7 |
Correct |
7 ms |
7424 KB |
Output is correct |
8 |
Correct |
8 ms |
7424 KB |
Output is correct |
9 |
Correct |
9 ms |
7424 KB |
Output is correct |
10 |
Correct |
9 ms |
7424 KB |
Output is correct |
11 |
Correct |
110 ms |
15144 KB |
Output is correct |
12 |
Correct |
81 ms |
13304 KB |
Output is correct |
13 |
Correct |
499 ms |
96468 KB |
Output is correct |
14 |
Correct |
175 ms |
22824 KB |
Output is correct |
15 |
Correct |
150 ms |
15220 KB |
Output is correct |
16 |
Correct |
354 ms |
69556 KB |
Output is correct |
17 |
Correct |
480 ms |
96632 KB |
Output is correct |
18 |
Correct |
473 ms |
97272 KB |
Output is correct |
19 |
Correct |
103 ms |
15272 KB |
Output is correct |
20 |
Correct |
75 ms |
13296 KB |
Output is correct |
21 |
Correct |
541 ms |
96592 KB |
Output is correct |
22 |
Correct |
133 ms |
22776 KB |
Output is correct |
23 |
Correct |
136 ms |
15352 KB |
Output is correct |
24 |
Correct |
326 ms |
69504 KB |
Output is correct |
25 |
Correct |
474 ms |
96672 KB |
Output is correct |
26 |
Correct |
461 ms |
97192 KB |
Output is correct |
27 |
Correct |
93 ms |
13304 KB |
Output is correct |
28 |
Correct |
141 ms |
16632 KB |
Output is correct |
29 |
Correct |
579 ms |
96660 KB |
Output is correct |
30 |
Correct |
362 ms |
55404 KB |
Output is correct |
31 |
Correct |
372 ms |
55424 KB |
Output is correct |
32 |
Correct |
568 ms |
96664 KB |
Output is correct |
33 |
Correct |
7 ms |
7424 KB |
Output is correct |
34 |
Correct |
8 ms |
7424 KB |
Output is correct |
35 |
Correct |
8 ms |
7380 KB |
Output is correct |
36 |
Correct |
8 ms |
7424 KB |
Output is correct |
37 |
Correct |
8 ms |
7424 KB |
Output is correct |
38 |
Correct |
9 ms |
7424 KB |
Output is correct |
39 |
Correct |
8 ms |
7424 KB |
Output is correct |
40 |
Correct |
8 ms |
7424 KB |
Output is correct |
41 |
Correct |
8 ms |
7424 KB |
Output is correct |
42 |
Correct |
9 ms |
7424 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
7424 KB |
Output is correct |
2 |
Correct |
45 ms |
9336 KB |
Output is correct |
3 |
Correct |
32 ms |
9344 KB |
Output is correct |
4 |
Correct |
131 ms |
37112 KB |
Output is correct |
5 |
Correct |
85 ms |
37744 KB |
Output is correct |
6 |
Correct |
177 ms |
37020 KB |
Output is correct |
7 |
Correct |
32 ms |
9336 KB |
Output is correct |
8 |
Correct |
163 ms |
37112 KB |
Output is correct |
9 |
Correct |
126 ms |
37744 KB |
Output is correct |
10 |
Correct |
116 ms |
37616 KB |
Output is correct |
11 |
Correct |
82 ms |
23028 KB |
Output is correct |
12 |
Correct |
109 ms |
30680 KB |
Output is correct |
13 |
Correct |
118 ms |
23136 KB |
Output is correct |
14 |
Correct |
222 ms |
37000 KB |
Output is correct |
15 |
Correct |
232 ms |
37240 KB |
Output is correct |
16 |
Correct |
7 ms |
7424 KB |
Output is correct |
17 |
Correct |
9 ms |
7552 KB |
Output is correct |
18 |
Correct |
8 ms |
7424 KB |
Output is correct |
19 |
Correct |
8 ms |
7424 KB |
Output is correct |
20 |
Correct |
10 ms |
7424 KB |
Output is correct |
21 |
Correct |
9 ms |
7424 KB |
Output is correct |
22 |
Correct |
9 ms |
7424 KB |
Output is correct |
23 |
Correct |
8 ms |
7424 KB |
Output is correct |
24 |
Correct |
8 ms |
7424 KB |
Output is correct |
25 |
Correct |
7 ms |
7424 KB |
Output is correct |