#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb(e) push_back(e)
#define sv(a) sort(a.begin(),a.end())
#define sa(a,n) sort(a,a+n)
#define mp(a,b) make_pair(a,b)
#define vf first
#define vs second
#define ar array
#define all(x) x.begin(),x.end()
const int inf = 0x3f3f3f3f;
const int mod = 1000000007;
const double PI=3.14159265358979323846264338327950288419716939937510582097494459230;
bool remender(ll a , ll b){return a%b;}
const int N = 300003;
int arr[N];
vector<int> adj[N];
/*ll dfs(int node , int mask){
if(((1 << arr[node]) & mask) > 0)return 0;
if(dp[node][mask]!=-1)return dp[node][mask] + 1;
ll res = 0;
mask += (1 << arr[node]);
for(int i : adj[node]){
res += dfs(i , mask);
}
return (dp[node][mask] = res) + 1;
}*/
void solve(){
int n , m , k;
cin >> n >> m >> k;
ll dp[n + 1][1 << k];
memset(dp,0,sizeof dp);
for(int i = 0; i < n; i++){
cin >> arr[i + 1];
arr[i + 1]--;
dp[i + 1][1 << arr[i + 1]] = 1;
}
for(int i = 0; i < m; i++){
int a , b;
cin >> a >> b;
adj[a].pb(b);
adj[b].pb(a);
}
ll ans = 0;
for(int mask = 0; mask < (1 << k); mask++){
for(int i = 1; i <= n; i++){
if((mask & (1 << arr[i])) > 0){
int mas = mask ^ (1 << arr[i]);
for(int j : adj[i]){
dp[i][mask] += dp[j][mas];
}
}
ans += dp[i][mask];
}
}
cout << ans - n << '\n';
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//int t;cin >> t;while(t--)
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
7244 KB |
Output is correct |
2 |
Correct |
8 ms |
7372 KB |
Output is correct |
3 |
Correct |
7 ms |
7244 KB |
Output is correct |
4 |
Correct |
7 ms |
7372 KB |
Output is correct |
5 |
Correct |
7 ms |
7244 KB |
Output is correct |
6 |
Correct |
7 ms |
7264 KB |
Output is correct |
7 |
Correct |
8 ms |
7372 KB |
Output is correct |
8 |
Correct |
7 ms |
7372 KB |
Output is correct |
9 |
Correct |
7 ms |
7244 KB |
Output is correct |
10 |
Correct |
7 ms |
7244 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
60 ms |
11304 KB |
Output is correct |
2 |
Correct |
50 ms |
13252 KB |
Output is correct |
3 |
Correct |
231 ms |
40104 KB |
Output is correct |
4 |
Correct |
87 ms |
16068 KB |
Output is correct |
5 |
Correct |
83 ms |
15612 KB |
Output is correct |
6 |
Correct |
168 ms |
31800 KB |
Output is correct |
7 |
Correct |
252 ms |
40228 KB |
Output is correct |
8 |
Correct |
246 ms |
40800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
7244 KB |
Output is correct |
2 |
Correct |
8 ms |
7372 KB |
Output is correct |
3 |
Correct |
7 ms |
7244 KB |
Output is correct |
4 |
Correct |
7 ms |
7372 KB |
Output is correct |
5 |
Correct |
7 ms |
7244 KB |
Output is correct |
6 |
Correct |
7 ms |
7264 KB |
Output is correct |
7 |
Correct |
8 ms |
7372 KB |
Output is correct |
8 |
Correct |
7 ms |
7372 KB |
Output is correct |
9 |
Correct |
7 ms |
7244 KB |
Output is correct |
10 |
Correct |
7 ms |
7244 KB |
Output is correct |
11 |
Correct |
60 ms |
11304 KB |
Output is correct |
12 |
Correct |
50 ms |
13252 KB |
Output is correct |
13 |
Correct |
231 ms |
40104 KB |
Output is correct |
14 |
Correct |
87 ms |
16068 KB |
Output is correct |
15 |
Correct |
83 ms |
15612 KB |
Output is correct |
16 |
Correct |
168 ms |
31800 KB |
Output is correct |
17 |
Correct |
252 ms |
40228 KB |
Output is correct |
18 |
Correct |
246 ms |
40800 KB |
Output is correct |
19 |
Correct |
60 ms |
14052 KB |
Output is correct |
20 |
Correct |
49 ms |
13176 KB |
Output is correct |
21 |
Correct |
234 ms |
40204 KB |
Output is correct |
22 |
Correct |
87 ms |
16160 KB |
Output is correct |
23 |
Correct |
89 ms |
15672 KB |
Output is correct |
24 |
Correct |
163 ms |
31796 KB |
Output is correct |
25 |
Correct |
240 ms |
40160 KB |
Output is correct |
26 |
Correct |
241 ms |
40760 KB |
Output is correct |
27 |
Correct |
51 ms |
13252 KB |
Output is correct |
28 |
Correct |
71 ms |
15532 KB |
Output is correct |
29 |
Correct |
323 ms |
59036 KB |
Output is correct |
30 |
Correct |
229 ms |
36672 KB |
Output is correct |
31 |
Correct |
205 ms |
36540 KB |
Output is correct |
32 |
Correct |
334 ms |
58820 KB |
Output is correct |
33 |
Correct |
8 ms |
7324 KB |
Output is correct |
34 |
Correct |
7 ms |
7372 KB |
Output is correct |
35 |
Correct |
7 ms |
7244 KB |
Output is correct |
36 |
Correct |
7 ms |
7244 KB |
Output is correct |
37 |
Correct |
7 ms |
7244 KB |
Output is correct |
38 |
Correct |
7 ms |
7372 KB |
Output is correct |
39 |
Correct |
7 ms |
7364 KB |
Output is correct |
40 |
Correct |
7 ms |
7372 KB |
Output is correct |
41 |
Correct |
7 ms |
7292 KB |
Output is correct |
42 |
Correct |
7 ms |
7244 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
7328 KB |
Output is correct |
2 |
Correct |
25 ms |
8600 KB |
Output is correct |
3 |
Correct |
20 ms |
9204 KB |
Output is correct |
4 |
Correct |
60 ms |
18072 KB |
Output is correct |
5 |
Correct |
51 ms |
18856 KB |
Output is correct |
6 |
Correct |
155 ms |
36988 KB |
Output is correct |
7 |
Correct |
22 ms |
9164 KB |
Output is correct |
8 |
Correct |
90 ms |
24300 KB |
Output is correct |
9 |
Correct |
71 ms |
25160 KB |
Output is correct |
10 |
Correct |
81 ms |
25236 KB |
Output is correct |
11 |
Correct |
83 ms |
22980 KB |
Output is correct |
12 |
Correct |
91 ms |
30452 KB |
Output is correct |
13 |
Correct |
79 ms |
23236 KB |
Output is correct |
14 |
Correct |
143 ms |
36804 KB |
Output is correct |
15 |
Correct |
141 ms |
36948 KB |
Output is correct |
16 |
Correct |
8 ms |
7244 KB |
Output is correct |
17 |
Correct |
7 ms |
7364 KB |
Output is correct |
18 |
Correct |
7 ms |
7244 KB |
Output is correct |
19 |
Correct |
7 ms |
7244 KB |
Output is correct |
20 |
Correct |
8 ms |
7372 KB |
Output is correct |
21 |
Correct |
7 ms |
7372 KB |
Output is correct |
22 |
Correct |
7 ms |
7244 KB |
Output is correct |
23 |
Correct |
7 ms |
7372 KB |
Output is correct |
24 |
Correct |
7 ms |
7244 KB |
Output is correct |
25 |
Correct |
7 ms |
7244 KB |
Output is correct |