10829 | 2024-04-16 09:17:29 | Ablablabla | Autó-tortúra | cpp17 | Wrong answer 24/100 | 728ms | 13224 KiB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e16;
int main(){
ll n, m, k;
cin >> n >> m >> k;
vector<vector<ll>> csucsok(n, vector<ll>());
for(ll i = 0; i < m; i++){
ll a, b;
cin >> a >> b;
a--; b--;
csucsok[a].push_back(b);
csucsok[b].push_back(a);
}
ll l;
cin >> l;
vector<ll> latogat(l);
for(ll &x : latogat){
cin >> x;
x--;
}
ll b;
cin >> b;
vector<ll> kutak(b);
for(ll &x : kutak){
cin >> x;
x--;
}
vector<vector<ll>> kutL(b, vector<ll>(l, INF));
vector<vector<ll>> kutKut(b, vector<ll>(b, INF));
for(ll i = 0; i < b; i++){
vector<ll> d(n, INF);
queue<ll> bejar;
bejar.push(kutak[i]);
d[kutak[i]] = 0;
while(!bejar.empty()){
ll akt = bejar.front();
bejar.pop();
for(ll x : csucsok[akt]){
if(d[akt] + 1 < d[x]){
d[x] = d[akt] + 1;
bejar.push(x);
}
}
}
for(ll j = 0; j < l; j++){
if(d[latogat[j]] <= k){
kutL[i][j] = d[latogat[j]];
}
}
for(ll j = 0; j < b; j++){
if(d[kutak[j]] <= k){
kutKut[i][j] = d[kutak[j]];
}
}
}
for(ll o = 0; o < b; o++){
for(ll i = 0; i < b; i++){
for(ll j = 0; j < b; j++){
kutKut[i][j] = min(kutKut[i][j], kutKut[i][o] + kutKut[o][j]);
}
}
}
vector<ll> ansA(k + 2);
ansA[k + 1] = INF;
for(ll i = 1; i < l; i++){
vector<ll> ansB(k + 2, INF);
queue<ll> bejar;
vector<ll> tavok(n, INF);
tavok[latogat[i - 1]] = 0;
bejar.push(latogat[i - 1]);
while(!bejar.empty()){
ll akt = bejar.front();
bejar.pop();
for(ll x : csucsok[akt]){
if(tavok[akt] + 1 < tavok[x]){
tavok[x] = tavok[akt] + 1;
bejar.push(x);
}
}
}
ll kovi = tavok[latogat[i]];
for(ll j = 0; j + kovi <= k; j++){
ansB[j] = min(ansB[j], ansA[j + kovi] + kovi);
}
for(ll j = 0; j < b; j++){
ll marad = k - kutL[j][i];
if(marad >= 0 && kutL[j][i - 1] <= k){
ansB[marad] = min(ansB[marad], ansA[kutL[j][i - 1]] + kutL[j][i - 1] + kutL[j][i]);
}
for(ll kk = 0; kk < b; kk++){
ll marad2 = k - kutL[kk][i];
if(marad2 >= 0 && kutL[kk][i - 1] <= k && kutL[j][i - 1] <= k){
ansB[marad2] = min(ansB[marad2], ansA[kutL[j][i - 1]] + kutL[j][i - 1] + kutKut[j][kk] + kutL[kk][i]);
}
}
}
for(ll j = k - 1; j >= 0; j--){
ansB[j] = min(ansB[j], ansB[j + 1]);
}
ansA = ansB;
}
cout << (ansA[0] == INF ? -1 : ansA[0]) << "\n";
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1936 KiB | ||||
2 | Accepted | 351ms | 7104 KiB | ||||
subtask2 | 0/12 | ||||||
3 | Accepted | 3ms | 2248 KiB | ||||
4 | Accepted | 3ms | 2460 KiB | ||||
5 | Accepted | 3ms | 2612 KiB | ||||
6 | Accepted | 3ms | 2924 KiB | ||||
7 | Accepted | 2ms | 2868 KiB | ||||
8 | Wrong answer | 2ms | 3004 KiB | ||||
9 | Wrong answer | 3ms | 2868 KiB | ||||
10 | Accepted | 3ms | 3112 KiB | ||||
subtask3 | 0/18 | ||||||
11 | Accepted | 3ms | 2248 KiB | ||||
12 | Accepted | 3ms | 2460 KiB | ||||
13 | Accepted | 3ms | 2612 KiB | ||||
14 | Accepted | 3ms | 2924 KiB | ||||
15 | Accepted | 2ms | 2868 KiB | ||||
16 | Wrong answer | 2ms | 3004 KiB | ||||
17 | Wrong answer | 3ms | 2868 KiB | ||||
18 | Accepted | 3ms | 3112 KiB | ||||
19 | Accepted | 4ms | 3136 KiB | ||||
20 | Accepted | 16ms | 3632 KiB | ||||
21 | Accepted | 14ms | 3940 KiB | ||||
22 | Accepted | 14ms | 3884 KiB | ||||
23 | Accepted | 8ms | 3796 KiB | ||||
24 | Wrong answer | 6ms | 3796 KiB | ||||
25 | Wrong answer | 14ms | 4100 KiB | ||||
26 | Wrong answer | 12ms | 4052 KiB | ||||
27 | Wrong answer | 7ms | 4172 KiB | ||||
subtask4 | 0/25 | ||||||
28 | Accepted | 3ms | 2248 KiB | ||||
29 | Accepted | 3ms | 2460 KiB | ||||
30 | Accepted | 3ms | 2612 KiB | ||||
31 | Accepted | 3ms | 2924 KiB | ||||
32 | Accepted | 2ms | 2868 KiB | ||||
33 | Wrong answer | 2ms | 3004 KiB | ||||
34 | Wrong answer | 3ms | 2868 KiB | ||||
35 | Accepted | 3ms | 3112 KiB | ||||
36 | Accepted | 39ms | 4864 KiB | ||||
37 | Accepted | 35ms | 5088 KiB | ||||
38 | Accepted | 37ms | 5116 KiB | ||||
39 | Accepted | 27ms | 4852 KiB | ||||
40 | Accepted | 14ms | 4676 KiB | ||||
41 | Accepted | 8ms | 4576 KiB | ||||
42 | Wrong answer | 37ms | 5380 KiB | ||||
43 | Accepted | 28ms | 5172 KiB | ||||
44 | Wrong answer | 28ms | 5408 KiB | ||||
45 | Wrong answer | 14ms | 5408 KiB | ||||
subtask5 | 24/24 | ||||||
46 | Accepted | 435ms | 5204 KiB | ||||
47 | Accepted | 379ms | 5184 KiB | ||||
48 | Accepted | 425ms | 5384 KiB | ||||
49 | Accepted | 393ms | 5384 KiB | ||||
50 | Accepted | 247ms | 5336 KiB | ||||
51 | Accepted | 430ms | 5352 KiB | ||||
52 | Accepted | 375ms | 5288 KiB | ||||
53 | Accepted | 423ms | 5332 KiB | ||||
54 | Accepted | 388ms | 5440 KiB | ||||
55 | Accepted | 243ms | 5532 KiB | ||||
subtask6 | 0/21 | ||||||
56 | Accepted | 3ms | 2248 KiB | ||||
57 | Accepted | 3ms | 2460 KiB | ||||
58 | Accepted | 3ms | 2612 KiB | ||||
59 | Accepted | 3ms | 2924 KiB | ||||
60 | Accepted | 2ms | 2868 KiB | ||||
61 | Wrong answer | 2ms | 3004 KiB | ||||
62 | Wrong answer | 3ms | 2868 KiB | ||||
63 | Accepted | 3ms | 3112 KiB | ||||
64 | Accepted | 4ms | 3136 KiB | ||||
65 | Accepted | 16ms | 3632 KiB | ||||
66 | Accepted | 14ms | 3940 KiB | ||||
67 | Accepted | 14ms | 3884 KiB | ||||
68 | Accepted | 8ms | 3796 KiB | ||||
69 | Wrong answer | 6ms | 3796 KiB | ||||
70 | Wrong answer | 14ms | 4100 KiB | ||||
71 | Wrong answer | 12ms | 4052 KiB | ||||
72 | Wrong answer | 7ms | 4172 KiB | ||||
73 | Accepted | 39ms | 4864 KiB | ||||
74 | Accepted | 35ms | 5088 KiB | ||||
75 | Accepted | 37ms | 5116 KiB | ||||
76 | Accepted | 27ms | 4852 KiB | ||||
77 | Accepted | 14ms | 4676 KiB | ||||
78 | Accepted | 8ms | 4576 KiB | ||||
79 | Wrong answer | 37ms | 5380 KiB | ||||
80 | Accepted | 28ms | 5172 KiB | ||||
81 | Wrong answer | 28ms | 5408 KiB | ||||
82 | Wrong answer | 14ms | 5408 KiB | ||||
83 | Accepted | 435ms | 5204 KiB | ||||
84 | Accepted | 379ms | 5184 KiB | ||||
85 | Accepted | 425ms | 5384 KiB | ||||
86 | Accepted | 393ms | 5384 KiB | ||||
87 | Accepted | 247ms | 5336 KiB | ||||
88 | Accepted | 430ms | 5352 KiB | ||||
89 | Accepted | 375ms | 5288 KiB | ||||
90 | Accepted | 423ms | 5332 KiB | ||||
91 | Accepted | 388ms | 5440 KiB | ||||
92 | Accepted | 243ms | 5532 KiB | ||||
93 | Accepted | 112ms | 6784 KiB | ||||
94 | Wrong answer | 109ms | 6784 KiB | ||||
95 | Wrong answer | 133ms | 7016 KiB | ||||
96 | Wrong answer | 140ms | 7016 KiB | ||||
97 | Wrong answer | 43ms | 6568 KiB | ||||
98 | Accepted | 129ms | 7684 KiB | ||||
99 | Accepted | 97ms | 6500 KiB | ||||
100 | Accepted | 699ms | 12972 KiB | ||||
101 | Accepted | 728ms | 12964 KiB | ||||
102 | Accepted | 679ms | 13044 KiB | ||||
103 | Accepted | 584ms | 13088 KiB | ||||
104 | Accepted | 449ms | 12988 KiB | ||||
105 | Accepted | 578ms | 12960 KiB | ||||
106 | Accepted | 573ms | 13096 KiB | ||||
107 | Accepted | 612ms | 13032 KiB | ||||
108 | Accepted | 689ms | 13224 KiB | ||||
109 | Accepted | 136ms | 5668 KiB | ||||
110 | Accepted | 375ms | 8352 KiB | ||||
111 | Accepted | 425ms | 5764 KiB | ||||
112 | Accepted | 340ms | 6028 KiB | ||||
113 | Accepted | 363ms | 5772 KiB | ||||
114 | Wrong answer | 634ms | 12980 KiB | ||||
115 | Wrong answer | 93ms | 6740 KiB | ||||
116 | Wrong answer | 96ms | 6716 KiB | ||||
117 | Wrong answer | 572ms | 12944 KiB | ||||
118 | Wrong answer | 190ms | 12620 KiB |