#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define debug(x) cout << #x << "= " << x << ", "
#define ll long long
#define fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define SZ(x) (int) x.size()
#define wall cout << endl;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define int long long
const int maxn = 3e5 + 10 , maxk = 5;
int n , m , k , ar[maxn] , dp[maxn][(1 << maxk)];
vector <int> adj[maxn];
int32_t main()
{
fast;
cin >> n >> m >> k;
for(int i = 1 ; i <= n ; i++)
{
cin >> ar[i];
ar[i]--;
dp[i][(1 << ar[i])] = 1;
}
for(int i = 0 ; i < m ; i++)
{
int v , u; cin >> v >> u;
adj[v].pb(u);
adj[u].pb(v);
}
int ans = 0;
for(int mask = 3 ; mask < (1 << k) ; mask++)
{
if(__builtin_popcount(mask) == 1) continue;
for(int i = 1 ; i <= n ; i++) if((mask >> ar[i]) & 1)
{
int m2 = mask ^ (1 << ar[i]);
for(auto u : adj[i])
dp[i][mask] += dp[u][m2];
ans += dp[i][mask];
}
}
cout << ans << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7380 KB |
Output is correct |
2 |
Correct |
4 ms |
7380 KB |
Output is correct |
3 |
Correct |
4 ms |
7380 KB |
Output is correct |
4 |
Correct |
4 ms |
7380 KB |
Output is correct |
5 |
Correct |
4 ms |
7384 KB |
Output is correct |
6 |
Correct |
4 ms |
7380 KB |
Output is correct |
7 |
Correct |
4 ms |
7380 KB |
Output is correct |
8 |
Correct |
4 ms |
7336 KB |
Output is correct |
9 |
Correct |
4 ms |
7380 KB |
Output is correct |
10 |
Correct |
5 ms |
7508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
62 ms |
18560 KB |
Output is correct |
2 |
Correct |
49 ms |
16936 KB |
Output is correct |
3 |
Correct |
258 ms |
99848 KB |
Output is correct |
4 |
Correct |
90 ms |
26524 KB |
Output is correct |
5 |
Correct |
83 ms |
26556 KB |
Output is correct |
6 |
Correct |
172 ms |
71936 KB |
Output is correct |
7 |
Correct |
236 ms |
99848 KB |
Output is correct |
8 |
Correct |
284 ms |
100312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7380 KB |
Output is correct |
2 |
Correct |
4 ms |
7380 KB |
Output is correct |
3 |
Correct |
4 ms |
7380 KB |
Output is correct |
4 |
Correct |
4 ms |
7380 KB |
Output is correct |
5 |
Correct |
4 ms |
7384 KB |
Output is correct |
6 |
Correct |
4 ms |
7380 KB |
Output is correct |
7 |
Correct |
4 ms |
7380 KB |
Output is correct |
8 |
Correct |
4 ms |
7336 KB |
Output is correct |
9 |
Correct |
4 ms |
7380 KB |
Output is correct |
10 |
Correct |
5 ms |
7508 KB |
Output is correct |
11 |
Correct |
62 ms |
18560 KB |
Output is correct |
12 |
Correct |
49 ms |
16936 KB |
Output is correct |
13 |
Correct |
258 ms |
99848 KB |
Output is correct |
14 |
Correct |
90 ms |
26524 KB |
Output is correct |
15 |
Correct |
83 ms |
26556 KB |
Output is correct |
16 |
Correct |
172 ms |
71936 KB |
Output is correct |
17 |
Correct |
236 ms |
99848 KB |
Output is correct |
18 |
Correct |
284 ms |
100312 KB |
Output is correct |
19 |
Correct |
62 ms |
18636 KB |
Output is correct |
20 |
Correct |
48 ms |
16984 KB |
Output is correct |
21 |
Correct |
258 ms |
99856 KB |
Output is correct |
22 |
Correct |
100 ms |
26592 KB |
Output is correct |
23 |
Correct |
94 ms |
26616 KB |
Output is correct |
24 |
Correct |
166 ms |
72084 KB |
Output is correct |
25 |
Correct |
244 ms |
99756 KB |
Output is correct |
26 |
Correct |
248 ms |
100472 KB |
Output is correct |
27 |
Correct |
52 ms |
16936 KB |
Output is correct |
28 |
Correct |
77 ms |
20824 KB |
Output is correct |
29 |
Correct |
329 ms |
99868 KB |
Output is correct |
30 |
Correct |
227 ms |
58880 KB |
Output is correct |
31 |
Correct |
223 ms |
58936 KB |
Output is correct |
32 |
Correct |
373 ms |
99836 KB |
Output is correct |
33 |
Correct |
4 ms |
7388 KB |
Output is correct |
34 |
Correct |
4 ms |
7380 KB |
Output is correct |
35 |
Correct |
4 ms |
7388 KB |
Output is correct |
36 |
Correct |
4 ms |
7384 KB |
Output is correct |
37 |
Correct |
4 ms |
7380 KB |
Output is correct |
38 |
Correct |
4 ms |
7380 KB |
Output is correct |
39 |
Correct |
4 ms |
7380 KB |
Output is correct |
40 |
Correct |
4 ms |
7380 KB |
Output is correct |
41 |
Correct |
4 ms |
7388 KB |
Output is correct |
42 |
Correct |
4 ms |
7384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7380 KB |
Output is correct |
2 |
Correct |
21 ms |
10348 KB |
Output is correct |
3 |
Correct |
19 ms |
10472 KB |
Output is correct |
4 |
Correct |
69 ms |
38064 KB |
Output is correct |
5 |
Correct |
53 ms |
38508 KB |
Output is correct |
6 |
Correct |
126 ms |
37980 KB |
Output is correct |
7 |
Correct |
22 ms |
10448 KB |
Output is correct |
8 |
Correct |
87 ms |
37964 KB |
Output is correct |
9 |
Correct |
63 ms |
38428 KB |
Output is correct |
10 |
Correct |
78 ms |
38648 KB |
Output is correct |
11 |
Correct |
71 ms |
24016 KB |
Output is correct |
12 |
Correct |
76 ms |
31156 KB |
Output is correct |
13 |
Correct |
70 ms |
24388 KB |
Output is correct |
14 |
Correct |
120 ms |
38124 KB |
Output is correct |
15 |
Correct |
128 ms |
38056 KB |
Output is correct |
16 |
Correct |
4 ms |
7380 KB |
Output is correct |
17 |
Correct |
4 ms |
7380 KB |
Output is correct |
18 |
Correct |
4 ms |
7380 KB |
Output is correct |
19 |
Correct |
4 ms |
7380 KB |
Output is correct |
20 |
Correct |
4 ms |
7380 KB |
Output is correct |
21 |
Correct |
5 ms |
7380 KB |
Output is correct |
22 |
Correct |
4 ms |
7380 KB |
Output is correct |
23 |
Correct |
5 ms |
7380 KB |
Output is correct |
24 |
Correct |
4 ms |
7380 KB |
Output is correct |
25 |
Correct |
4 ms |
7384 KB |
Output is correct |