10698 | 2024-04-09 23:04:36 | 111 | Autó-tortúra | cpp17 | Time limit exceeded 61/100 | 1.6s | 8072 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 j=K-1;j>=0;j--){
b[j]=min(b[j],b[j+1]);
for(int k=0;k<B;k++){
if(x[k][i]<=K-j&&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++){
if(x[kk][i]<=K-j&&x[k][i-1]<=K){
b[j]=min(b[j],a[x[k][i-1]]+x[k][i-1]+x[kk][i]+y[k][kk]);
}
}
}
}
a=b;
}
cout<<(a[0]==INF?-1:a[0])<<'\n';
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1824 KiB | ||||
2 | Time limit exceeded | 1.6s | 3788 KiB | ||||
subtask2 | 12/12 | ||||||
3 | Accepted | 3ms | 2564 KiB | ||||
4 | Accepted | 3ms | 2352 KiB | ||||
5 | Accepted | 3ms | 2676 KiB | ||||
6 | Accepted | 3ms | 2684 KiB | ||||
7 | Accepted | 3ms | 2824 KiB | ||||
8 | Accepted | 3ms | 2792 KiB | ||||
9 | Accepted | 3ms | 2924 KiB | ||||
10 | Accepted | 3ms | 3144 KiB | ||||
subtask3 | 0/18 | ||||||
11 | Accepted | 3ms | 2564 KiB | ||||
12 | Accepted | 3ms | 2352 KiB | ||||
13 | Accepted | 3ms | 2676 KiB | ||||
14 | Accepted | 3ms | 2684 KiB | ||||
15 | Accepted | 3ms | 2824 KiB | ||||
16 | Accepted | 3ms | 2792 KiB | ||||
17 | Accepted | 3ms | 2924 KiB | ||||
18 | Accepted | 3ms | 3144 KiB | ||||
19 | Accepted | 37ms | 3292 KiB | ||||
20 | Time limit exceeded | 1.56s | 3144 KiB | ||||
21 | Time limit exceeded | 1.57s | 3324 KiB | ||||
22 | Time limit exceeded | 1.58s | 3464 KiB | ||||
23 | Accepted | 439ms | 4196 KiB | ||||
24 | Accepted | 7ms | 4364 KiB | ||||
25 | Accepted | 59ms | 4788 KiB | ||||
26 | Accepted | 29ms | 4804 KiB | ||||
27 | Accepted | 14ms | 4768 KiB | ||||
subtask4 | 25/25 | ||||||
28 | Accepted | 3ms | 2564 KiB | ||||
29 | Accepted | 3ms | 2352 KiB | ||||
30 | Accepted | 3ms | 2676 KiB | ||||
31 | Accepted | 3ms | 2684 KiB | ||||
32 | Accepted | 3ms | 2824 KiB | ||||
33 | Accepted | 3ms | 2792 KiB | ||||
34 | Accepted | 3ms | 2924 KiB | ||||
35 | Accepted | 3ms | 3144 KiB | ||||
36 | Accepted | 574ms | 5184 KiB | ||||
37 | Accepted | 570ms | 5176 KiB | ||||
38 | Accepted | 575ms | 5252 KiB | ||||
39 | Accepted | 268ms | 4920 KiB | ||||
40 | Accepted | 79ms | 4664 KiB | ||||
41 | Accepted | 9ms | 4680 KiB | ||||
42 | Accepted | 79ms | 5224 KiB | ||||
43 | Accepted | 158ms | 5004 KiB | ||||
44 | Accepted | 68ms | 4984 KiB | ||||
45 | Accepted | 26ms | 4916 KiB | ||||
subtask5 | 24/24 | ||||||
46 | Accepted | 467ms | 4752 KiB | ||||
47 | Accepted | 414ms | 5036 KiB | ||||
48 | Accepted | 456ms | 4916 KiB | ||||
49 | Accepted | 423ms | 5012 KiB | ||||
50 | Accepted | 273ms | 4748 KiB | ||||
51 | Accepted | 458ms | 4864 KiB | ||||
52 | Accepted | 405ms | 4736 KiB | ||||
53 | Accepted | 448ms | 4872 KiB | ||||
54 | Accepted | 412ms | 4892 KiB | ||||
55 | Accepted | 263ms | 4736 KiB | ||||
subtask6 | 0/21 | ||||||
56 | Accepted | 3ms | 2564 KiB | ||||
57 | Accepted | 3ms | 2352 KiB | ||||
58 | Accepted | 3ms | 2676 KiB | ||||
59 | Accepted | 3ms | 2684 KiB | ||||
60 | Accepted | 3ms | 2824 KiB | ||||
61 | Accepted | 3ms | 2792 KiB | ||||
62 | Accepted | 3ms | 2924 KiB | ||||
63 | Accepted | 3ms | 3144 KiB | ||||
64 | Accepted | 37ms | 3292 KiB | ||||
65 | Time limit exceeded | 1.56s | 3144 KiB | ||||
66 | Time limit exceeded | 1.57s | 3324 KiB | ||||
67 | Time limit exceeded | 1.58s | 3464 KiB | ||||
68 | Accepted | 439ms | 4196 KiB | ||||
69 | Accepted | 7ms | 4364 KiB | ||||
70 | Accepted | 59ms | 4788 KiB | ||||
71 | Accepted | 29ms | 4804 KiB | ||||
72 | Accepted | 14ms | 4768 KiB | ||||
73 | Accepted | 574ms | 5184 KiB | ||||
74 | Accepted | 570ms | 5176 KiB | ||||
75 | Accepted | 575ms | 5252 KiB | ||||
76 | Accepted | 268ms | 4920 KiB | ||||
77 | Accepted | 79ms | 4664 KiB | ||||
78 | Accepted | 9ms | 4680 KiB | ||||
79 | Accepted | 79ms | 5224 KiB | ||||
80 | Accepted | 158ms | 5004 KiB | ||||
81 | Accepted | 68ms | 4984 KiB | ||||
82 | Accepted | 26ms | 4916 KiB | ||||
83 | Accepted | 467ms | 4752 KiB | ||||
84 | Accepted | 414ms | 5036 KiB | ||||
85 | Accepted | 456ms | 4916 KiB | ||||
86 | Accepted | 423ms | 5012 KiB | ||||
87 | Accepted | 273ms | 4748 KiB | ||||
88 | Accepted | 458ms | 4864 KiB | ||||
89 | Accepted | 405ms | 4736 KiB | ||||
90 | Accepted | 448ms | 4872 KiB | ||||
91 | Accepted | 412ms | 4892 KiB | ||||
92 | Accepted | 263ms | 4736 KiB | ||||
93 | Time limit exceeded | 1.531s | 4432 KiB | ||||
94 | Time limit exceeded | 1.554s | 4416 KiB | ||||
95 | Time limit exceeded | 1.557s | 4348 KiB | ||||
96 | Accepted | 356ms | 6272 KiB | ||||
97 | Accepted | 372ms | 5908 KiB | ||||
98 | Time limit exceeded | 1.557s | 4768 KiB | ||||
99 | Time limit exceeded | 1.554s | 4224 KiB | ||||
100 | Time limit exceeded | 1.567s | 7712 KiB | ||||
101 | Time limit exceeded | 1.562s | 7920 KiB | ||||
102 | Time limit exceeded | 1.57s | 7760 KiB | ||||
103 | Time limit exceeded | 1.567s | 7832 KiB | ||||
104 | Time limit exceeded | 1.575s | 7796 KiB | ||||
105 | Time limit exceeded | 1.567s | 7776 KiB | ||||
106 | Time limit exceeded | 1.55s | 7864 KiB | ||||
107 | Time limit exceeded | 1.529s | 7808 KiB | ||||
108 | Time limit exceeded | 1.577s | 8072 KiB | ||||
109 | Accepted | 252ms | 5252 KiB | ||||
110 | Time limit exceeded | 1.577s | 5436 KiB | ||||
111 | Accepted | 603ms | 5420 KiB | ||||
112 | Time limit exceeded | 1.565s | 4356 KiB | ||||
113 | Accepted | 691ms | 5352 KiB | ||||
114 | Time limit exceeded | 1.574s | 7832 KiB | ||||
115 | Accepted | 1.412s | 6340 KiB | ||||
116 | Accepted | 759ms | 6156 KiB | ||||
117 | Time limit exceeded | 1.562s | 7804 KiB | ||||
118 | Time limit exceeded | 1.582s | 7464 KiB |