#include <bits/stdc++.h>
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using cd = complex <double>;
typedef pair <int, int> pii;
const int N = 3e3 + 5;
const long long INF = 1e18;
const int mod = 998244353;//786433;//998244353;
const double Pi = acos(-1);
void Fastio()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
int n, m, k;
int c[300005];
long long dp[300005][32];
vector <int> Adj[300005];
int main()
{
cin >> n >> m >> k;
for(int i = 1; i <= n; i++)
{
cin >> c[i];
c[i]--;
dp[i][1 << c[i]] = 1;
}
for(int i = 1; i <= m; i++)
{
int u, v;
cin >> u >> v;
Adj[u].eb(v);
Adj[v].eb(u);
}
for(int i = 2; i <= k; i++)
{
for(int j = 1; j <= n; j++)
{
for(int t = 1; t <= 31; t++)
{
if(__builtin_popcount(t) != i - 1)
{
continue;
}
for(auto x : Adj[j])
{
if((t & (1 << c[x])) == 0)
{
dp[x][t ^ (1 << c[x])] += dp[j][t];
}
}
}
}
}
long long ans = 0;
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= 31; j++)
{
ans += dp[i][j];
}
}
cout << ans - (long long)n;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
7424 KB |
Output is correct |
2 |
Correct |
5 ms |
7424 KB |
Output is correct |
3 |
Correct |
5 ms |
7424 KB |
Output is correct |
4 |
Correct |
5 ms |
7424 KB |
Output is correct |
5 |
Correct |
6 ms |
7424 KB |
Output is correct |
6 |
Correct |
5 ms |
7424 KB |
Output is correct |
7 |
Correct |
5 ms |
7424 KB |
Output is correct |
8 |
Correct |
5 ms |
7424 KB |
Output is correct |
9 |
Correct |
5 ms |
7424 KB |
Output is correct |
10 |
Correct |
5 ms |
7424 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
396 ms |
15096 KB |
Output is correct |
2 |
Correct |
329 ms |
13308 KB |
Output is correct |
3 |
Correct |
1014 ms |
96632 KB |
Output is correct |
4 |
Correct |
456 ms |
22904 KB |
Output is correct |
5 |
Correct |
407 ms |
22904 KB |
Output is correct |
6 |
Correct |
806 ms |
69548 KB |
Output is correct |
7 |
Correct |
1034 ms |
96632 KB |
Output is correct |
8 |
Correct |
1029 ms |
97272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
7424 KB |
Output is correct |
2 |
Correct |
5 ms |
7424 KB |
Output is correct |
3 |
Correct |
5 ms |
7424 KB |
Output is correct |
4 |
Correct |
5 ms |
7424 KB |
Output is correct |
5 |
Correct |
6 ms |
7424 KB |
Output is correct |
6 |
Correct |
5 ms |
7424 KB |
Output is correct |
7 |
Correct |
5 ms |
7424 KB |
Output is correct |
8 |
Correct |
5 ms |
7424 KB |
Output is correct |
9 |
Correct |
5 ms |
7424 KB |
Output is correct |
10 |
Correct |
5 ms |
7424 KB |
Output is correct |
11 |
Correct |
396 ms |
15096 KB |
Output is correct |
12 |
Correct |
329 ms |
13308 KB |
Output is correct |
13 |
Correct |
1014 ms |
96632 KB |
Output is correct |
14 |
Correct |
456 ms |
22904 KB |
Output is correct |
15 |
Correct |
407 ms |
22904 KB |
Output is correct |
16 |
Correct |
806 ms |
69548 KB |
Output is correct |
17 |
Correct |
1034 ms |
96632 KB |
Output is correct |
18 |
Correct |
1029 ms |
97272 KB |
Output is correct |
19 |
Correct |
407 ms |
15352 KB |
Output is correct |
20 |
Correct |
331 ms |
13332 KB |
Output is correct |
21 |
Correct |
986 ms |
96888 KB |
Output is correct |
22 |
Correct |
436 ms |
22832 KB |
Output is correct |
23 |
Correct |
391 ms |
22904 KB |
Output is correct |
24 |
Correct |
791 ms |
69712 KB |
Output is correct |
25 |
Correct |
968 ms |
96632 KB |
Output is correct |
26 |
Correct |
966 ms |
97272 KB |
Output is correct |
27 |
Correct |
378 ms |
13304 KB |
Output is correct |
28 |
Correct |
466 ms |
16760 KB |
Output is correct |
29 |
Correct |
1158 ms |
96632 KB |
Output is correct |
30 |
Correct |
870 ms |
55532 KB |
Output is correct |
31 |
Correct |
888 ms |
55664 KB |
Output is correct |
32 |
Correct |
1158 ms |
96760 KB |
Output is correct |
33 |
Correct |
6 ms |
7424 KB |
Output is correct |
34 |
Correct |
5 ms |
7424 KB |
Output is correct |
35 |
Correct |
5 ms |
7424 KB |
Output is correct |
36 |
Correct |
5 ms |
7424 KB |
Output is correct |
37 |
Correct |
5 ms |
7424 KB |
Output is correct |
38 |
Correct |
5 ms |
7424 KB |
Output is correct |
39 |
Correct |
5 ms |
7424 KB |
Output is correct |
40 |
Correct |
5 ms |
7424 KB |
Output is correct |
41 |
Correct |
5 ms |
7424 KB |
Output is correct |
42 |
Correct |
5 ms |
7424 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
7424 KB |
Output is correct |
2 |
Correct |
134 ms |
9360 KB |
Output is correct |
3 |
Correct |
112 ms |
9336 KB |
Output is correct |
4 |
Correct |
288 ms |
36984 KB |
Output is correct |
5 |
Correct |
275 ms |
37744 KB |
Output is correct |
6 |
Correct |
387 ms |
36988 KB |
Output is correct |
7 |
Correct |
129 ms |
9336 KB |
Output is correct |
8 |
Correct |
342 ms |
37112 KB |
Output is correct |
9 |
Correct |
299 ms |
38000 KB |
Output is correct |
10 |
Correct |
315 ms |
37748 KB |
Output is correct |
11 |
Correct |
259 ms |
23032 KB |
Output is correct |
12 |
Correct |
278 ms |
30572 KB |
Output is correct |
13 |
Correct |
265 ms |
23288 KB |
Output is correct |
14 |
Correct |
398 ms |
36984 KB |
Output is correct |
15 |
Correct |
416 ms |
37240 KB |
Output is correct |
16 |
Correct |
5 ms |
7424 KB |
Output is correct |
17 |
Correct |
5 ms |
7424 KB |
Output is correct |
18 |
Correct |
5 ms |
7424 KB |
Output is correct |
19 |
Correct |
5 ms |
7424 KB |
Output is correct |
20 |
Correct |
6 ms |
7424 KB |
Output is correct |
21 |
Correct |
5 ms |
7424 KB |
Output is correct |
22 |
Correct |
5 ms |
7424 KB |
Output is correct |
23 |
Correct |
6 ms |
7424 KB |
Output is correct |
24 |
Correct |
5 ms |
7424 KB |
Output is correct |
25 |
Correct |
5 ms |
7424 KB |
Output is correct |