# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
716421 |
2023-03-30T05:11:06 Z |
amir |
Paths (BOI18_paths) |
C++17 |
|
344 ms |
53864 KB |
/*
<< in the name of ALLAH >>
*/
#include <bits/stdc++.h>
//#pragma strings(readonly)
//#pragma variable(var_name,NORENT)
//#pragma GCC optimize("O3,no-stack-protector,unroll-loops,Ofast")
//#pragma GCC target("avx2,fma")
//#pragma GCC optimize("Ofast")
using namespace std;
typedef long long int ll ;
typedef pair<int , int> pii ;
typedef pair<ll , ll> pll ;
typedef double db ;
#define ps push_back
#define pb pop_back
#define mp make_pair
#define all(x) x.begin() , x.end()
#define sz(x) (int)x.size()
#define debug(a) cout<<"debug: "<<(#a)<<" = "<<a<<'\n'
#define debugAr(a) cout << "Array " << (#a) << " :\n" ;for (int TMP : a) cout << TMP << " " ; cout << '\n'
#define noo(x) (int)__builtin_popcount(x)
#define lastone(x) (x)&(-x)
const int maxn = 3e5 + 5 , maxk = 5 , maxb = 37 ;
int n , k , m;
int col[maxn] ;
ll dp[maxb][maxn] ;
vector<int > adj[maxn] ;
int main()
{
ios::sync_with_stdio(false) ; cin.tie(NULL) ; cout.tie(NULL) ;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
cin >> n >> m >> k ;
for (int i = 1 ;i <= n ; i ++ ) cin >> col[i] , col[i] -- ;
for (int i = 0 ;i < m ; i ++){
int u , v ;
cin >> u >> v ;
adj[u].ps(v) ;
adj[v].ps(u) ;
}
for (int i = 1 ; i <= n ; i++) adj[i].ps(0 ) ;
int MX = (1 << k ) ;
dp[0][0] = 1 ;
for (int mask = 1 ; mask < MX ; mask ++){
for (int v = 1 ; v <= n ; v++){
if (mask & (1 << col[v])){
int mask2 = mask ^ (1 << col[v]) ;
for (int u : adj[v]){
dp[mask][v] += dp[mask2][u] ;
}
}
}
}
ll ans = 0 ;
for (int i = 1 ; i < MX ; i++){
if (noo(i) < 2 ) continue ;
for (int v = 1 ; v <= n ; v++) ans += dp[i][v] ;
}
cout << ans << '\n' ;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7380 KB |
Output is correct |
2 |
Correct |
5 ms |
7508 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 |
7272 KB |
Output is correct |
6 |
Correct |
3 ms |
7508 KB |
Output is correct |
7 |
Correct |
4 ms |
7508 KB |
Output is correct |
8 |
Correct |
4 ms |
7508 KB |
Output is correct |
9 |
Correct |
4 ms |
7380 KB |
Output is correct |
10 |
Correct |
4 ms |
7380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
11376 KB |
Output is correct |
2 |
Correct |
55 ms |
10956 KB |
Output is correct |
3 |
Correct |
245 ms |
34980 KB |
Output is correct |
4 |
Correct |
79 ms |
12620 KB |
Output is correct |
5 |
Correct |
79 ms |
12276 KB |
Output is correct |
6 |
Correct |
171 ms |
26760 KB |
Output is correct |
7 |
Correct |
251 ms |
35148 KB |
Output is correct |
8 |
Correct |
243 ms |
34332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7380 KB |
Output is correct |
2 |
Correct |
5 ms |
7508 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 |
7272 KB |
Output is correct |
6 |
Correct |
3 ms |
7508 KB |
Output is correct |
7 |
Correct |
4 ms |
7508 KB |
Output is correct |
8 |
Correct |
4 ms |
7508 KB |
Output is correct |
9 |
Correct |
4 ms |
7380 KB |
Output is correct |
10 |
Correct |
4 ms |
7380 KB |
Output is correct |
11 |
Correct |
60 ms |
11376 KB |
Output is correct |
12 |
Correct |
55 ms |
10956 KB |
Output is correct |
13 |
Correct |
245 ms |
34980 KB |
Output is correct |
14 |
Correct |
79 ms |
12620 KB |
Output is correct |
15 |
Correct |
79 ms |
12276 KB |
Output is correct |
16 |
Correct |
171 ms |
26760 KB |
Output is correct |
17 |
Correct |
251 ms |
35148 KB |
Output is correct |
18 |
Correct |
243 ms |
34332 KB |
Output is correct |
19 |
Correct |
57 ms |
11404 KB |
Output is correct |
20 |
Correct |
44 ms |
10988 KB |
Output is correct |
21 |
Correct |
260 ms |
34952 KB |
Output is correct |
22 |
Correct |
88 ms |
12688 KB |
Output is correct |
23 |
Correct |
78 ms |
12196 KB |
Output is correct |
24 |
Correct |
169 ms |
26732 KB |
Output is correct |
25 |
Correct |
254 ms |
34940 KB |
Output is correct |
26 |
Correct |
247 ms |
34320 KB |
Output is correct |
27 |
Correct |
47 ms |
11084 KB |
Output is correct |
28 |
Correct |
64 ms |
12772 KB |
Output is correct |
29 |
Correct |
344 ms |
53864 KB |
Output is correct |
30 |
Correct |
191 ms |
32412 KB |
Output is correct |
31 |
Correct |
191 ms |
31376 KB |
Output is correct |
32 |
Correct |
319 ms |
53716 KB |
Output is correct |
33 |
Correct |
4 ms |
7380 KB |
Output is correct |
34 |
Correct |
4 ms |
7508 KB |
Output is correct |
35 |
Correct |
4 ms |
7380 KB |
Output is correct |
36 |
Correct |
4 ms |
7380 KB |
Output is correct |
37 |
Correct |
4 ms |
7380 KB |
Output is correct |
38 |
Correct |
4 ms |
7508 KB |
Output is correct |
39 |
Correct |
5 ms |
7508 KB |
Output is correct |
40 |
Correct |
5 ms |
7508 KB |
Output is correct |
41 |
Correct |
5 ms |
7380 KB |
Output is correct |
42 |
Correct |
5 ms |
7380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
7508 KB |
Output is correct |
2 |
Correct |
26 ms |
8812 KB |
Output is correct |
3 |
Correct |
20 ms |
8572 KB |
Output is correct |
4 |
Correct |
81 ms |
16556 KB |
Output is correct |
5 |
Correct |
67 ms |
16728 KB |
Output is correct |
6 |
Correct |
161 ms |
35700 KB |
Output is correct |
7 |
Correct |
22 ms |
8660 KB |
Output is correct |
8 |
Correct |
112 ms |
22956 KB |
Output is correct |
9 |
Correct |
73 ms |
23032 KB |
Output is correct |
10 |
Correct |
83 ms |
22196 KB |
Output is correct |
11 |
Correct |
72 ms |
22060 KB |
Output is correct |
12 |
Correct |
92 ms |
27056 KB |
Output is correct |
13 |
Correct |
90 ms |
20920 KB |
Output is correct |
14 |
Correct |
120 ms |
35516 KB |
Output is correct |
15 |
Correct |
106 ms |
35468 KB |
Output is correct |
16 |
Correct |
4 ms |
7380 KB |
Output is correct |
17 |
Correct |
4 ms |
7508 KB |
Output is correct |
18 |
Correct |
5 ms |
7380 KB |
Output is correct |
19 |
Correct |
4 ms |
7424 KB |
Output is correct |
20 |
Correct |
4 ms |
7380 KB |
Output is correct |
21 |
Correct |
4 ms |
7508 KB |
Output is correct |
22 |
Correct |
4 ms |
7508 KB |
Output is correct |
23 |
Correct |
4 ms |
7508 KB |
Output is correct |
24 |
Correct |
4 ms |
7380 KB |
Output is correct |
25 |
Correct |
4 ms |
7380 KB |
Output is correct |