# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
510027 |
2022-01-14T14:18:51 Z |
haxorman |
Paths (BOI18_paths) |
C++14 |
|
476 ms |
208456 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mxN = 3e5 + 7;
const int mxK = 39;
int n, m, k, color[mxN], dp[mxN][mxK][2];
vector<int> graph[mxN];
int dfs(int u, int mask, bool sz) {
if (dp[u][mask][sz]) {
return dp[u][mask][sz];
}
if (sz) {
dp[u][mask][sz] = 1;
}
for (auto v : graph[u]) {
if (!(mask & (1 << color[v]))) {
dp[u][mask][sz] += dfs(v, mask | (1 << color[v]), 1);
}
}
return dp[u][mask][sz];
}
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m >> k;
for (int u = 1; u <= n; ++u) {
cin >> color[u];
color[u]--;
}
for (int i = 0; i < m; ++i) {
int u, v;
cin >> u >> v;
graph[u].push_back(v);
graph[v].push_back(u);
}
int ans = 0;
for (int i = 1; i <= n; ++i) {
ans += dfs(i, 1 << color[i], 0);
}
cout << ans << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7372 KB |
Output is correct |
2 |
Correct |
4 ms |
7368 KB |
Output is correct |
3 |
Correct |
4 ms |
7364 KB |
Output is correct |
4 |
Correct |
3 ms |
7368 KB |
Output is correct |
5 |
Correct |
4 ms |
7372 KB |
Output is correct |
6 |
Correct |
4 ms |
7372 KB |
Output is correct |
7 |
Correct |
4 ms |
7372 KB |
Output is correct |
8 |
Correct |
4 ms |
7376 KB |
Output is correct |
9 |
Correct |
5 ms |
7372 KB |
Output is correct |
10 |
Correct |
3 ms |
7372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
74 ms |
17564 KB |
Output is correct |
2 |
Correct |
61 ms |
17224 KB |
Output is correct |
3 |
Correct |
430 ms |
207896 KB |
Output is correct |
4 |
Correct |
106 ms |
37380 KB |
Output is correct |
5 |
Correct |
106 ms |
19108 KB |
Output is correct |
6 |
Correct |
279 ms |
144096 KB |
Output is correct |
7 |
Correct |
381 ms |
207792 KB |
Output is correct |
8 |
Correct |
391 ms |
208456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7372 KB |
Output is correct |
2 |
Correct |
4 ms |
7368 KB |
Output is correct |
3 |
Correct |
4 ms |
7364 KB |
Output is correct |
4 |
Correct |
3 ms |
7368 KB |
Output is correct |
5 |
Correct |
4 ms |
7372 KB |
Output is correct |
6 |
Correct |
4 ms |
7372 KB |
Output is correct |
7 |
Correct |
4 ms |
7372 KB |
Output is correct |
8 |
Correct |
4 ms |
7376 KB |
Output is correct |
9 |
Correct |
5 ms |
7372 KB |
Output is correct |
10 |
Correct |
3 ms |
7372 KB |
Output is correct |
11 |
Correct |
74 ms |
17564 KB |
Output is correct |
12 |
Correct |
61 ms |
17224 KB |
Output is correct |
13 |
Correct |
430 ms |
207896 KB |
Output is correct |
14 |
Correct |
106 ms |
37380 KB |
Output is correct |
15 |
Correct |
106 ms |
19108 KB |
Output is correct |
16 |
Correct |
279 ms |
144096 KB |
Output is correct |
17 |
Correct |
381 ms |
207792 KB |
Output is correct |
18 |
Correct |
391 ms |
208456 KB |
Output is correct |
19 |
Correct |
85 ms |
20472 KB |
Output is correct |
20 |
Correct |
67 ms |
17324 KB |
Output is correct |
21 |
Correct |
399 ms |
207856 KB |
Output is correct |
22 |
Correct |
120 ms |
37312 KB |
Output is correct |
23 |
Correct |
86 ms |
19120 KB |
Output is correct |
24 |
Correct |
278 ms |
143976 KB |
Output is correct |
25 |
Correct |
377 ms |
207780 KB |
Output is correct |
26 |
Correct |
364 ms |
208304 KB |
Output is correct |
27 |
Correct |
86 ms |
17224 KB |
Output is correct |
28 |
Correct |
117 ms |
23776 KB |
Output is correct |
29 |
Correct |
456 ms |
207876 KB |
Output is correct |
30 |
Correct |
336 ms |
112880 KB |
Output is correct |
31 |
Correct |
386 ms |
112900 KB |
Output is correct |
32 |
Correct |
476 ms |
207972 KB |
Output is correct |
33 |
Correct |
4 ms |
7372 KB |
Output is correct |
34 |
Correct |
4 ms |
7368 KB |
Output is correct |
35 |
Correct |
4 ms |
7372 KB |
Output is correct |
36 |
Correct |
4 ms |
7372 KB |
Output is correct |
37 |
Correct |
3 ms |
7364 KB |
Output is correct |
38 |
Correct |
4 ms |
7376 KB |
Output is correct |
39 |
Correct |
3 ms |
7372 KB |
Output is correct |
40 |
Correct |
4 ms |
7372 KB |
Output is correct |
41 |
Correct |
5 ms |
7372 KB |
Output is correct |
42 |
Correct |
3 ms |
7372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
7372 KB |
Output is correct |
2 |
Correct |
43 ms |
9804 KB |
Output is correct |
3 |
Correct |
23 ms |
10592 KB |
Output is correct |
4 |
Correct |
116 ms |
73944 KB |
Output is correct |
5 |
Correct |
78 ms |
74332 KB |
Output is correct |
6 |
Correct |
123 ms |
74040 KB |
Output is correct |
7 |
Correct |
38 ms |
10548 KB |
Output is correct |
8 |
Correct |
108 ms |
73944 KB |
Output is correct |
9 |
Correct |
116 ms |
74388 KB |
Output is correct |
10 |
Correct |
119 ms |
74164 KB |
Output is correct |
11 |
Correct |
145 ms |
42012 KB |
Output is correct |
12 |
Correct |
99 ms |
58116 KB |
Output is correct |
13 |
Correct |
107 ms |
42172 KB |
Output is correct |
14 |
Correct |
202 ms |
74052 KB |
Output is correct |
15 |
Correct |
131 ms |
74144 KB |
Output is correct |
16 |
Correct |
7 ms |
7344 KB |
Output is correct |
17 |
Correct |
4 ms |
7372 KB |
Output is correct |
18 |
Correct |
4 ms |
7372 KB |
Output is correct |
19 |
Correct |
4 ms |
7372 KB |
Output is correct |
20 |
Correct |
4 ms |
7372 KB |
Output is correct |
21 |
Correct |
4 ms |
7368 KB |
Output is correct |
22 |
Correct |
4 ms |
7372 KB |
Output is correct |
23 |
Correct |
5 ms |
7348 KB |
Output is correct |
24 |
Correct |
5 ms |
7372 KB |
Output is correct |
25 |
Correct |
4 ms |
7364 KB |
Output is correct |