/*
<< 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 = 1e5 + 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' ;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2780 KB |
Output is correct |
3 |
Correct |
2 ms |
2688 KB |
Output is correct |
4 |
Correct |
1 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
1 ms |
2772 KB |
Output is correct |
7 |
Correct |
2 ms |
2772 KB |
Output is correct |
8 |
Correct |
2 ms |
2772 KB |
Output is correct |
9 |
Correct |
1 ms |
2644 KB |
Output is correct |
10 |
Correct |
2 ms |
2644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
6732 KB |
Output is correct |
2 |
Correct |
44 ms |
6304 KB |
Output is correct |
3 |
Incorrect |
6 ms |
2948 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2780 KB |
Output is correct |
3 |
Correct |
2 ms |
2688 KB |
Output is correct |
4 |
Correct |
1 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
1 ms |
2772 KB |
Output is correct |
7 |
Correct |
2 ms |
2772 KB |
Output is correct |
8 |
Correct |
2 ms |
2772 KB |
Output is correct |
9 |
Correct |
1 ms |
2644 KB |
Output is correct |
10 |
Correct |
2 ms |
2644 KB |
Output is correct |
11 |
Correct |
56 ms |
6732 KB |
Output is correct |
12 |
Correct |
44 ms |
6304 KB |
Output is correct |
13 |
Incorrect |
6 ms |
2948 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2772 KB |
Output is correct |
2 |
Correct |
17 ms |
4008 KB |
Output is correct |
3 |
Correct |
15 ms |
3792 KB |
Output is correct |
4 |
Correct |
57 ms |
11860 KB |
Output is correct |
5 |
Correct |
48 ms |
11964 KB |
Output is correct |
6 |
Correct |
141 ms |
30604 KB |
Output is correct |
7 |
Correct |
16 ms |
3932 KB |
Output is correct |
8 |
Correct |
88 ms |
18084 KB |
Output is correct |
9 |
Correct |
62 ms |
18256 KB |
Output is correct |
10 |
Correct |
81 ms |
17424 KB |
Output is correct |
11 |
Correct |
55 ms |
17260 KB |
Output is correct |
12 |
Correct |
67 ms |
22220 KB |
Output is correct |
13 |
Correct |
55 ms |
16084 KB |
Output is correct |
14 |
Correct |
117 ms |
30668 KB |
Output is correct |
15 |
Correct |
107 ms |
30572 KB |
Output is correct |
16 |
Correct |
2 ms |
2764 KB |
Output is correct |
17 |
Correct |
2 ms |
2772 KB |
Output is correct |
18 |
Correct |
1 ms |
2644 KB |
Output is correct |
19 |
Correct |
2 ms |
2644 KB |
Output is correct |
20 |
Correct |
2 ms |
2644 KB |
Output is correct |
21 |
Correct |
2 ms |
2772 KB |
Output is correct |
22 |
Correct |
2 ms |
2772 KB |
Output is correct |
23 |
Correct |
2 ms |
2772 KB |
Output is correct |
24 |
Correct |
1 ms |
2644 KB |
Output is correct |
25 |
Correct |
1 ms |
2644 KB |
Output is correct |