10815 | 2024-04-15 14:57:37 | Ablablabla | Autó-tortúra | cpp17 | Wrong answer 24/100 | 759ms | 13296 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 k = 0; k < b; k++){
for(ll i = 0; i < b; i++){
for(ll j = 0; j < b; j++){
kutKut[i][j] = min(kutKut[i][j], kutKut[i][k] + kutKut[k][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 | 1960 KiB | ||||
2 | Accepted | 351ms | 7384 KiB | ||||
subtask2 | 0/12 | ||||||
3 | Accepted | 3ms | 2468 KiB | ||||
4 | Accepted | 2ms | 2488 KiB | ||||
5 | Accepted | 3ms | 2492 KiB | ||||
6 | Accepted | 3ms | 2708 KiB | ||||
7 | Accepted | 3ms | 2908 KiB | ||||
8 | Wrong answer | 3ms | 3120 KiB | ||||
9 | Wrong answer | 3ms | 3380 KiB | ||||
10 | Accepted | 3ms | 3504 KiB | ||||
subtask3 | 0/18 | ||||||
11 | Accepted | 3ms | 2468 KiB | ||||
12 | Accepted | 2ms | 2488 KiB | ||||
13 | Accepted | 3ms | 2492 KiB | ||||
14 | Accepted | 3ms | 2708 KiB | ||||
15 | Accepted | 3ms | 2908 KiB | ||||
16 | Wrong answer | 3ms | 3120 KiB | ||||
17 | Wrong answer | 3ms | 3380 KiB | ||||
18 | Accepted | 3ms | 3504 KiB | ||||
19 | Accepted | 4ms | 3656 KiB | ||||
20 | Accepted | 16ms | 4408 KiB | ||||
21 | Accepted | 14ms | 4320 KiB | ||||
22 | Accepted | 14ms | 4580 KiB | ||||
23 | Accepted | 7ms | 4480 KiB | ||||
24 | Wrong answer | 6ms | 4608 KiB | ||||
25 | Wrong answer | 14ms | 5080 KiB | ||||
26 | Wrong answer | 12ms | 5144 KiB | ||||
27 | Wrong answer | 7ms | 4908 KiB | ||||
subtask4 | 0/25 | ||||||
28 | Accepted | 3ms | 2468 KiB | ||||
29 | Accepted | 2ms | 2488 KiB | ||||
30 | Accepted | 3ms | 2492 KiB | ||||
31 | Accepted | 3ms | 2708 KiB | ||||
32 | Accepted | 3ms | 2908 KiB | ||||
33 | Wrong answer | 3ms | 3120 KiB | ||||
34 | Wrong answer | 3ms | 3380 KiB | ||||
35 | Accepted | 3ms | 3504 KiB | ||||
36 | Accepted | 39ms | 5644 KiB | ||||
37 | Accepted | 35ms | 5724 KiB | ||||
38 | Accepted | 39ms | 5872 KiB | ||||
39 | Accepted | 27ms | 5712 KiB | ||||
40 | Accepted | 14ms | 5436 KiB | ||||
41 | Accepted | 8ms | 5348 KiB | ||||
42 | Wrong answer | 37ms | 5904 KiB | ||||
43 | Accepted | 28ms | 6072 KiB | ||||
44 | Wrong answer | 28ms | 5996 KiB | ||||
45 | Wrong answer | 14ms | 5928 KiB | ||||
subtask5 | 24/24 | ||||||
46 | Accepted | 435ms | 5788 KiB | ||||
47 | Accepted | 379ms | 5916 KiB | ||||
48 | Accepted | 425ms | 6096 KiB | ||||
49 | Accepted | 393ms | 5964 KiB | ||||
50 | Accepted | 247ms | 5880 KiB | ||||
51 | Accepted | 432ms | 5768 KiB | ||||
52 | Accepted | 375ms | 5752 KiB | ||||
53 | Accepted | 421ms | 5916 KiB | ||||
54 | Accepted | 388ms | 5800 KiB | ||||
55 | Accepted | 244ms | 5668 KiB | ||||
subtask6 | 0/21 | ||||||
56 | Accepted | 3ms | 2468 KiB | ||||
57 | Accepted | 2ms | 2488 KiB | ||||
58 | Accepted | 3ms | 2492 KiB | ||||
59 | Accepted | 3ms | 2708 KiB | ||||
60 | Accepted | 3ms | 2908 KiB | ||||
61 | Wrong answer | 3ms | 3120 KiB | ||||
62 | Wrong answer | 3ms | 3380 KiB | ||||
63 | Accepted | 3ms | 3504 KiB | ||||
64 | Accepted | 4ms | 3656 KiB | ||||
65 | Accepted | 16ms | 4408 KiB | ||||
66 | Accepted | 14ms | 4320 KiB | ||||
67 | Accepted | 14ms | 4580 KiB | ||||
68 | Accepted | 7ms | 4480 KiB | ||||
69 | Wrong answer | 6ms | 4608 KiB | ||||
70 | Wrong answer | 14ms | 5080 KiB | ||||
71 | Wrong answer | 12ms | 5144 KiB | ||||
72 | Wrong answer | 7ms | 4908 KiB | ||||
73 | Accepted | 39ms | 5644 KiB | ||||
74 | Accepted | 35ms | 5724 KiB | ||||
75 | Accepted | 39ms | 5872 KiB | ||||
76 | Accepted | 27ms | 5712 KiB | ||||
77 | Accepted | 14ms | 5436 KiB | ||||
78 | Accepted | 8ms | 5348 KiB | ||||
79 | Wrong answer | 37ms | 5904 KiB | ||||
80 | Accepted | 28ms | 6072 KiB | ||||
81 | Wrong answer | 28ms | 5996 KiB | ||||
82 | Wrong answer | 14ms | 5928 KiB | ||||
83 | Accepted | 435ms | 5788 KiB | ||||
84 | Accepted | 379ms | 5916 KiB | ||||
85 | Accepted | 425ms | 6096 KiB | ||||
86 | Accepted | 393ms | 5964 KiB | ||||
87 | Accepted | 247ms | 5880 KiB | ||||
88 | Accepted | 432ms | 5768 KiB | ||||
89 | Accepted | 375ms | 5752 KiB | ||||
90 | Accepted | 421ms | 5916 KiB | ||||
91 | Accepted | 388ms | 5800 KiB | ||||
92 | Accepted | 244ms | 5668 KiB | ||||
93 | Accepted | 112ms | 7080 KiB | ||||
94 | Wrong answer | 109ms | 7220 KiB | ||||
95 | Wrong answer | 133ms | 7164 KiB | ||||
96 | Wrong answer | 140ms | 7196 KiB | ||||
97 | Wrong answer | 45ms | 6964 KiB | ||||
98 | Accepted | 109ms | 8228 KiB | ||||
99 | Accepted | 97ms | 6964 KiB | ||||
100 | Accepted | 759ms | 13296 KiB | ||||
101 | Accepted | 728ms | 13080 KiB | ||||
102 | Accepted | 677ms | 13020 KiB | ||||
103 | Accepted | 584ms | 13072 KiB | ||||
104 | Accepted | 449ms | 13180 KiB | ||||
105 | Accepted | 642ms | 13152 KiB | ||||
106 | Accepted | 572ms | 13148 KiB | ||||
107 | Accepted | 559ms | 13080 KiB | ||||
108 | Accepted | 688ms | 13080 KiB | ||||
109 | Accepted | 135ms | 5776 KiB | ||||
110 | Accepted | 375ms | 8504 KiB | ||||
111 | Accepted | 425ms | 5976 KiB | ||||
112 | Accepted | 340ms | 6104 KiB | ||||
113 | Accepted | 363ms | 5704 KiB | ||||
114 | Wrong answer | 633ms | 13104 KiB | ||||
115 | Wrong answer | 94ms | 6724 KiB | ||||
116 | Wrong answer | 96ms | 6648 KiB | ||||
117 | Wrong answer | 570ms | 13008 KiB | ||||
118 | Wrong answer | 192ms | 12744 KiB |