10701 | 2024-04-09 23:15:17 | 111 | Autó-tortúra | cpp17 | Wrong answer 24/100 | 717ms | 12584 KiB |
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define INF (int)1e16
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef CB
freopen("be2.txt","r",stdin);
// freopen("ki.txt","w",stdout);
#endif
int N,M,K;
cin>>N>>M>>K;
vector<vector<int>>g(N+1);
for(int i=0;i<M;i++){
int a,b;
cin>>a>>b;
g[a].push_back(b);
g[b].push_back(a);
}
int L;
cin>>L;
vector<int>l(L);
for(int i=0;i<L;i++){
cin>>l[i];
}
int B;
cin>>B;
vector<int>b(B);
for(int i=0;i<B;i++){
cin>>b[i];
}
vector<vector<int>>x(B,vector<int>(L,INF));
vector<vector<int>>y(B,vector<int>(B,INF));
for(int i=0;i<B;i++){
deque<int>q;
vector<int>d(N+1,INF);
d[b[i]]=0;
q.push_back(b[i]);
while(!q.empty()){
int i=q.front();
q.pop_front();
for(int j:g[i]){
if(d[i]+1<d[j]){
d[j]=d[i]+1;
q.push_back(j);
}
}
}
for(int j=0;j<L;j++){
if(d[l[j]]<=K){
x[i][j]=d[l[j]];
}
}
for(int j=0;j<B;j++){
if(d[b[j]]<=K){
y[i][j]=d[b[j]];
}
}
}
for(int i=0;i<B;i++){
for(int j=0;j<B;j++){
for(int k=0;k<B;k++){
y[j][k]=min(y[j][k],y[j][i]+y[i][k]);
}
}
}
vector<int>a(K+2);
a[K+1]=INF;
for(int i=1;i<L;i++){
vector<int>b(K+2,INF);
deque<int>q;
vector<int>d(N+1,INF);
d[l[i-1]]=0;
q.push_back(l[i-1]);
while(!q.empty()){
int i=q.front();
q.pop_front();
for(int j:g[i]){
if(d[i]+1<d[j]){
d[j]=d[i]+1;
q.push_back(j);
}
}
}
int dl=d[l[i]];
for(int j=0;j+dl<=K;j++){
b[j]=min(b[j],a[j+dl]+dl);
}
for(int k=0;k<B;k++){
int j=K-x[k][i];
if(j<0){
continue;
}
if(x[k][i-1]<=K){
b[j]=min(b[j],a[x[k][i-1]]+x[k][i-1]+x[k][i]);
}
for(int kk=0;kk<B;kk++){
int jj=K-x[kk][i];
if(jj<0){
continue;
}
if(x[k][i-1]<=K){
b[min(j,jj)]=min(b[min(j,jj)],a[x[k][i-1]]+x[k][i-1]+x[kk][i]+y[k][kk]);
}
}
}
for(int j=K-1;j>=0;j--){
b[j]=min(b[j],b[j+1]);
}
a=b;
}
cout<<(a[0]==INF?-1:a[0])<<'\n';
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1836 KiB | ||||
2 | Accepted | 345ms | 7256 KiB | ||||
subtask2 | 0/12 | ||||||
3 | Accepted | 3ms | 2536 KiB | ||||
4 | Accepted | 3ms | 2644 KiB | ||||
5 | Accepted | 3ms | 2528 KiB | ||||
6 | Accepted | 3ms | 2472 KiB | ||||
7 | Accepted | 3ms | 2424 KiB | ||||
8 | Wrong answer | 2ms | 2488 KiB | ||||
9 | Wrong answer | 3ms | 2620 KiB | ||||
10 | Accepted | 3ms | 2828 KiB | ||||
subtask3 | 0/18 | ||||||
11 | Accepted | 3ms | 2536 KiB | ||||
12 | Accepted | 3ms | 2644 KiB | ||||
13 | Accepted | 3ms | 2528 KiB | ||||
14 | Accepted | 3ms | 2472 KiB | ||||
15 | Accepted | 3ms | 2424 KiB | ||||
16 | Wrong answer | 2ms | 2488 KiB | ||||
17 | Wrong answer | 3ms | 2620 KiB | ||||
18 | Accepted | 3ms | 2828 KiB | ||||
19 | Accepted | 4ms | 3120 KiB | ||||
20 | Accepted | 16ms | 3800 KiB | ||||
21 | Accepted | 14ms | 4004 KiB | ||||
22 | Accepted | 14ms | 4144 KiB | ||||
23 | Accepted | 7ms | 3836 KiB | ||||
24 | Wrong answer | 4ms | 3744 KiB | ||||
25 | Wrong answer | 8ms | 4128 KiB | ||||
26 | Wrong answer | 8ms | 4136 KiB | ||||
27 | Wrong answer | 4ms | 4076 KiB | ||||
subtask4 | 0/25 | ||||||
28 | Accepted | 3ms | 2536 KiB | ||||
29 | Accepted | 3ms | 2644 KiB | ||||
30 | Accepted | 3ms | 2528 KiB | ||||
31 | Accepted | 3ms | 2472 KiB | ||||
32 | Accepted | 3ms | 2424 KiB | ||||
33 | Wrong answer | 2ms | 2488 KiB | ||||
34 | Wrong answer | 3ms | 2620 KiB | ||||
35 | Accepted | 3ms | 2828 KiB | ||||
36 | Accepted | 35ms | 4464 KiB | ||||
37 | Accepted | 32ms | 4608 KiB | ||||
38 | Accepted | 35ms | 4904 KiB | ||||
39 | Accepted | 24ms | 4632 KiB | ||||
40 | Accepted | 14ms | 4452 KiB | ||||
41 | Accepted | 7ms | 4388 KiB | ||||
42 | Wrong answer | 32ms | 4928 KiB | ||||
43 | Accepted | 25ms | 4712 KiB | ||||
44 | Wrong answer | 25ms | 4712 KiB | ||||
45 | Wrong answer | 13ms | 4656 KiB | ||||
subtask5 | 24/24 | ||||||
46 | Accepted | 416ms | 4628 KiB | ||||
47 | Accepted | 365ms | 4620 KiB | ||||
48 | Accepted | 404ms | 4716 KiB | ||||
49 | Accepted | 374ms | 4588 KiB | ||||
50 | Accepted | 238ms | 4452 KiB | ||||
51 | Accepted | 411ms | 4712 KiB | ||||
52 | Accepted | 360ms | 4708 KiB | ||||
53 | Accepted | 400ms | 4804 KiB | ||||
54 | Accepted | 368ms | 4804 KiB | ||||
55 | Accepted | 233ms | 4812 KiB | ||||
subtask6 | 0/21 | ||||||
56 | Accepted | 3ms | 2536 KiB | ||||
57 | Accepted | 3ms | 2644 KiB | ||||
58 | Accepted | 3ms | 2528 KiB | ||||
59 | Accepted | 3ms | 2472 KiB | ||||
60 | Accepted | 3ms | 2424 KiB | ||||
61 | Wrong answer | 2ms | 2488 KiB | ||||
62 | Wrong answer | 3ms | 2620 KiB | ||||
63 | Accepted | 3ms | 2828 KiB | ||||
64 | Accepted | 4ms | 3120 KiB | ||||
65 | Accepted | 16ms | 3800 KiB | ||||
66 | Accepted | 14ms | 4004 KiB | ||||
67 | Accepted | 14ms | 4144 KiB | ||||
68 | Accepted | 7ms | 3836 KiB | ||||
69 | Wrong answer | 4ms | 3744 KiB | ||||
70 | Wrong answer | 8ms | 4128 KiB | ||||
71 | Wrong answer | 8ms | 4136 KiB | ||||
72 | Wrong answer | 4ms | 4076 KiB | ||||
73 | Accepted | 35ms | 4464 KiB | ||||
74 | Accepted | 32ms | 4608 KiB | ||||
75 | Accepted | 35ms | 4904 KiB | ||||
76 | Accepted | 24ms | 4632 KiB | ||||
77 | Accepted | 14ms | 4452 KiB | ||||
78 | Accepted | 7ms | 4388 KiB | ||||
79 | Wrong answer | 32ms | 4928 KiB | ||||
80 | Accepted | 25ms | 4712 KiB | ||||
81 | Wrong answer | 25ms | 4712 KiB | ||||
82 | Wrong answer | 13ms | 4656 KiB | ||||
83 | Accepted | 416ms | 4628 KiB | ||||
84 | Accepted | 365ms | 4620 KiB | ||||
85 | Accepted | 404ms | 4716 KiB | ||||
86 | Accepted | 374ms | 4588 KiB | ||||
87 | Accepted | 238ms | 4452 KiB | ||||
88 | Accepted | 411ms | 4712 KiB | ||||
89 | Accepted | 360ms | 4708 KiB | ||||
90 | Accepted | 400ms | 4804 KiB | ||||
91 | Accepted | 368ms | 4804 KiB | ||||
92 | Accepted | 233ms | 4812 KiB | ||||
93 | Accepted | 111ms | 6244 KiB | ||||
94 | Wrong answer | 98ms | 6344 KiB | ||||
95 | Wrong answer | 127ms | 6300 KiB | ||||
96 | Wrong answer | 133ms | 6348 KiB | ||||
97 | Wrong answer | 29ms | 5912 KiB | ||||
98 | Accepted | 111ms | 7192 KiB | ||||
99 | Accepted | 97ms | 6016 KiB | ||||
100 | Accepted | 685ms | 12304 KiB | ||||
101 | Accepted | 717ms | 12352 KiB | ||||
102 | Accepted | 662ms | 12172 KiB | ||||
103 | Accepted | 578ms | 12148 KiB | ||||
104 | Accepted | 460ms | 12260 KiB | ||||
105 | Accepted | 612ms | 12280 KiB | ||||
106 | Accepted | 591ms | 12284 KiB | ||||
107 | Accepted | 558ms | 12204 KiB | ||||
108 | Accepted | 676ms | 12584 KiB | ||||
109 | Accepted | 140ms | 4932 KiB | ||||
110 | Accepted | 361ms | 7584 KiB | ||||
111 | Accepted | 412ms | 4996 KiB | ||||
112 | Accepted | 328ms | 5272 KiB | ||||
113 | Accepted | 351ms | 5096 KiB | ||||
114 | Wrong answer | 587ms | 12536 KiB | ||||
115 | Wrong answer | 87ms | 5960 KiB | ||||
116 | Wrong answer | 90ms | 6072 KiB | ||||
117 | Wrong answer | 361ms | 12120 KiB | ||||
118 | Wrong answer | 109ms | 11988 KiB |