# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
796243 |
2023-07-28T08:18:33 Z |
tch1cherin |
Paths (BOI18_paths) |
C++17 |
|
274 ms |
103044 KB |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 300005;
vector<int> G[MAX_N];
int A[MAX_N], cnt[MAX_N][5];
int64_t c[MAX_N][1 << 5];
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int N, M, K;
cin >> N >> M >> K;
for (int i = 0; i < N; i++) {
cin >> A[i];
A[i]--;
}
for (int i = 0; i < M; i++) {
int a, b;
cin >> a >> b;
a--, b--;
G[a].push_back(b);
G[b].push_back(a);
}
vector<int> pc(1 << K);
for (int i = 0; i < (1 << K); i++) {
pc[i] = __builtin_popcount(i);
}
for (int i = 0; i < N; i++) {
for (int j : G[i]) {
cnt[i][A[j]]++;
}
}
int64_t ans = 0;
vector<int64_t> len(5);
for (int i = 0; i < N; i++) {
c[i][0] = 1;
for (int j : G[i]) {
c[i][1 << A[j]]++;
for (int k = 0; k < K; k++) {
if (A[j] != k) {
c[i][(1 << A[j]) | (1 << k)] += cnt[j][k];
}
}
}
for (int msk1 = 0; msk1 < (1 << K); msk1++) {
if ((msk1 >> A[i]) & 1) {
continue;
}
for (int msk2 = 0; msk2 < (1 << K); msk2++) {
if (((msk2 >> A[i]) & 1) || (msk1 & msk2)) {
continue;
}
len[pc[msk1 | msk2]] += c[i][msk1] * c[i][msk2];
}
}
}
cout << len[1] / 2 + len[2] / 3 + len[3] / 2 + len[4] << "\n";
}
Compilation message
paths.cpp: In function 'int main()':
paths.cpp:33:11: warning: unused variable 'ans' [-Wunused-variable]
33 | int64_t ans = 0;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
7380 KB |
Output is correct |
2 |
Correct |
3 ms |
7380 KB |
Output is correct |
3 |
Correct |
4 ms |
7380 KB |
Output is correct |
4 |
Correct |
3 ms |
7376 KB |
Output is correct |
5 |
Correct |
4 ms |
7376 KB |
Output is correct |
6 |
Correct |
4 ms |
7308 KB |
Output is correct |
7 |
Correct |
3 ms |
7380 KB |
Output is correct |
8 |
Correct |
3 ms |
7380 KB |
Output is correct |
9 |
Correct |
4 ms |
7380 KB |
Output is correct |
10 |
Correct |
3 ms |
7380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
51 ms |
15188 KB |
Output is correct |
2 |
Correct |
42 ms |
13388 KB |
Output is correct |
3 |
Correct |
220 ms |
102360 KB |
Output is correct |
4 |
Correct |
70 ms |
23292 KB |
Output is correct |
5 |
Correct |
66 ms |
23380 KB |
Output is correct |
6 |
Correct |
161 ms |
73344 KB |
Output is correct |
7 |
Correct |
208 ms |
102332 KB |
Output is correct |
8 |
Correct |
213 ms |
102956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
7380 KB |
Output is correct |
2 |
Correct |
3 ms |
7380 KB |
Output is correct |
3 |
Correct |
4 ms |
7380 KB |
Output is correct |
4 |
Correct |
3 ms |
7376 KB |
Output is correct |
5 |
Correct |
4 ms |
7376 KB |
Output is correct |
6 |
Correct |
4 ms |
7308 KB |
Output is correct |
7 |
Correct |
3 ms |
7380 KB |
Output is correct |
8 |
Correct |
3 ms |
7380 KB |
Output is correct |
9 |
Correct |
4 ms |
7380 KB |
Output is correct |
10 |
Correct |
3 ms |
7380 KB |
Output is correct |
11 |
Correct |
51 ms |
15188 KB |
Output is correct |
12 |
Correct |
42 ms |
13388 KB |
Output is correct |
13 |
Correct |
220 ms |
102360 KB |
Output is correct |
14 |
Correct |
70 ms |
23292 KB |
Output is correct |
15 |
Correct |
66 ms |
23380 KB |
Output is correct |
16 |
Correct |
161 ms |
73344 KB |
Output is correct |
17 |
Correct |
208 ms |
102332 KB |
Output is correct |
18 |
Correct |
213 ms |
102956 KB |
Output is correct |
19 |
Correct |
55 ms |
15192 KB |
Output is correct |
20 |
Correct |
46 ms |
13420 KB |
Output is correct |
21 |
Correct |
212 ms |
102348 KB |
Output is correct |
22 |
Correct |
69 ms |
23332 KB |
Output is correct |
23 |
Correct |
65 ms |
23292 KB |
Output is correct |
24 |
Correct |
154 ms |
73340 KB |
Output is correct |
25 |
Correct |
221 ms |
102348 KB |
Output is correct |
26 |
Correct |
210 ms |
103044 KB |
Output is correct |
27 |
Correct |
45 ms |
13420 KB |
Output is correct |
28 |
Correct |
58 ms |
16724 KB |
Output is correct |
29 |
Correct |
271 ms |
102412 KB |
Output is correct |
30 |
Correct |
136 ms |
58260 KB |
Output is correct |
31 |
Correct |
134 ms |
58320 KB |
Output is correct |
32 |
Correct |
274 ms |
102384 KB |
Output is correct |
33 |
Correct |
3 ms |
7380 KB |
Output is correct |
34 |
Correct |
3 ms |
7380 KB |
Output is correct |
35 |
Correct |
3 ms |
7380 KB |
Output is correct |
36 |
Correct |
4 ms |
7380 KB |
Output is correct |
37 |
Correct |
3 ms |
7376 KB |
Output is correct |
38 |
Correct |
3 ms |
7376 KB |
Output is correct |
39 |
Correct |
3 ms |
7380 KB |
Output is correct |
40 |
Correct |
4 ms |
7380 KB |
Output is correct |
41 |
Correct |
4 ms |
7380 KB |
Output is correct |
42 |
Correct |
4 ms |
7380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7380 KB |
Output is correct |
2 |
Correct |
17 ms |
9300 KB |
Output is correct |
3 |
Correct |
24 ms |
9356 KB |
Output is correct |
4 |
Correct |
52 ms |
38868 KB |
Output is correct |
5 |
Correct |
50 ms |
39544 KB |
Output is correct |
6 |
Correct |
102 ms |
38860 KB |
Output is correct |
7 |
Correct |
16 ms |
9380 KB |
Output is correct |
8 |
Correct |
62 ms |
38832 KB |
Output is correct |
9 |
Correct |
54 ms |
39652 KB |
Output is correct |
10 |
Correct |
57 ms |
39436 KB |
Output is correct |
11 |
Correct |
57 ms |
23956 KB |
Output is correct |
12 |
Correct |
71 ms |
31952 KB |
Output is correct |
13 |
Correct |
69 ms |
24140 KB |
Output is correct |
14 |
Correct |
104 ms |
38788 KB |
Output is correct |
15 |
Correct |
134 ms |
38900 KB |
Output is correct |
16 |
Correct |
3 ms |
7380 KB |
Output is correct |
17 |
Correct |
3 ms |
7380 KB |
Output is correct |
18 |
Correct |
3 ms |
7380 KB |
Output is correct |
19 |
Correct |
3 ms |
7304 KB |
Output is correct |
20 |
Correct |
3 ms |
7380 KB |
Output is correct |
21 |
Correct |
3 ms |
7376 KB |
Output is correct |
22 |
Correct |
3 ms |
7380 KB |
Output is correct |
23 |
Correct |
3 ms |
7372 KB |
Output is correct |
24 |
Correct |
3 ms |
7380 KB |
Output is correct |
25 |
Correct |
3 ms |
7380 KB |
Output is correct |