//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("Ofast,unroll-loops,fast-math,O3")
#include<bits/stdc++.h>
using namespace std;
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(a) (int)a.size()
#define s second
#define f first
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
vector<pii> rid = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
vector<pii> dir = {{-1, -1}, {-1, 1}, {1, -1}, {1, 1}};
const int N = 2e3 + 1, mod = 1e9 + 7;
const ll inf = 1e9;
double eps = 1e-15;
bool flg = 0;
void slv() {
int n, m, k;
cin >> n >> m >> k;
vector<int> s[k + 1], c(n + 1);
for (int i = 1; i <= n; i++) {
cin >> c[i];
s[c[i]].push_back(i);
}
vector<int> g[n + 1][k + 1];
while (m--) {
int u, v;
cin >> u >> v;
g[u][c[v]].push_back(v);
g[v][c[u]].push_back(u);
}
ll dp[(1 << k)][n + 1];
for (int i = 0; i < (1 << k); i++) {
for (int j = 0; j <= n; j++)
dp[i][j] = 0;
}
ll ans = 0;
for (int msk = 1; msk < (1 << k); msk++) {
vector<int> h;
for (int i = 0; i < k; i++) {
if (msk >> i & 1)
h.push_back(i + 1);
}
if (sz(h) == 1) {
for (int v: s[h[0]])
dp[msk][v] = 1;
continue;
}
for (int i = 0; i < sz(h); i++) {
int mk = msk - (1 << (h[i] - 1));
for (int v: s[h[i]]) {
for (int j = 0; j < sz(h); j++) {
if (i == j) continue;
for (int to: g[v][h[j]]) {
dp[msk][v] += dp[mk][to];
}
}
ans += dp[msk][v];
}
}
}
cout << ans;
}
main() {
//freopen("rsq.in", "r", stdin);
//freopen("rsq.out", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
int tp = 1;
if (flg) cin >> tp;
while (tp--) {
slv();
}
}
//wenomechainsama
Compilation message
paths.cpp:79:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
79 | main() {
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
5504 KB |
Output is correct |
2 |
Correct |
33 ms |
3920 KB |
Output is correct |
3 |
Correct |
283 ms |
63556 KB |
Output is correct |
4 |
Correct |
75 ms |
8528 KB |
Output is correct |
5 |
Correct |
59 ms |
6736 KB |
Output is correct |
6 |
Correct |
185 ms |
44408 KB |
Output is correct |
7 |
Correct |
274 ms |
63296 KB |
Output is correct |
8 |
Correct |
307 ms |
64476 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
49 ms |
5504 KB |
Output is correct |
12 |
Correct |
33 ms |
3920 KB |
Output is correct |
13 |
Correct |
283 ms |
63556 KB |
Output is correct |
14 |
Correct |
75 ms |
8528 KB |
Output is correct |
15 |
Correct |
59 ms |
6736 KB |
Output is correct |
16 |
Correct |
185 ms |
44408 KB |
Output is correct |
17 |
Correct |
274 ms |
63296 KB |
Output is correct |
18 |
Correct |
307 ms |
64476 KB |
Output is correct |
19 |
Correct |
47 ms |
5456 KB |
Output is correct |
20 |
Correct |
34 ms |
3932 KB |
Output is correct |
21 |
Correct |
257 ms |
63460 KB |
Output is correct |
22 |
Correct |
77 ms |
8424 KB |
Output is correct |
23 |
Correct |
59 ms |
6736 KB |
Output is correct |
24 |
Correct |
171 ms |
44484 KB |
Output is correct |
25 |
Correct |
276 ms |
63564 KB |
Output is correct |
26 |
Correct |
314 ms |
64696 KB |
Output is correct |
27 |
Correct |
36 ms |
4180 KB |
Output is correct |
28 |
Correct |
57 ms |
9808 KB |
Output is correct |
29 |
Correct |
376 ms |
94880 KB |
Output is correct |
30 |
Correct |
282 ms |
52760 KB |
Output is correct |
31 |
Correct |
245 ms |
53792 KB |
Output is correct |
32 |
Correct |
407 ms |
94820 KB |
Output is correct |
33 |
Correct |
0 ms |
344 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
600 KB |
Output is correct |
37 |
Correct |
1 ms |
760 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
1 ms |
344 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
13 ms |
1896 KB |
Output is correct |
3 |
Correct |
13 ms |
2648 KB |
Output is correct |
4 |
Correct |
66 ms |
22628 KB |
Output is correct |
5 |
Correct |
44 ms |
22056 KB |
Output is correct |
6 |
Correct |
173 ms |
46944 KB |
Output is correct |
7 |
Correct |
13 ms |
2392 KB |
Output is correct |
8 |
Correct |
119 ms |
31836 KB |
Output is correct |
9 |
Correct |
63 ms |
30440 KB |
Output is correct |
10 |
Correct |
77 ms |
31412 KB |
Output is correct |
11 |
Correct |
63 ms |
24916 KB |
Output is correct |
12 |
Correct |
79 ms |
35096 KB |
Output is correct |
13 |
Correct |
62 ms |
25760 KB |
Output is correct |
14 |
Correct |
159 ms |
47000 KB |
Output is correct |
15 |
Correct |
162 ms |
47160 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |