# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
930397 |
2024-02-19T14:30:32 Z |
vjudge1 |
Paths (BOI18_paths) |
C++17 |
|
533 ms |
133228 KB |
#pragma GCC optimize("O3", "unroll-loops") // "Ofast"
#pragma GCC target("avx2", "bmi", "bmi2", "lzcnt", "popcnt")
#include <bits/stdc++.h>
#define int long long
#define vt vector
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define f first
#define s second
#define dbg(x) cerr << #x << " = " << x << '\n'
#define bit(x, i) ((x) >> (i) & 1)
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
const int N = 1e6 + 5, mod = 10056;
const ll inf = 1e18;
const ld eps = 1e-6;
ll add (ll a, ll b) {
a += b;
if (a < 0) a += mod;
if (a >= mod) a -= mod;
return a;
}
ll mul (ll a, ll b) {
a *= b;
if (a >= mod) a %= mod;
return a;
}
int n, m, k, a[N], dp[N][40];
vt<int> g[N];
void solve () {
cin >> n >> m >> k;
for (int i = 1; i <= n; i++) cin >> a[i], a[i]--, dp[i][1 << a[i]]++;
for (int i = 1; i <= m; i++) {
int x, y;
cin >> x >> y;
g[x].pb(y), g[y].pb(x);
}
int ans = 0;
for (int mask = 0; mask < (1 << k); mask++) {
for (int i = 1; i <= n; i++) {
for (int j: g[i]) {
if (bit(mask, a[j])) continue;
int nmask = mask ^ (1 << a[j]);
dp[j][nmask] += dp[i][mask];
}
}
}
for (int mask = 0; mask < (1 << k); mask++) {
if (__builtin_popcountll(mask) < 2) continue;
for (int i = 1; i <= n; i++) ans += dp[i][mask];
}
cout << ans;
cout << '\n';
}
bool testcases = 0;
signed main() {
cin.tie(0) -> sync_with_stdio(0);
int test = 1;
if (testcases) cin >> test;
for (int cs = 1; cs <= test; cs++) {
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
27228 KB |
Output is correct |
2 |
Correct |
9 ms |
27272 KB |
Output is correct |
3 |
Correct |
8 ms |
27228 KB |
Output is correct |
4 |
Correct |
8 ms |
27228 KB |
Output is correct |
5 |
Correct |
9 ms |
27228 KB |
Output is correct |
6 |
Correct |
8 ms |
27228 KB |
Output is correct |
7 |
Correct |
9 ms |
27224 KB |
Output is correct |
8 |
Correct |
9 ms |
27228 KB |
Output is correct |
9 |
Correct |
14 ms |
23896 KB |
Output is correct |
10 |
Correct |
8 ms |
27228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
36540 KB |
Output is correct |
2 |
Correct |
60 ms |
34444 KB |
Output is correct |
3 |
Correct |
353 ms |
132692 KB |
Output is correct |
4 |
Correct |
85 ms |
45568 KB |
Output is correct |
5 |
Correct |
88 ms |
45432 KB |
Output is correct |
6 |
Correct |
267 ms |
99300 KB |
Output is correct |
7 |
Correct |
363 ms |
132680 KB |
Output is correct |
8 |
Correct |
354 ms |
133200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
27228 KB |
Output is correct |
2 |
Correct |
9 ms |
27272 KB |
Output is correct |
3 |
Correct |
8 ms |
27228 KB |
Output is correct |
4 |
Correct |
8 ms |
27228 KB |
Output is correct |
5 |
Correct |
9 ms |
27228 KB |
Output is correct |
6 |
Correct |
8 ms |
27228 KB |
Output is correct |
7 |
Correct |
9 ms |
27224 KB |
Output is correct |
8 |
Correct |
9 ms |
27228 KB |
Output is correct |
9 |
Correct |
14 ms |
23896 KB |
Output is correct |
10 |
Correct |
8 ms |
27228 KB |
Output is correct |
11 |
Correct |
76 ms |
36540 KB |
Output is correct |
12 |
Correct |
60 ms |
34444 KB |
Output is correct |
13 |
Correct |
353 ms |
132692 KB |
Output is correct |
14 |
Correct |
85 ms |
45568 KB |
Output is correct |
15 |
Correct |
88 ms |
45432 KB |
Output is correct |
16 |
Correct |
267 ms |
99300 KB |
Output is correct |
17 |
Correct |
363 ms |
132680 KB |
Output is correct |
18 |
Correct |
354 ms |
133200 KB |
Output is correct |
19 |
Correct |
75 ms |
32664 KB |
Output is correct |
20 |
Correct |
60 ms |
34444 KB |
Output is correct |
21 |
Correct |
381 ms |
130644 KB |
Output is correct |
22 |
Correct |
113 ms |
45484 KB |
Output is correct |
23 |
Correct |
79 ms |
45688 KB |
Output is correct |
24 |
Correct |
211 ms |
99344 KB |
Output is correct |
25 |
Correct |
347 ms |
132512 KB |
Output is correct |
26 |
Correct |
363 ms |
133228 KB |
Output is correct |
27 |
Correct |
80 ms |
34384 KB |
Output is correct |
28 |
Correct |
102 ms |
38152 KB |
Output is correct |
29 |
Correct |
533 ms |
132620 KB |
Output is correct |
30 |
Correct |
338 ms |
83656 KB |
Output is correct |
31 |
Correct |
302 ms |
83904 KB |
Output is correct |
32 |
Correct |
505 ms |
132704 KB |
Output is correct |
33 |
Correct |
12 ms |
23900 KB |
Output is correct |
34 |
Correct |
12 ms |
23900 KB |
Output is correct |
35 |
Correct |
9 ms |
27284 KB |
Output is correct |
36 |
Correct |
10 ms |
23968 KB |
Output is correct |
37 |
Correct |
13 ms |
23916 KB |
Output is correct |
38 |
Correct |
8 ms |
23900 KB |
Output is correct |
39 |
Correct |
8 ms |
23900 KB |
Output is correct |
40 |
Correct |
8 ms |
27228 KB |
Output is correct |
41 |
Correct |
9 ms |
27384 KB |
Output is correct |
42 |
Correct |
9 ms |
27228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
27228 KB |
Output is correct |
2 |
Correct |
51 ms |
29476 KB |
Output is correct |
3 |
Correct |
27 ms |
29532 KB |
Output is correct |
4 |
Correct |
84 ms |
63644 KB |
Output is correct |
5 |
Correct |
61 ms |
63872 KB |
Output is correct |
6 |
Correct |
191 ms |
63648 KB |
Output is correct |
7 |
Correct |
32 ms |
29276 KB |
Output is correct |
8 |
Correct |
137 ms |
63624 KB |
Output is correct |
9 |
Correct |
75 ms |
63944 KB |
Output is correct |
10 |
Correct |
98 ms |
64048 KB |
Output is correct |
11 |
Correct |
95 ms |
46284 KB |
Output is correct |
12 |
Correct |
105 ms |
55488 KB |
Output is correct |
13 |
Correct |
94 ms |
46676 KB |
Output is correct |
14 |
Correct |
169 ms |
63644 KB |
Output is correct |
15 |
Correct |
197 ms |
63596 KB |
Output is correct |
16 |
Correct |
8 ms |
27224 KB |
Output is correct |
17 |
Correct |
8 ms |
27316 KB |
Output is correct |
18 |
Correct |
9 ms |
27228 KB |
Output is correct |
19 |
Correct |
8 ms |
27228 KB |
Output is correct |
20 |
Correct |
8 ms |
27272 KB |
Output is correct |
21 |
Correct |
8 ms |
27228 KB |
Output is correct |
22 |
Correct |
9 ms |
27228 KB |
Output is correct |
23 |
Correct |
8 ms |
27228 KB |
Output is correct |
24 |
Correct |
9 ms |
27312 KB |
Output is correct |
25 |
Correct |
8 ms |
27228 KB |
Output is correct |