#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vt vector
#define ar array
void solve(){
int n, m, k;
cin >> n >> m >> k;
int colors[n];
for(int i = 0; i < n; i++){
cin >> colors[i];
colors[i]--;
if (colors[i] == 0) colors[i] = 1;
else if (colors[i] == 1) colors[i] = 2;
else if (colors[i] == 2) colors[i] = 4;
else if (colors[i] == 3) colors[i] = 8;
else if (colors[i] == 4) colors[i] = 16;
}
// map<int, vt<int>> lines;
vt<pair<int, int>> onlyLines;
for(int i = 0; i < m; i++){
int a, b;
cin >> a >> b;
a--; b--;
// if (lines.find(a) == lines.end()) lines[a] = {};
// if (lines.find(b) == lines.end()) lines[b] = {};
// lines[a].push_back(b);
// lines[b].push_back(a);
onlyLines.push_back({a, b});
}
map<int, map<int, int>> amount;
amount[0] = {};
for(int j = 0; j < 1<<k; j++){
amount[0][j] = 0;
}
for(int i = 1; i < n; i++) amount[i] = amount[0];
for(int i = 0; i < n; i++){
amount[i][colors[i]] = 1;
}
ll res = 0;
for(int i = 2; i <= k; i++){
vt<int> nums = {};
for(int j = 0; j < 1<<k; j++){
if (__builtin_popcount(j) == i) nums.push_back(j);
}
for (pair<int, int> line : onlyLines){
for(int j : nums){
if (!(j & colors[line.first]) || !(j & colors[line.second])) continue;
ll mykk = amount[line.second][j - colors[line.first]];
amount[line.first][j] += mykk;
res += mykk;
mykk = amount[line.first][j - colors[line.second]];
amount[line.second][j] += mykk;
res += mykk;
}
}
}
cout << res << endl;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int testcases = 1;
// cin >> testcases;
while(testcases--){
solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
432 ms |
5060 KB |
Output is correct |
2 |
Correct |
268 ms |
4480 KB |
Output is correct |
3 |
Correct |
1967 ms |
144780 KB |
Output is correct |
4 |
Correct |
343 ms |
11232 KB |
Output is correct |
5 |
Correct |
60 ms |
8296 KB |
Output is correct |
6 |
Correct |
1259 ms |
97372 KB |
Output is correct |
7 |
Correct |
1888 ms |
144752 KB |
Output is correct |
8 |
Correct |
1871 ms |
144824 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
432 ms |
5060 KB |
Output is correct |
12 |
Correct |
268 ms |
4480 KB |
Output is correct |
13 |
Correct |
1967 ms |
144780 KB |
Output is correct |
14 |
Correct |
343 ms |
11232 KB |
Output is correct |
15 |
Correct |
60 ms |
8296 KB |
Output is correct |
16 |
Correct |
1259 ms |
97372 KB |
Output is correct |
17 |
Correct |
1888 ms |
144752 KB |
Output is correct |
18 |
Correct |
1871 ms |
144824 KB |
Output is correct |
19 |
Correct |
378 ms |
5028 KB |
Output is correct |
20 |
Correct |
248 ms |
4492 KB |
Output is correct |
21 |
Correct |
1830 ms |
144868 KB |
Output is correct |
22 |
Correct |
332 ms |
11228 KB |
Output is correct |
23 |
Correct |
59 ms |
8352 KB |
Output is correct |
24 |
Correct |
1215 ms |
97384 KB |
Output is correct |
25 |
Correct |
1887 ms |
144700 KB |
Output is correct |
26 |
Correct |
1905 ms |
144752 KB |
Output is correct |
27 |
Correct |
540 ms |
4476 KB |
Output is correct |
28 |
Correct |
959 ms |
9528 KB |
Output is correct |
29 |
Execution timed out |
3081 ms |
257560 KB |
Time limit exceeded |
30 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
315 ms |
1888 KB |
Output is correct |
3 |
Correct |
75 ms |
1492 KB |
Output is correct |
4 |
Correct |
462 ms |
48448 KB |
Output is correct |
5 |
Correct |
337 ms |
48452 KB |
Output is correct |
6 |
Correct |
1463 ms |
161232 KB |
Output is correct |
7 |
Correct |
152 ms |
1504 KB |
Output is correct |
8 |
Correct |
805 ms |
86036 KB |
Output is correct |
9 |
Correct |
563 ms |
86020 KB |
Output is correct |
10 |
Correct |
638 ms |
86028 KB |
Output is correct |
11 |
Correct |
866 ms |
81052 KB |
Output is correct |
12 |
Correct |
875 ms |
121156 KB |
Output is correct |
13 |
Correct |
870 ms |
81100 KB |
Output is correct |
14 |
Correct |
1439 ms |
161180 KB |
Output is correct |
15 |
Correct |
1450 ms |
161140 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
244 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
0 ms |
212 KB |
Output is correct |