///
/// Oh? You're approaching me?
///
#include <bits/stdc++.h>
#define Loop(x,l,r) for(ll x = ll(l); x < ll(r); ++x)
#define LoopR(x,l,r) for(ll x = ll(r)-1; x >= ll(l); --x)
#define Kill(x) exit((cout << (x) << '\n', 0))
typedef long long ll;
typedef std::pair<int,int> pii;
typedef std::pair<ll,ll> pll;
using namespace std;
const int N = 300010;
vector<int> A[N];
int c[N];
ll dp[32][N];
int n, m, k;
int main()
{
cin.tie(0) -> sync_with_stdio(false);
cin >> n >> m >> k;
Loop(i,0,n) cin >> c[i], c[i]=1<<(c[i]-1);
Loop(i,0,m){
int v, u;
cin >> v >> u;
--v; --u;
A[v].push_back(u);
A[u].push_back(v);
}
Loop(i,0,n) dp[c[i]][i]=1;
Loop(msk,1,1<<k){
if(__builtin_popcount(msk)==1) continue;
Loop(v,0,n) {
if((msk|c[v]) != msk) continue;
for(int u : A[v])
dp[msk][v] += dp[msk^c[v]][u];
}
}
ll ans = 0;
Loop(msk,1,1<<k) Loop(i,0,n)
ans += dp[msk][i];
cout << ans-n << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7492 KB |
Output is correct |
2 |
Correct |
4 ms |
7500 KB |
Output is correct |
3 |
Correct |
4 ms |
7372 KB |
Output is correct |
4 |
Correct |
4 ms |
7372 KB |
Output is correct |
5 |
Correct |
4 ms |
7372 KB |
Output is correct |
6 |
Correct |
4 ms |
7516 KB |
Output is correct |
7 |
Correct |
4 ms |
7500 KB |
Output is correct |
8 |
Correct |
4 ms |
7500 KB |
Output is correct |
9 |
Correct |
4 ms |
7372 KB |
Output is correct |
10 |
Correct |
4 ms |
7372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
14120 KB |
Output is correct |
2 |
Correct |
50 ms |
13220 KB |
Output is correct |
3 |
Correct |
197 ms |
37704 KB |
Output is correct |
4 |
Correct |
101 ms |
15940 KB |
Output is correct |
5 |
Correct |
77 ms |
15440 KB |
Output is correct |
6 |
Correct |
157 ms |
30204 KB |
Output is correct |
7 |
Correct |
218 ms |
37740 KB |
Output is correct |
8 |
Correct |
211 ms |
38492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7492 KB |
Output is correct |
2 |
Correct |
4 ms |
7500 KB |
Output is correct |
3 |
Correct |
4 ms |
7372 KB |
Output is correct |
4 |
Correct |
4 ms |
7372 KB |
Output is correct |
5 |
Correct |
4 ms |
7372 KB |
Output is correct |
6 |
Correct |
4 ms |
7516 KB |
Output is correct |
7 |
Correct |
4 ms |
7500 KB |
Output is correct |
8 |
Correct |
4 ms |
7500 KB |
Output is correct |
9 |
Correct |
4 ms |
7372 KB |
Output is correct |
10 |
Correct |
4 ms |
7372 KB |
Output is correct |
11 |
Correct |
59 ms |
14120 KB |
Output is correct |
12 |
Correct |
50 ms |
13220 KB |
Output is correct |
13 |
Correct |
197 ms |
37704 KB |
Output is correct |
14 |
Correct |
101 ms |
15940 KB |
Output is correct |
15 |
Correct |
77 ms |
15440 KB |
Output is correct |
16 |
Correct |
157 ms |
30204 KB |
Output is correct |
17 |
Correct |
218 ms |
37740 KB |
Output is correct |
18 |
Correct |
211 ms |
38492 KB |
Output is correct |
19 |
Correct |
60 ms |
14076 KB |
Output is correct |
20 |
Correct |
48 ms |
13240 KB |
Output is correct |
21 |
Correct |
220 ms |
37712 KB |
Output is correct |
22 |
Correct |
83 ms |
15952 KB |
Output is correct |
23 |
Correct |
77 ms |
15452 KB |
Output is correct |
24 |
Correct |
142 ms |
30316 KB |
Output is correct |
25 |
Correct |
219 ms |
37828 KB |
Output is correct |
26 |
Correct |
217 ms |
38452 KB |
Output is correct |
27 |
Correct |
48 ms |
13332 KB |
Output is correct |
28 |
Correct |
67 ms |
15684 KB |
Output is correct |
29 |
Correct |
269 ms |
56528 KB |
Output is correct |
30 |
Correct |
169 ms |
35476 KB |
Output is correct |
31 |
Correct |
176 ms |
34244 KB |
Output is correct |
32 |
Correct |
282 ms |
56688 KB |
Output is correct |
33 |
Correct |
4 ms |
7500 KB |
Output is correct |
34 |
Correct |
4 ms |
7500 KB |
Output is correct |
35 |
Correct |
4 ms |
7364 KB |
Output is correct |
36 |
Correct |
3 ms |
7364 KB |
Output is correct |
37 |
Correct |
5 ms |
7352 KB |
Output is correct |
38 |
Correct |
4 ms |
7500 KB |
Output is correct |
39 |
Correct |
3 ms |
7500 KB |
Output is correct |
40 |
Correct |
4 ms |
7500 KB |
Output is correct |
41 |
Correct |
4 ms |
7372 KB |
Output is correct |
42 |
Correct |
4 ms |
7356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7500 KB |
Output is correct |
2 |
Correct |
20 ms |
9552 KB |
Output is correct |
3 |
Correct |
20 ms |
9232 KB |
Output is correct |
4 |
Correct |
50 ms |
17356 KB |
Output is correct |
5 |
Correct |
50 ms |
18164 KB |
Output is correct |
6 |
Correct |
93 ms |
36296 KB |
Output is correct |
7 |
Correct |
20 ms |
9280 KB |
Output is correct |
8 |
Correct |
65 ms |
23684 KB |
Output is correct |
9 |
Correct |
53 ms |
24480 KB |
Output is correct |
10 |
Correct |
56 ms |
23528 KB |
Output is correct |
11 |
Correct |
63 ms |
22864 KB |
Output is correct |
12 |
Correct |
64 ms |
28348 KB |
Output is correct |
13 |
Correct |
55 ms |
21708 KB |
Output is correct |
14 |
Correct |
92 ms |
36300 KB |
Output is correct |
15 |
Correct |
110 ms |
36444 KB |
Output is correct |
16 |
Correct |
4 ms |
7500 KB |
Output is correct |
17 |
Correct |
4 ms |
7500 KB |
Output is correct |
18 |
Correct |
5 ms |
7372 KB |
Output is correct |
19 |
Correct |
4 ms |
7372 KB |
Output is correct |
20 |
Correct |
3 ms |
7372 KB |
Output is correct |
21 |
Correct |
4 ms |
7504 KB |
Output is correct |
22 |
Correct |
4 ms |
7500 KB |
Output is correct |
23 |
Correct |
5 ms |
7500 KB |
Output is correct |
24 |
Correct |
4 ms |
7368 KB |
Output is correct |
25 |
Correct |
4 ms |
7372 KB |
Output is correct |