# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
130223 |
2019-07-14T10:06:04 Z |
mechfrog88 |
Paths (BOI18_paths) |
C++14 |
|
574 ms |
62484 KB |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long ll;
typedef long double ld;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n,m,k;
cin >> n >> m >> k;
vector <ll> color(n+1);
vector <vector<ll>> graph(n+1);
for (int z=1;z<=n;z++){
cin >> color[z];
color[z]--;
}
for (int z=0;z<m;z++){
ll a,b;
cin >> a >> b;
graph[a].push_back(b);
graph[b].push_back(a);
}
ll dp[n+1][1 << k] = {0};
for (int z=1;z<=n;z++){
dp[z][1 << color[z]] = 1;
}
for (int z=1;z<(1<<k);z++){
for (int x=1;x<=n;x++){
if (dp[x][z] < 1) continue;
for (int q=0;q<graph[x].size();q++){
if (graph[x][q] == x) continue;
ll v = graph[x][q];
if (z & (1 << color[v])) continue;
dp[v][z | (1 << color[v])] += dp[x][z];
}
}
}
ll count = 0;
for (int z=1;z<=(1<<k);z++){
if (__builtin_popcount(z) == 1) continue;
for (int x=1;x<=n;x++){
count += dp[x][z];
}
}
cout << count << endl;
}
Compilation message
paths.cpp: In function 'int main()':
paths.cpp:40:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int q=0;q<graph[x].size();q++){
~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
248 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
108 ms |
10800 KB |
Output is correct |
2 |
Correct |
83 ms |
9720 KB |
Output is correct |
3 |
Correct |
412 ms |
43512 KB |
Output is correct |
4 |
Correct |
142 ms |
13688 KB |
Output is correct |
5 |
Correct |
130 ms |
13180 KB |
Output is correct |
6 |
Correct |
350 ms |
32252 KB |
Output is correct |
7 |
Correct |
412 ms |
43512 KB |
Output is correct |
8 |
Correct |
415 ms |
44152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
248 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
108 ms |
10800 KB |
Output is correct |
12 |
Correct |
83 ms |
9720 KB |
Output is correct |
13 |
Correct |
412 ms |
43512 KB |
Output is correct |
14 |
Correct |
142 ms |
13688 KB |
Output is correct |
15 |
Correct |
130 ms |
13180 KB |
Output is correct |
16 |
Correct |
350 ms |
32252 KB |
Output is correct |
17 |
Correct |
412 ms |
43512 KB |
Output is correct |
18 |
Correct |
415 ms |
44152 KB |
Output is correct |
19 |
Correct |
108 ms |
10824 KB |
Output is correct |
20 |
Correct |
84 ms |
9720 KB |
Output is correct |
21 |
Correct |
417 ms |
43688 KB |
Output is correct |
22 |
Correct |
164 ms |
13716 KB |
Output is correct |
23 |
Correct |
146 ms |
13320 KB |
Output is correct |
24 |
Correct |
292 ms |
32104 KB |
Output is correct |
25 |
Correct |
411 ms |
43772 KB |
Output is correct |
26 |
Correct |
410 ms |
44024 KB |
Output is correct |
27 |
Correct |
100 ms |
9720 KB |
Output is correct |
28 |
Correct |
156 ms |
13176 KB |
Output is correct |
29 |
Correct |
566 ms |
62384 KB |
Output is correct |
30 |
Correct |
372 ms |
36584 KB |
Output is correct |
31 |
Correct |
391 ms |
36588 KB |
Output is correct |
32 |
Correct |
574 ms |
62484 KB |
Output is correct |
33 |
Correct |
2 ms |
376 KB |
Output is correct |
34 |
Correct |
2 ms |
376 KB |
Output is correct |
35 |
Correct |
2 ms |
376 KB |
Output is correct |
36 |
Correct |
2 ms |
376 KB |
Output is correct |
37 |
Correct |
2 ms |
376 KB |
Output is correct |
38 |
Correct |
2 ms |
376 KB |
Output is correct |
39 |
Correct |
2 ms |
272 KB |
Output is correct |
40 |
Correct |
2 ms |
376 KB |
Output is correct |
41 |
Correct |
2 ms |
376 KB |
Output is correct |
42 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
46 ms |
3352 KB |
Output is correct |
3 |
Correct |
29 ms |
3192 KB |
Output is correct |
4 |
Correct |
101 ms |
14584 KB |
Output is correct |
5 |
Correct |
75 ms |
14956 KB |
Output is correct |
6 |
Correct |
205 ms |
33572 KB |
Output is correct |
7 |
Correct |
34 ms |
3192 KB |
Output is correct |
8 |
Correct |
154 ms |
20856 KB |
Output is correct |
9 |
Correct |
96 ms |
21228 KB |
Output is correct |
10 |
Correct |
112 ms |
21100 KB |
Output is correct |
11 |
Correct |
106 ms |
18160 KB |
Output is correct |
12 |
Correct |
109 ms |
26060 KB |
Output is correct |
13 |
Correct |
102 ms |
18280 KB |
Output is correct |
14 |
Correct |
187 ms |
33328 KB |
Output is correct |
15 |
Correct |
171 ms |
33528 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |