#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define pb push_back
#define vl vector<ll>
#define fi first
#define se second
#define in insert
#define all(v) v.begin(), v.end()
#define bpc(x) __builtin_popcount(x)
#define endl "\n"
using namespace std;
const int sz = 3e5 + 5; /// mind the sz
const ll inf = 1e18;
// using namespace __gnu_pbds;
// tree <ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> rbt;
ll n, m, k, dp[sz][33], a[sz];
vl e[sz];
ll recursiondpbetch(ll node, ll mask){
mask |= (1 << a[node]);
if(dp[node][mask] != -1){return dp[node][mask];}
ll ans = 0;
if(bpc(mask) > 1){ans++;}
for(auto edge: e[node]){
if(!(mask & (1 << a[edge]))){
ans += recursiondpbetch(edge, mask);
}
}
return dp[node][mask] = ans;
}
void solve(){
ll i, j, u, v, res = 0;
cin >> n >> m >> k;
for(i = 1; i <= n; i++){
cin >> a[i];
}
for(i = 1; i <= m; i++){
cin >> u >> v;
e[u].pb(v);
e[v].pb(u);
}
memset(dp, -1, sizeof(dp));
for(i = 1; i <= n; i++){
res += recursiondpbetch(i, 0);
}
cout << res << endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll t = 1;
// cin >> t;
while(t--){
solve();
}
}
/*
*/
Compilation message
paths.cpp: In function 'void solve()':
paths.cpp:36:11: warning: unused variable 'j' [-Wunused-variable]
36 | ll i, j, u, v, res = 0;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
87128 KB |
Output is correct |
2 |
Correct |
12 ms |
87132 KB |
Output is correct |
3 |
Correct |
13 ms |
87132 KB |
Output is correct |
4 |
Correct |
12 ms |
87264 KB |
Output is correct |
5 |
Correct |
12 ms |
87132 KB |
Output is correct |
6 |
Correct |
12 ms |
87332 KB |
Output is correct |
7 |
Correct |
12 ms |
87128 KB |
Output is correct |
8 |
Correct |
12 ms |
87288 KB |
Output is correct |
9 |
Correct |
14 ms |
87300 KB |
Output is correct |
10 |
Correct |
13 ms |
87132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
70 ms |
96640 KB |
Output is correct |
2 |
Correct |
57 ms |
96340 KB |
Output is correct |
3 |
Correct |
227 ms |
102108 KB |
Output is correct |
4 |
Correct |
90 ms |
98736 KB |
Output is correct |
5 |
Correct |
74 ms |
98644 KB |
Output is correct |
6 |
Correct |
163 ms |
100292 KB |
Output is correct |
7 |
Correct |
242 ms |
102228 KB |
Output is correct |
8 |
Correct |
222 ms |
102880 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
87128 KB |
Output is correct |
2 |
Correct |
12 ms |
87132 KB |
Output is correct |
3 |
Correct |
13 ms |
87132 KB |
Output is correct |
4 |
Correct |
12 ms |
87264 KB |
Output is correct |
5 |
Correct |
12 ms |
87132 KB |
Output is correct |
6 |
Correct |
12 ms |
87332 KB |
Output is correct |
7 |
Correct |
12 ms |
87128 KB |
Output is correct |
8 |
Correct |
12 ms |
87288 KB |
Output is correct |
9 |
Correct |
14 ms |
87300 KB |
Output is correct |
10 |
Correct |
13 ms |
87132 KB |
Output is correct |
11 |
Correct |
70 ms |
96640 KB |
Output is correct |
12 |
Correct |
57 ms |
96340 KB |
Output is correct |
13 |
Correct |
227 ms |
102108 KB |
Output is correct |
14 |
Correct |
90 ms |
98736 KB |
Output is correct |
15 |
Correct |
74 ms |
98644 KB |
Output is correct |
16 |
Correct |
163 ms |
100292 KB |
Output is correct |
17 |
Correct |
242 ms |
102228 KB |
Output is correct |
18 |
Correct |
222 ms |
102880 KB |
Output is correct |
19 |
Correct |
67 ms |
97352 KB |
Output is correct |
20 |
Correct |
56 ms |
96700 KB |
Output is correct |
21 |
Correct |
259 ms |
102344 KB |
Output is correct |
22 |
Correct |
84 ms |
98684 KB |
Output is correct |
23 |
Correct |
80 ms |
98644 KB |
Output is correct |
24 |
Correct |
165 ms |
100044 KB |
Output is correct |
25 |
Correct |
265 ms |
102308 KB |
Output is correct |
26 |
Correct |
223 ms |
102736 KB |
Output is correct |
27 |
Correct |
71 ms |
96596 KB |
Output is correct |
28 |
Correct |
102 ms |
98896 KB |
Output is correct |
29 |
Correct |
329 ms |
102228 KB |
Output is correct |
30 |
Correct |
219 ms |
100032 KB |
Output is correct |
31 |
Correct |
243 ms |
100548 KB |
Output is correct |
32 |
Correct |
303 ms |
102308 KB |
Output is correct |
33 |
Correct |
12 ms |
87132 KB |
Output is correct |
34 |
Correct |
12 ms |
87132 KB |
Output is correct |
35 |
Correct |
12 ms |
87148 KB |
Output is correct |
36 |
Correct |
12 ms |
87388 KB |
Output is correct |
37 |
Correct |
12 ms |
87132 KB |
Output is correct |
38 |
Correct |
12 ms |
87332 KB |
Output is correct |
39 |
Correct |
13 ms |
87132 KB |
Output is correct |
40 |
Correct |
12 ms |
87128 KB |
Output is correct |
41 |
Correct |
12 ms |
87132 KB |
Output is correct |
42 |
Correct |
12 ms |
87308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
87132 KB |
Output is correct |
2 |
Correct |
41 ms |
90456 KB |
Output is correct |
3 |
Correct |
27 ms |
90240 KB |
Output is correct |
4 |
Correct |
60 ms |
92056 KB |
Output is correct |
5 |
Correct |
53 ms |
92616 KB |
Output is correct |
6 |
Correct |
96 ms |
91988 KB |
Output is correct |
7 |
Correct |
33 ms |
90196 KB |
Output is correct |
8 |
Correct |
71 ms |
92036 KB |
Output is correct |
9 |
Correct |
58 ms |
92612 KB |
Output is correct |
10 |
Correct |
69 ms |
92356 KB |
Output is correct |
11 |
Correct |
69 ms |
91080 KB |
Output is correct |
12 |
Correct |
63 ms |
91792 KB |
Output is correct |
13 |
Correct |
76 ms |
91212 KB |
Output is correct |
14 |
Correct |
80 ms |
91996 KB |
Output is correct |
15 |
Correct |
77 ms |
92248 KB |
Output is correct |
16 |
Correct |
12 ms |
87284 KB |
Output is correct |
17 |
Correct |
12 ms |
87132 KB |
Output is correct |
18 |
Correct |
12 ms |
87356 KB |
Output is correct |
19 |
Correct |
13 ms |
87240 KB |
Output is correct |
20 |
Correct |
13 ms |
87644 KB |
Output is correct |
21 |
Correct |
12 ms |
87132 KB |
Output is correct |
22 |
Correct |
13 ms |
87200 KB |
Output is correct |
23 |
Correct |
13 ms |
87268 KB |
Output is correct |
24 |
Correct |
12 ms |
87132 KB |
Output is correct |
25 |
Correct |
12 ms |
87132 KB |
Output is correct |