# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
927219 |
2024-02-14T12:43:03 Z |
vjudge1 |
Paths (BOI18_paths) |
C++17 |
|
485 ms |
85840 KB |
#include <bits/stdc++.h>
using namespace std;
#define all(a) a.begin(),a.end()
#define pb push_back
#define vt vector
#define endl '\n'
typedef long long ll;
const ll mod=1e9+7;
const ll inf=1e9+7;
const int N=3e5+4;
int n,m,k,a[N],used[N];
ll res=0;
ll dp[(1<<6)][N];
vt<int>g[N];
void solve(){
cin>>n>>m>>k;
for(int i=1; i<=n; ++i) {
cin>>a[i];
a[i]--;
dp[(1<<a[i])][i]=1;
}
for(int i=1; i<=m; ++i){
int u,v;
cin>>u>>v;
g[u].pb(v);
g[v].pb(u);
}
for(int mask=0; mask<(1<<k); ++mask){
for(int v=1; v<=n; ++v){
for(int to:g[v]){
if(a[to]!=a[v] && ((mask>>a[to])&1)==0) dp[mask|(1<<a[to])][to]+=dp[mask][v];
}
}
}
ll ans=0;
for(int mask=1; mask<(1<<k); ++mask){
for(int v=1; v<=n; ++v){
ans+=dp[mask][v];
}
}
cout<<ans-n<<endl;
}
int main(){
int tt=1;
//cin>>tt;
while(tt--) {
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
39516 KB |
Output is correct |
2 |
Correct |
6 ms |
39772 KB |
Output is correct |
3 |
Correct |
4 ms |
23128 KB |
Output is correct |
4 |
Correct |
3 ms |
15092 KB |
Output is correct |
5 |
Correct |
2 ms |
10844 KB |
Output is correct |
6 |
Correct |
6 ms |
39516 KB |
Output is correct |
7 |
Correct |
6 ms |
39516 KB |
Output is correct |
8 |
Correct |
6 ms |
39516 KB |
Output is correct |
9 |
Correct |
4 ms |
33372 KB |
Output is correct |
10 |
Correct |
3 ms |
23132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
134 ms |
26704 KB |
Output is correct |
2 |
Correct |
117 ms |
26748 KB |
Output is correct |
3 |
Correct |
317 ms |
36692 KB |
Output is correct |
4 |
Correct |
148 ms |
19496 KB |
Output is correct |
5 |
Correct |
138 ms |
15720 KB |
Output is correct |
6 |
Correct |
234 ms |
35092 KB |
Output is correct |
7 |
Correct |
315 ms |
36712 KB |
Output is correct |
8 |
Correct |
329 ms |
37304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
39516 KB |
Output is correct |
2 |
Correct |
6 ms |
39772 KB |
Output is correct |
3 |
Correct |
4 ms |
23128 KB |
Output is correct |
4 |
Correct |
3 ms |
15092 KB |
Output is correct |
5 |
Correct |
2 ms |
10844 KB |
Output is correct |
6 |
Correct |
6 ms |
39516 KB |
Output is correct |
7 |
Correct |
6 ms |
39516 KB |
Output is correct |
8 |
Correct |
6 ms |
39516 KB |
Output is correct |
9 |
Correct |
4 ms |
33372 KB |
Output is correct |
10 |
Correct |
3 ms |
23132 KB |
Output is correct |
11 |
Correct |
134 ms |
26704 KB |
Output is correct |
12 |
Correct |
117 ms |
26748 KB |
Output is correct |
13 |
Correct |
317 ms |
36692 KB |
Output is correct |
14 |
Correct |
148 ms |
19496 KB |
Output is correct |
15 |
Correct |
138 ms |
15720 KB |
Output is correct |
16 |
Correct |
234 ms |
35092 KB |
Output is correct |
17 |
Correct |
315 ms |
36712 KB |
Output is correct |
18 |
Correct |
329 ms |
37304 KB |
Output is correct |
19 |
Correct |
159 ms |
26704 KB |
Output is correct |
20 |
Correct |
115 ms |
26704 KB |
Output is correct |
21 |
Correct |
325 ms |
36952 KB |
Output is correct |
22 |
Correct |
148 ms |
19280 KB |
Output is correct |
23 |
Correct |
129 ms |
15268 KB |
Output is correct |
24 |
Correct |
242 ms |
34948 KB |
Output is correct |
25 |
Correct |
298 ms |
36788 KB |
Output is correct |
26 |
Correct |
317 ms |
37712 KB |
Output is correct |
27 |
Correct |
139 ms |
43088 KB |
Output is correct |
28 |
Correct |
168 ms |
43772 KB |
Output is correct |
29 |
Correct |
441 ms |
55440 KB |
Output is correct |
30 |
Correct |
288 ms |
52056 KB |
Output is correct |
31 |
Correct |
301 ms |
52516 KB |
Output is correct |
32 |
Correct |
485 ms |
55124 KB |
Output is correct |
33 |
Correct |
5 ms |
39512 KB |
Output is correct |
34 |
Correct |
5 ms |
39516 KB |
Output is correct |
35 |
Correct |
4 ms |
23132 KB |
Output is correct |
36 |
Correct |
3 ms |
14940 KB |
Output is correct |
37 |
Correct |
2 ms |
10844 KB |
Output is correct |
38 |
Correct |
5 ms |
39516 KB |
Output is correct |
39 |
Correct |
5 ms |
39516 KB |
Output is correct |
40 |
Correct |
5 ms |
39532 KB |
Output is correct |
41 |
Correct |
5 ms |
33368 KB |
Output is correct |
42 |
Correct |
3 ms |
23132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
57948 KB |
Output is correct |
2 |
Correct |
70 ms |
73552 KB |
Output is correct |
3 |
Correct |
40 ms |
24144 KB |
Output is correct |
4 |
Correct |
100 ms |
28556 KB |
Output is correct |
5 |
Correct |
76 ms |
29128 KB |
Output is correct |
6 |
Correct |
161 ms |
85780 KB |
Output is correct |
7 |
Correct |
50 ms |
40720 KB |
Output is correct |
8 |
Correct |
112 ms |
46676 KB |
Output is correct |
9 |
Correct |
86 ms |
47568 KB |
Output is correct |
10 |
Correct |
97 ms |
47308 KB |
Output is correct |
11 |
Correct |
111 ms |
84584 KB |
Output is correct |
12 |
Correct |
105 ms |
83516 KB |
Output is correct |
13 |
Correct |
134 ms |
82724 KB |
Output is correct |
14 |
Correct |
166 ms |
85840 KB |
Output is correct |
15 |
Correct |
164 ms |
85840 KB |
Output is correct |
16 |
Correct |
5 ms |
39512 KB |
Output is correct |
17 |
Correct |
5 ms |
39516 KB |
Output is correct |
18 |
Correct |
4 ms |
23132 KB |
Output is correct |
19 |
Correct |
3 ms |
15192 KB |
Output is correct |
20 |
Correct |
2 ms |
10844 KB |
Output is correct |
21 |
Correct |
5 ms |
39516 KB |
Output is correct |
22 |
Correct |
5 ms |
39528 KB |
Output is correct |
23 |
Correct |
5 ms |
39512 KB |
Output is correct |
24 |
Correct |
4 ms |
33372 KB |
Output is correct |
25 |
Correct |
4 ms |
23132 KB |
Output is correct |