# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
645484 |
2022-09-27T08:27:11 Z |
mychecksedad |
Paths (BOI18_paths) |
C++17 |
|
640 ms |
124132 KB |
/* Author : Mychecksdead */
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define PI 3.1415926535
#define pb push_back
#define setp() cout << setprecision(15)
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " is " << x << '\n';
const int N = 1e6+100, M = 1e5+10, F = 2147483646, K = 20;
int n, m, k, a[N];
ll ans = 0, dp[N][32];
vector<int> g[N];
vector<bool> vis(N);
void dfs(int v, int p, int d){
vis[v] = 1;
for(int u: g[v]){
for(int mask = 0; mask < (1<<k); ++mask){
if(__builtin_popcount(mask) == d){
if(!(mask&(1<<a[v]))) continue;
if(a[u] != a[v]){
dp[v][mask] += dp[u][mask ^ (1<<a[v])];
ans += dp[u][mask ^ (1<<a[v])];
}
}
}
if(vis[u]) continue;
dfs(u, v, d);
}
}
void solve(){
cin >> n >> m >> k;
for(int i = 1; i <= n; ++i) cin >> a[i];
for(int i = 1; i <= n; ++i){
--a[i];
for(int j = 0; j < (1<<k); ++j) dp[i][j] = 0;
dp[i][1<<a[i]]++;
}
for(int i = 0; i < m; ++i){
int u, v; cin >> u >> v;
g[u].pb(v);
g[v].pb(u);
}
for(int j = 2; j <= k; ++j){
vis.clear();
vis.resize(n+1);
for(int i = 1; i <= n; ++i) if(!vis[i]) dfs(i, 0, j);
}
cout << ans;
}
int main(){
cin.tie(0); ios::sync_with_stdio(0);
int T = 1, aa;
// cin >> T;aa=T;
while(T--){
// cout << "Case #" << aa-T << ": ";
solve();
cout << '\n';
}
return 0;
}
Compilation message
paths.cpp: In function 'int main()':
paths.cpp:66:16: warning: unused variable 'aa' [-Wunused-variable]
66 | int T = 1, aa;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23940 KB |
Output is correct |
2 |
Correct |
13 ms |
23892 KB |
Output is correct |
3 |
Correct |
16 ms |
23932 KB |
Output is correct |
4 |
Correct |
13 ms |
23892 KB |
Output is correct |
5 |
Correct |
13 ms |
23872 KB |
Output is correct |
6 |
Correct |
13 ms |
23936 KB |
Output is correct |
7 |
Correct |
13 ms |
23892 KB |
Output is correct |
8 |
Correct |
13 ms |
23948 KB |
Output is correct |
9 |
Correct |
14 ms |
24020 KB |
Output is correct |
10 |
Correct |
16 ms |
23940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
110 ms |
30104 KB |
Output is correct |
2 |
Correct |
105 ms |
30096 KB |
Output is correct |
3 |
Correct |
474 ms |
123428 KB |
Output is correct |
4 |
Correct |
122 ms |
43048 KB |
Output is correct |
5 |
Correct |
111 ms |
39208 KB |
Output is correct |
6 |
Correct |
286 ms |
85700 KB |
Output is correct |
7 |
Correct |
343 ms |
112340 KB |
Output is correct |
8 |
Correct |
393 ms |
112768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23940 KB |
Output is correct |
2 |
Correct |
13 ms |
23892 KB |
Output is correct |
3 |
Correct |
16 ms |
23932 KB |
Output is correct |
4 |
Correct |
13 ms |
23892 KB |
Output is correct |
5 |
Correct |
13 ms |
23872 KB |
Output is correct |
6 |
Correct |
13 ms |
23936 KB |
Output is correct |
7 |
Correct |
13 ms |
23892 KB |
Output is correct |
8 |
Correct |
13 ms |
23948 KB |
Output is correct |
9 |
Correct |
14 ms |
24020 KB |
Output is correct |
10 |
Correct |
16 ms |
23940 KB |
Output is correct |
11 |
Correct |
110 ms |
30104 KB |
Output is correct |
12 |
Correct |
105 ms |
30096 KB |
Output is correct |
13 |
Correct |
474 ms |
123428 KB |
Output is correct |
14 |
Correct |
122 ms |
43048 KB |
Output is correct |
15 |
Correct |
111 ms |
39208 KB |
Output is correct |
16 |
Correct |
286 ms |
85700 KB |
Output is correct |
17 |
Correct |
343 ms |
112340 KB |
Output is correct |
18 |
Correct |
393 ms |
112768 KB |
Output is correct |
19 |
Correct |
104 ms |
32244 KB |
Output is correct |
20 |
Correct |
93 ms |
30000 KB |
Output is correct |
21 |
Correct |
395 ms |
123448 KB |
Output is correct |
22 |
Correct |
148 ms |
43076 KB |
Output is correct |
23 |
Correct |
103 ms |
39200 KB |
Output is correct |
24 |
Correct |
299 ms |
85624 KB |
Output is correct |
25 |
Correct |
393 ms |
110904 KB |
Output is correct |
26 |
Correct |
373 ms |
112352 KB |
Output is correct |
27 |
Correct |
184 ms |
30204 KB |
Output is correct |
28 |
Correct |
213 ms |
34316 KB |
Output is correct |
29 |
Correct |
640 ms |
124132 KB |
Output is correct |
30 |
Correct |
429 ms |
77428 KB |
Output is correct |
31 |
Correct |
452 ms |
80960 KB |
Output is correct |
32 |
Correct |
604 ms |
113116 KB |
Output is correct |
33 |
Correct |
17 ms |
23880 KB |
Output is correct |
34 |
Correct |
17 ms |
23924 KB |
Output is correct |
35 |
Correct |
13 ms |
23844 KB |
Output is correct |
36 |
Correct |
14 ms |
23936 KB |
Output is correct |
37 |
Correct |
17 ms |
23944 KB |
Output is correct |
38 |
Correct |
17 ms |
23916 KB |
Output is correct |
39 |
Correct |
13 ms |
23892 KB |
Output is correct |
40 |
Correct |
16 ms |
23892 KB |
Output is correct |
41 |
Correct |
14 ms |
23932 KB |
Output is correct |
42 |
Correct |
13 ms |
23892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23820 KB |
Output is correct |
2 |
Correct |
129 ms |
25916 KB |
Output is correct |
3 |
Correct |
40 ms |
25940 KB |
Output is correct |
4 |
Correct |
128 ms |
57196 KB |
Output is correct |
5 |
Correct |
115 ms |
54204 KB |
Output is correct |
6 |
Correct |
305 ms |
57216 KB |
Output is correct |
7 |
Correct |
66 ms |
25960 KB |
Output is correct |
8 |
Correct |
171 ms |
57180 KB |
Output is correct |
9 |
Correct |
126 ms |
54204 KB |
Output is correct |
10 |
Correct |
143 ms |
54344 KB |
Output is correct |
11 |
Correct |
191 ms |
40616 KB |
Output is correct |
12 |
Correct |
220 ms |
47068 KB |
Output is correct |
13 |
Correct |
228 ms |
39900 KB |
Output is correct |
14 |
Correct |
282 ms |
53584 KB |
Output is correct |
15 |
Correct |
267 ms |
53596 KB |
Output is correct |
16 |
Correct |
18 ms |
23892 KB |
Output is correct |
17 |
Correct |
14 ms |
23892 KB |
Output is correct |
18 |
Correct |
18 ms |
23956 KB |
Output is correct |
19 |
Correct |
18 ms |
23956 KB |
Output is correct |
20 |
Correct |
15 ms |
23892 KB |
Output is correct |
21 |
Correct |
15 ms |
23892 KB |
Output is correct |
22 |
Correct |
17 ms |
23908 KB |
Output is correct |
23 |
Correct |
13 ms |
23940 KB |
Output is correct |
24 |
Correct |
16 ms |
23944 KB |
Output is correct |
25 |
Correct |
13 ms |
23900 KB |
Output is correct |