#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define vb vector<bool>
#define vi vector<int>
#define vpii vector<pii>
#define vvpii vector<vpii>
#define vvi vector<vi>
#define tiii tuple<int,int,int>
#define vtiii vector<tiii>
#define F0R(i, n) for(int i = 0; i < (n); ++i)
#define R0F(i, n) for(int i = (n)-1; i >= 0; --i)
#define sz(x) ((int)(x).size())
#define all(x) begin(x), end(x)
#define nl "\n";
vvi Helper;
void initHelper(int K) {
Helper.resize(K+1);
for (int i = 0; i < K; ++i) Helper[1].push_back(1 << i);
for (int i = 2; i <= K; ++i) {
for (int x : Helper[i-1]) {
for (int j = 32 - __builtin_clz(x); j < K; ++j) {
Helper[i].push_back(x | (1<<j));
}
}
}
}
int main() {
ios::sync_with_stdio(false);
cout.tie(0);
cin.tie(0);
int N, M, K;
cin >> N >> M >> K;
initHelper(K);
vvi adj(N);
vi color(N);
int k, a,b;
F0R(i,N) { cin >> k; --k; color[i] = 1 << k; }
F0R(i,M) {
cin >> a >> b;
--a; --b;
adj[a].push_back(b);
adj[b].push_back(a);
}
vvi dp(N, vi(1<<K, 0));
for (int v = 0; v < N; ++v) ++dp[v][color[v]];
ll ans = 0;
for (k = 2; k <= K; ++k) {
for (int v = 0; v < N; ++v) {
for (int u : adj[v]) {
for (int code : Helper[k-1]) {
if ((code & color[v]) > 0) continue;
dp[v][code | color[v]] += dp[u][code];
}
}
for (int code : Helper[k]) ans += dp[v][code];
}
}
cout << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
320 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
6960 KB |
Output is correct |
2 |
Correct |
39 ms |
6160 KB |
Output is correct |
3 |
Correct |
259 ms |
42528 KB |
Output is correct |
4 |
Correct |
92 ms |
10084 KB |
Output is correct |
5 |
Correct |
77 ms |
10060 KB |
Output is correct |
6 |
Correct |
187 ms |
31040 KB |
Output is correct |
7 |
Correct |
269 ms |
42520 KB |
Output is correct |
8 |
Correct |
313 ms |
43144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
320 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
47 ms |
6960 KB |
Output is correct |
12 |
Correct |
39 ms |
6160 KB |
Output is correct |
13 |
Correct |
259 ms |
42528 KB |
Output is correct |
14 |
Correct |
92 ms |
10084 KB |
Output is correct |
15 |
Correct |
77 ms |
10060 KB |
Output is correct |
16 |
Correct |
187 ms |
31040 KB |
Output is correct |
17 |
Correct |
269 ms |
42520 KB |
Output is correct |
18 |
Correct |
313 ms |
43144 KB |
Output is correct |
19 |
Correct |
56 ms |
7012 KB |
Output is correct |
20 |
Correct |
39 ms |
6244 KB |
Output is correct |
21 |
Correct |
286 ms |
42444 KB |
Output is correct |
22 |
Correct |
80 ms |
10104 KB |
Output is correct |
23 |
Correct |
65 ms |
10096 KB |
Output is correct |
24 |
Correct |
166 ms |
31088 KB |
Output is correct |
25 |
Correct |
236 ms |
42544 KB |
Output is correct |
26 |
Correct |
313 ms |
43068 KB |
Output is correct |
27 |
Correct |
43 ms |
6196 KB |
Output is correct |
28 |
Correct |
60 ms |
8156 KB |
Output is correct |
29 |
Correct |
374 ms |
51912 KB |
Output is correct |
30 |
Correct |
203 ms |
29660 KB |
Output is correct |
31 |
Correct |
197 ms |
29560 KB |
Output is correct |
32 |
Correct |
355 ms |
51916 KB |
Output is correct |
33 |
Correct |
1 ms |
316 KB |
Output is correct |
34 |
Correct |
0 ms |
340 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
0 ms |
212 KB |
Output is correct |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
0 ms |
212 KB |
Output is correct |
41 |
Correct |
0 ms |
316 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
18 ms |
2208 KB |
Output is correct |
3 |
Correct |
13 ms |
2132 KB |
Output is correct |
4 |
Correct |
56 ms |
14156 KB |
Output is correct |
5 |
Correct |
37 ms |
14940 KB |
Output is correct |
6 |
Correct |
114 ms |
23628 KB |
Output is correct |
7 |
Correct |
14 ms |
2192 KB |
Output is correct |
8 |
Correct |
63 ms |
17336 KB |
Output is correct |
9 |
Correct |
56 ms |
18116 KB |
Output is correct |
10 |
Correct |
59 ms |
17960 KB |
Output is correct |
11 |
Correct |
53 ms |
12864 KB |
Output is correct |
12 |
Correct |
62 ms |
18764 KB |
Output is correct |
13 |
Correct |
46 ms |
12956 KB |
Output is correct |
14 |
Correct |
123 ms |
23636 KB |
Output is correct |
15 |
Correct |
169 ms |
23732 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
0 ms |
212 KB |
Output is correct |