#include <bits/stdc++.h>
#define ll long long
#define cll const ll
#define lp(a, b, c) for(ll a = b; a <= c; ++a)
#define lpd(a, b, c) for(ll a = b; a >= c; --a)
#define vec(a) vector<a>
#define pp(a, b) pair<a, b>
#define EACHCASE lpd(cs, read(), 1)
#define Fname "f"
using namespace std;
template <typename T> inline void Read(T &x){
x = 0; char c;
while(!isdigit(c = getchar()));
do
{
x = x * 10 + c - '0';
} while (isdigit(c = getchar()));
}
ll read(){
ll tmp;
cin >> tmp;
return tmp;
}
void giuncute(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
}
void OF(){
freopen(Fname".inp", "r", stdin);
freopen(Fname".out", "w", stdout);
}
cll mxn = 3e5 + 7, mxk = 5;
ll n, m, k, a[mxn], dp[mxn][1 << mxk] = {{0}}, ans = 0;
vec(ll) g[mxn], state[6];
inline ll cntbit(ll x){
if(!x) return 0;
return cntbit(x >> 1) + (x & 1);
}
int main(){
giuncute();
cin >> n >> m >> k;
lp(i, 1, n) a[i] = read() - 1, dp[i][1 << a[i]] = 1;
lp(i, 1, m){
ll u, v;
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
lp(i, 1, (1 << mxk) - 1) if(i < (1 << k)) state[cntbit(i)].push_back(i);
lp(i, 2, k){
lp(u, 1, n){
for(ll stt : state[i]){
if(stt & (1 << a[u]))
for(ll v : g[u])
dp[u][stt] += dp[v][stt ^ (1 << a[u])];
ans += dp[u][stt];
}
}
}
cout << ans;
}
Compilation message
paths.cpp: In function 'void OF()':
paths.cpp:33:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
33 | freopen(Fname".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
paths.cpp:34:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
34 | freopen(Fname".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
7372 KB |
Output is correct |
2 |
Correct |
6 ms |
7372 KB |
Output is correct |
3 |
Correct |
6 ms |
7312 KB |
Output is correct |
4 |
Correct |
5 ms |
7368 KB |
Output is correct |
5 |
Correct |
6 ms |
7372 KB |
Output is correct |
6 |
Correct |
5 ms |
7372 KB |
Output is correct |
7 |
Correct |
6 ms |
7368 KB |
Output is correct |
8 |
Correct |
5 ms |
7372 KB |
Output is correct |
9 |
Correct |
7 ms |
7372 KB |
Output is correct |
10 |
Correct |
6 ms |
7368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
89 ms |
18572 KB |
Output is correct |
2 |
Correct |
69 ms |
16916 KB |
Output is correct |
3 |
Correct |
405 ms |
99844 KB |
Output is correct |
4 |
Correct |
130 ms |
26564 KB |
Output is correct |
5 |
Correct |
118 ms |
26600 KB |
Output is correct |
6 |
Correct |
253 ms |
72000 KB |
Output is correct |
7 |
Correct |
377 ms |
99848 KB |
Output is correct |
8 |
Correct |
367 ms |
100396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
7372 KB |
Output is correct |
2 |
Correct |
6 ms |
7372 KB |
Output is correct |
3 |
Correct |
6 ms |
7312 KB |
Output is correct |
4 |
Correct |
5 ms |
7368 KB |
Output is correct |
5 |
Correct |
6 ms |
7372 KB |
Output is correct |
6 |
Correct |
5 ms |
7372 KB |
Output is correct |
7 |
Correct |
6 ms |
7368 KB |
Output is correct |
8 |
Correct |
5 ms |
7372 KB |
Output is correct |
9 |
Correct |
7 ms |
7372 KB |
Output is correct |
10 |
Correct |
6 ms |
7368 KB |
Output is correct |
11 |
Correct |
89 ms |
18572 KB |
Output is correct |
12 |
Correct |
69 ms |
16916 KB |
Output is correct |
13 |
Correct |
405 ms |
99844 KB |
Output is correct |
14 |
Correct |
130 ms |
26564 KB |
Output is correct |
15 |
Correct |
118 ms |
26600 KB |
Output is correct |
16 |
Correct |
253 ms |
72000 KB |
Output is correct |
17 |
Correct |
377 ms |
99848 KB |
Output is correct |
18 |
Correct |
367 ms |
100396 KB |
Output is correct |
19 |
Correct |
90 ms |
18668 KB |
Output is correct |
20 |
Correct |
70 ms |
16980 KB |
Output is correct |
21 |
Correct |
345 ms |
99776 KB |
Output is correct |
22 |
Correct |
145 ms |
26656 KB |
Output is correct |
23 |
Correct |
112 ms |
26516 KB |
Output is correct |
24 |
Correct |
254 ms |
71856 KB |
Output is correct |
25 |
Correct |
397 ms |
99960 KB |
Output is correct |
26 |
Correct |
370 ms |
100492 KB |
Output is correct |
27 |
Correct |
74 ms |
16948 KB |
Output is correct |
28 |
Correct |
102 ms |
20804 KB |
Output is correct |
29 |
Correct |
493 ms |
99868 KB |
Output is correct |
30 |
Correct |
301 ms |
58844 KB |
Output is correct |
31 |
Correct |
332 ms |
58852 KB |
Output is correct |
32 |
Correct |
461 ms |
99772 KB |
Output is correct |
33 |
Correct |
5 ms |
7372 KB |
Output is correct |
34 |
Correct |
5 ms |
7372 KB |
Output is correct |
35 |
Correct |
6 ms |
7372 KB |
Output is correct |
36 |
Correct |
5 ms |
7372 KB |
Output is correct |
37 |
Correct |
5 ms |
7384 KB |
Output is correct |
38 |
Correct |
5 ms |
7372 KB |
Output is correct |
39 |
Correct |
5 ms |
7372 KB |
Output is correct |
40 |
Correct |
5 ms |
7372 KB |
Output is correct |
41 |
Correct |
7 ms |
7352 KB |
Output is correct |
42 |
Correct |
5 ms |
7372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
7368 KB |
Output is correct |
2 |
Correct |
30 ms |
10316 KB |
Output is correct |
3 |
Correct |
26 ms |
10424 KB |
Output is correct |
4 |
Correct |
98 ms |
38052 KB |
Output is correct |
5 |
Correct |
68 ms |
38400 KB |
Output is correct |
6 |
Correct |
155 ms |
37944 KB |
Output is correct |
7 |
Correct |
29 ms |
10392 KB |
Output is correct |
8 |
Correct |
123 ms |
37956 KB |
Output is correct |
9 |
Correct |
81 ms |
38468 KB |
Output is correct |
10 |
Correct |
103 ms |
38688 KB |
Output is correct |
11 |
Correct |
91 ms |
23996 KB |
Output is correct |
12 |
Correct |
97 ms |
31068 KB |
Output is correct |
13 |
Correct |
95 ms |
24360 KB |
Output is correct |
14 |
Correct |
176 ms |
37976 KB |
Output is correct |
15 |
Correct |
189 ms |
38080 KB |
Output is correct |
16 |
Correct |
6 ms |
7372 KB |
Output is correct |
17 |
Correct |
5 ms |
7364 KB |
Output is correct |
18 |
Correct |
5 ms |
7372 KB |
Output is correct |
19 |
Correct |
5 ms |
7356 KB |
Output is correct |
20 |
Correct |
6 ms |
7368 KB |
Output is correct |
21 |
Correct |
6 ms |
7368 KB |
Output is correct |
22 |
Correct |
5 ms |
7372 KB |
Output is correct |
23 |
Correct |
6 ms |
7372 KB |
Output is correct |
24 |
Correct |
5 ms |
7372 KB |
Output is correct |
25 |
Correct |
6 ms |
7372 KB |
Output is correct |