#include <iostream>
#include <fstream>
using namespace std;
const int nmax=300005;
long long dp[32][nmax];
int c[nmax],a[nmax],b[nmax];
int n,m,k,i,j,x,y;
long long ans;
int main()
{
//freopen("data.in","r",stdin);
cin>>n>>m>>k;
for(i=1;i<=n;i++)
{
cin>>c[i];
c[i]--;
}
for(i=1;i<=m;i++)
{
cin>>a[i]>>b[i];
}
for(j=1;j<=n;j++)
dp[(1<<c[j])][j]=1;
for(i=1;i<(1<<k);i++)
{
if((i&(i-1)))
for(j=1;j<=n;j++)
ans+=dp[i][j];
for(j=1;j<=m;j++)
{
x=a[j];y=b[j];
if(((1<<c[x])&i)&&(!((1<<c[y])&i)))
dp[i+(1<<c[y])][y]+=dp[i][x];
if((!((1<<c[x])&i))&&((1<<c[y])&i))
dp[i+(1<<c[x])][x]+=dp[i][y];
}
}
cout<<ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
400 KB |
Output is correct |
2 |
Correct |
3 ms |
616 KB |
Output is correct |
3 |
Correct |
2 ms |
616 KB |
Output is correct |
4 |
Correct |
2 ms |
616 KB |
Output is correct |
5 |
Correct |
2 ms |
616 KB |
Output is correct |
6 |
Correct |
2 ms |
616 KB |
Output is correct |
7 |
Correct |
2 ms |
616 KB |
Output is correct |
8 |
Correct |
2 ms |
616 KB |
Output is correct |
9 |
Correct |
2 ms |
616 KB |
Output is correct |
10 |
Correct |
2 ms |
616 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
213 ms |
3196 KB |
Output is correct |
2 |
Correct |
186 ms |
5160 KB |
Output is correct |
3 |
Correct |
352 ms |
26852 KB |
Output is correct |
4 |
Correct |
232 ms |
26852 KB |
Output is correct |
5 |
Correct |
222 ms |
26852 KB |
Output is correct |
6 |
Correct |
329 ms |
26852 KB |
Output is correct |
7 |
Correct |
358 ms |
26976 KB |
Output is correct |
8 |
Correct |
349 ms |
26996 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
400 KB |
Output is correct |
2 |
Correct |
3 ms |
616 KB |
Output is correct |
3 |
Correct |
2 ms |
616 KB |
Output is correct |
4 |
Correct |
2 ms |
616 KB |
Output is correct |
5 |
Correct |
2 ms |
616 KB |
Output is correct |
6 |
Correct |
2 ms |
616 KB |
Output is correct |
7 |
Correct |
2 ms |
616 KB |
Output is correct |
8 |
Correct |
2 ms |
616 KB |
Output is correct |
9 |
Correct |
2 ms |
616 KB |
Output is correct |
10 |
Correct |
2 ms |
616 KB |
Output is correct |
11 |
Correct |
213 ms |
3196 KB |
Output is correct |
12 |
Correct |
186 ms |
5160 KB |
Output is correct |
13 |
Correct |
352 ms |
26852 KB |
Output is correct |
14 |
Correct |
232 ms |
26852 KB |
Output is correct |
15 |
Correct |
222 ms |
26852 KB |
Output is correct |
16 |
Correct |
329 ms |
26852 KB |
Output is correct |
17 |
Correct |
358 ms |
26976 KB |
Output is correct |
18 |
Correct |
349 ms |
26996 KB |
Output is correct |
19 |
Correct |
214 ms |
26996 KB |
Output is correct |
20 |
Correct |
182 ms |
26996 KB |
Output is correct |
21 |
Correct |
366 ms |
27012 KB |
Output is correct |
22 |
Correct |
230 ms |
27012 KB |
Output is correct |
23 |
Correct |
226 ms |
27012 KB |
Output is correct |
24 |
Correct |
325 ms |
27012 KB |
Output is correct |
25 |
Correct |
356 ms |
32820 KB |
Output is correct |
26 |
Correct |
351 ms |
32820 KB |
Output is correct |
27 |
Correct |
206 ms |
32820 KB |
Output is correct |
28 |
Correct |
252 ms |
32820 KB |
Output is correct |
29 |
Correct |
467 ms |
51584 KB |
Output is correct |
30 |
Correct |
384 ms |
51584 KB |
Output is correct |
31 |
Correct |
351 ms |
51584 KB |
Output is correct |
32 |
Correct |
429 ms |
51584 KB |
Output is correct |
33 |
Correct |
2 ms |
51584 KB |
Output is correct |
34 |
Correct |
2 ms |
51584 KB |
Output is correct |
35 |
Correct |
2 ms |
51584 KB |
Output is correct |
36 |
Correct |
2 ms |
51584 KB |
Output is correct |
37 |
Correct |
2 ms |
51584 KB |
Output is correct |
38 |
Correct |
2 ms |
51584 KB |
Output is correct |
39 |
Correct |
2 ms |
51584 KB |
Output is correct |
40 |
Correct |
2 ms |
51584 KB |
Output is correct |
41 |
Correct |
2 ms |
51584 KB |
Output is correct |
42 |
Correct |
2 ms |
51584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
51584 KB |
Output is correct |
2 |
Correct |
88 ms |
51584 KB |
Output is correct |
3 |
Correct |
62 ms |
51584 KB |
Output is correct |
4 |
Correct |
114 ms |
51584 KB |
Output is correct |
5 |
Correct |
106 ms |
51584 KB |
Output is correct |
6 |
Correct |
238 ms |
51584 KB |
Output is correct |
7 |
Correct |
72 ms |
51584 KB |
Output is correct |
8 |
Correct |
132 ms |
51584 KB |
Output is correct |
9 |
Correct |
187 ms |
51584 KB |
Output is correct |
10 |
Correct |
126 ms |
51584 KB |
Output is correct |
11 |
Correct |
133 ms |
51584 KB |
Output is correct |
12 |
Correct |
149 ms |
51584 KB |
Output is correct |
13 |
Correct |
132 ms |
51584 KB |
Output is correct |
14 |
Correct |
174 ms |
51584 KB |
Output is correct |
15 |
Correct |
176 ms |
51584 KB |
Output is correct |
16 |
Correct |
2 ms |
51584 KB |
Output is correct |
17 |
Correct |
2 ms |
51584 KB |
Output is correct |
18 |
Correct |
2 ms |
51584 KB |
Output is correct |
19 |
Correct |
3 ms |
51584 KB |
Output is correct |
20 |
Correct |
2 ms |
51584 KB |
Output is correct |
21 |
Correct |
2 ms |
51584 KB |
Output is correct |
22 |
Correct |
3 ms |
51584 KB |
Output is correct |
23 |
Correct |
3 ms |
51584 KB |
Output is correct |
24 |
Correct |
2 ms |
51584 KB |
Output is correct |
25 |
Correct |
2 ms |
51584 KB |
Output is correct |