// Only GOD
// Believe in yourself!
// -o Sango zadam be shishe
// -o Comeback bezan hamishe!
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
#define pb push_back
#define F first
#define S second
#define bit(x, y) (x >> y)&1
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define kill(x) return cout << x << '\n', void()
#define KILL(x) return cout << x << '\n', 0
#define mid ((l+r)>>1)
#define lid (id << 1)
#define rid (lid | 1)
#define int ll
const int N = 3e5+10;
const int INF = 1e9+10;
const int M = (1<<5);
int dp[M][N];// keshi friendly!
int n, m, k;
int color[N];
vector<int> G[N];
int32_t main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n >> m >> k;
for(int i = 0; i < n; i++){
cin >> color[i];
color[i]--;
}
for(int i = 0; i < m; i++){
int v, u;
cin >> v >> u;
--v, --u;
G[v].pb(u);
G[u].pb(v);
if(color[v]!=color[u]){
int msk = (1<<color[v])|(1<<color[u]);
dp[msk][v]++;
dp[msk][u]++;
}
}
for(int i=3; i <= k; i++){
for(int j = 0; j < n; j++){
for(int u : G[j]){
for(int mask = 0; mask < (1<<k); mask++){
if(__builtin_popcount(mask) != i)
continue;
if(!((1<<color[j])&mask))
continue;
dp[mask][j] += dp[mask^(1<<color[j])][u];
}
}
}
}
int ans = 0;
for(int i = 0; i < n; i++){
for(int mask = 0; mask < (1<<k); mask++){
ans += dp[mask][i];
}
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7380 KB |
Output is correct |
2 |
Correct |
4 ms |
7380 KB |
Output is correct |
3 |
Correct |
4 ms |
7380 KB |
Output is correct |
4 |
Correct |
4 ms |
7380 KB |
Output is correct |
5 |
Correct |
4 ms |
7380 KB |
Output is correct |
6 |
Correct |
4 ms |
7380 KB |
Output is correct |
7 |
Correct |
4 ms |
7380 KB |
Output is correct |
8 |
Correct |
4 ms |
7508 KB |
Output is correct |
9 |
Correct |
6 ms |
7380 KB |
Output is correct |
10 |
Correct |
5 ms |
7424 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
75 ms |
14796 KB |
Output is correct |
2 |
Correct |
64 ms |
14484 KB |
Output is correct |
3 |
Correct |
315 ms |
29764 KB |
Output is correct |
4 |
Correct |
97 ms |
15988 KB |
Output is correct |
5 |
Correct |
82 ms |
15644 KB |
Output is correct |
6 |
Correct |
200 ms |
24100 KB |
Output is correct |
7 |
Correct |
319 ms |
29612 KB |
Output is correct |
8 |
Correct |
322 ms |
30132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7380 KB |
Output is correct |
2 |
Correct |
4 ms |
7380 KB |
Output is correct |
3 |
Correct |
4 ms |
7380 KB |
Output is correct |
4 |
Correct |
4 ms |
7380 KB |
Output is correct |
5 |
Correct |
4 ms |
7380 KB |
Output is correct |
6 |
Correct |
4 ms |
7380 KB |
Output is correct |
7 |
Correct |
4 ms |
7380 KB |
Output is correct |
8 |
Correct |
4 ms |
7508 KB |
Output is correct |
9 |
Correct |
6 ms |
7380 KB |
Output is correct |
10 |
Correct |
5 ms |
7424 KB |
Output is correct |
11 |
Correct |
75 ms |
14796 KB |
Output is correct |
12 |
Correct |
64 ms |
14484 KB |
Output is correct |
13 |
Correct |
315 ms |
29764 KB |
Output is correct |
14 |
Correct |
97 ms |
15988 KB |
Output is correct |
15 |
Correct |
82 ms |
15644 KB |
Output is correct |
16 |
Correct |
200 ms |
24100 KB |
Output is correct |
17 |
Correct |
319 ms |
29612 KB |
Output is correct |
18 |
Correct |
322 ms |
30132 KB |
Output is correct |
19 |
Correct |
75 ms |
14780 KB |
Output is correct |
20 |
Correct |
60 ms |
14612 KB |
Output is correct |
21 |
Correct |
309 ms |
29748 KB |
Output is correct |
22 |
Correct |
120 ms |
15996 KB |
Output is correct |
23 |
Correct |
93 ms |
15628 KB |
Output is correct |
24 |
Correct |
208 ms |
24120 KB |
Output is correct |
25 |
Correct |
310 ms |
29764 KB |
Output is correct |
26 |
Correct |
303 ms |
30180 KB |
Output is correct |
27 |
Correct |
120 ms |
14672 KB |
Output is correct |
28 |
Correct |
140 ms |
16792 KB |
Output is correct |
29 |
Correct |
461 ms |
46080 KB |
Output is correct |
30 |
Correct |
333 ms |
30228 KB |
Output is correct |
31 |
Correct |
349 ms |
29248 KB |
Output is correct |
32 |
Correct |
464 ms |
46100 KB |
Output is correct |
33 |
Correct |
4 ms |
7380 KB |
Output is correct |
34 |
Correct |
6 ms |
7464 KB |
Output is correct |
35 |
Correct |
4 ms |
7380 KB |
Output is correct |
36 |
Correct |
4 ms |
7380 KB |
Output is correct |
37 |
Correct |
5 ms |
7380 KB |
Output is correct |
38 |
Correct |
3 ms |
7380 KB |
Output is correct |
39 |
Correct |
4 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7508 KB |
Output is correct |
2 |
Correct |
81 ms |
9804 KB |
Output is correct |
3 |
Correct |
25 ms |
9608 KB |
Output is correct |
4 |
Correct |
81 ms |
14804 KB |
Output is correct |
5 |
Correct |
66 ms |
14412 KB |
Output is correct |
6 |
Correct |
241 ms |
32112 KB |
Output is correct |
7 |
Correct |
40 ms |
9684 KB |
Output is correct |
8 |
Correct |
113 ms |
20384 KB |
Output is correct |
9 |
Correct |
71 ms |
18352 KB |
Output is correct |
10 |
Correct |
98 ms |
18148 KB |
Output is correct |
11 |
Correct |
130 ms |
20700 KB |
Output is correct |
12 |
Correct |
146 ms |
22992 KB |
Output is correct |
13 |
Correct |
133 ms |
19612 KB |
Output is correct |
14 |
Correct |
235 ms |
32156 KB |
Output is correct |
15 |
Correct |
268 ms |
32408 KB |
Output is correct |
16 |
Correct |
4 ms |
7380 KB |
Output is correct |
17 |
Correct |
3 ms |
7380 KB |
Output is correct |
18 |
Correct |
4 ms |
7380 KB |
Output is correct |
19 |
Correct |
3 ms |
7380 KB |
Output is correct |
20 |
Correct |
4 ms |
7380 KB |
Output is correct |
21 |
Correct |
3 ms |
7380 KB |
Output is correct |
22 |
Correct |
5 ms |
7380 KB |
Output is correct |
23 |
Correct |
4 ms |
7380 KB |
Output is correct |
24 |
Correct |
4 ms |
7380 KB |
Output is correct |
25 |
Correct |
4 ms |
7396 KB |
Output is correct |