#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>
const ll inf = 1e18;
const int mxn = 5050;
const int b = 5;
vector<pll> paths[mxn];
ll dist[mxn][1<<b];
int N,M,Q,K;
namespace DIJKSTRA{
priority_queue<pll,vector<pll>,greater<pll>> pq;
void GO(vector<int> starts){
for(auto &i:dist){
for(auto &j:i)j = inf;
}
for(auto &i:starts){
dist[i][0] = 0;
pq.push(pll(0,i<<b));
}
while(!pq.empty()){
auto [d,now] = pq.top();
pq.pop();
int mask = now%(1<<b);
now>>=b;
if(dist[now][mask] != d)continue;
for(int i = 0;i<b;i++){
if(mask&(1<<i))continue;
int tm = mask^(1<<i);
for(auto [nxt,w]:paths[now]){
w = w*(100-10*(i+1))/100;
if(dist[nxt][tm]>d+w){
dist[nxt][tm] = d+w;
pq.push(pll(dist[nxt][tm],(nxt<<5)+tm));
}
}
}
for(auto [nxt,w]:paths[now]){
if(dist[nxt][mask]>d+w){
dist[nxt][mask] = d+w;
pq.push(pll(dist[nxt][mask],(nxt<<5)+mask));
}
}
}
return;
}
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>N>>M>>K;
vector<int> v;
for(int i = 0;i<K;i++){
int tmp;
cin>>tmp;
v.push_back(tmp);
}
for(int i = 0;i<M;i++){
int a,b,c;
cin>>a>>b>>c;
paths[b].push_back(pii(a,c));
}
DIJKSTRA::GO(v);
cin>>Q;
while(Q--){
int s,arr[b];
cin>>s;
for(auto &i:arr)cin>>i;
ll ans = inf;
for(int i = 0;i<(1<<b);i++){
ll cost = dist[s][i];
bool f = true;
for(int j = 0;j<b;j++){
if(i&(1<<j)){
if(arr[j] == -1)f = false;
cost += arr[j];
}
}
if(!f)continue;
ans = min(ans,cost);
}
cout<<(ans>=inf?-1:ans)<<'\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
3204 KB |
Output is correct |
2 |
Correct |
13 ms |
1880 KB |
Output is correct |
3 |
Correct |
37 ms |
3028 KB |
Output is correct |
4 |
Correct |
1 ms |
1624 KB |
Output is correct |
5 |
Correct |
1 ms |
1628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
3204 KB |
Output is correct |
2 |
Correct |
13 ms |
1880 KB |
Output is correct |
3 |
Correct |
37 ms |
3028 KB |
Output is correct |
4 |
Correct |
1 ms |
1624 KB |
Output is correct |
5 |
Correct |
1 ms |
1628 KB |
Output is correct |
6 |
Correct |
39 ms |
3032 KB |
Output is correct |
7 |
Correct |
13 ms |
1880 KB |
Output is correct |
8 |
Correct |
39 ms |
3032 KB |
Output is correct |
9 |
Correct |
1 ms |
1624 KB |
Output is correct |
10 |
Correct |
1 ms |
1624 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
3204 KB |
Output is correct |
2 |
Correct |
13 ms |
1880 KB |
Output is correct |
3 |
Correct |
37 ms |
3028 KB |
Output is correct |
4 |
Correct |
1 ms |
1624 KB |
Output is correct |
5 |
Correct |
1 ms |
1628 KB |
Output is correct |
6 |
Correct |
39 ms |
3032 KB |
Output is correct |
7 |
Correct |
13 ms |
1880 KB |
Output is correct |
8 |
Correct |
39 ms |
3032 KB |
Output is correct |
9 |
Correct |
1 ms |
1624 KB |
Output is correct |
10 |
Correct |
1 ms |
1624 KB |
Output is correct |
11 |
Correct |
73 ms |
8136 KB |
Output is correct |
12 |
Correct |
18 ms |
1880 KB |
Output is correct |
13 |
Correct |
49 ms |
3124 KB |
Output is correct |
14 |
Correct |
1 ms |
1880 KB |
Output is correct |
15 |
Correct |
1 ms |
1628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
3204 KB |
Output is correct |
2 |
Correct |
13 ms |
1880 KB |
Output is correct |
3 |
Correct |
37 ms |
3028 KB |
Output is correct |
4 |
Correct |
1 ms |
1624 KB |
Output is correct |
5 |
Correct |
1 ms |
1628 KB |
Output is correct |
6 |
Correct |
3 ms |
1880 KB |
Output is correct |
7 |
Correct |
14 ms |
1880 KB |
Output is correct |
8 |
Correct |
42 ms |
3440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
3204 KB |
Output is correct |
2 |
Correct |
13 ms |
1880 KB |
Output is correct |
3 |
Correct |
37 ms |
3028 KB |
Output is correct |
4 |
Correct |
1 ms |
1624 KB |
Output is correct |
5 |
Correct |
1 ms |
1628 KB |
Output is correct |
6 |
Correct |
39 ms |
3032 KB |
Output is correct |
7 |
Correct |
13 ms |
1880 KB |
Output is correct |
8 |
Correct |
39 ms |
3032 KB |
Output is correct |
9 |
Correct |
1 ms |
1624 KB |
Output is correct |
10 |
Correct |
1 ms |
1624 KB |
Output is correct |
11 |
Correct |
3 ms |
1880 KB |
Output is correct |
12 |
Correct |
14 ms |
1880 KB |
Output is correct |
13 |
Correct |
42 ms |
3440 KB |
Output is correct |
14 |
Correct |
36 ms |
3648 KB |
Output is correct |
15 |
Correct |
15 ms |
1880 KB |
Output is correct |
16 |
Correct |
44 ms |
3288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
4308 KB |
Output is correct |
2 |
Correct |
62 ms |
7888 KB |
Output is correct |
3 |
Correct |
29 ms |
2396 KB |
Output is correct |
4 |
Correct |
46 ms |
3288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2140 KB |
Output is correct |
2 |
Correct |
3 ms |
2140 KB |
Output is correct |
3 |
Correct |
2 ms |
1624 KB |
Output is correct |
4 |
Correct |
3 ms |
2140 KB |
Output is correct |
5 |
Correct |
3 ms |
2140 KB |
Output is correct |
6 |
Correct |
1 ms |
1864 KB |
Output is correct |
7 |
Correct |
3 ms |
2140 KB |
Output is correct |
8 |
Correct |
3 ms |
2140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
3204 KB |
Output is correct |
2 |
Correct |
13 ms |
1880 KB |
Output is correct |
3 |
Correct |
37 ms |
3028 KB |
Output is correct |
4 |
Correct |
1 ms |
1624 KB |
Output is correct |
5 |
Correct |
1 ms |
1628 KB |
Output is correct |
6 |
Correct |
39 ms |
3032 KB |
Output is correct |
7 |
Correct |
13 ms |
1880 KB |
Output is correct |
8 |
Correct |
39 ms |
3032 KB |
Output is correct |
9 |
Correct |
1 ms |
1624 KB |
Output is correct |
10 |
Correct |
1 ms |
1624 KB |
Output is correct |
11 |
Correct |
73 ms |
8136 KB |
Output is correct |
12 |
Correct |
18 ms |
1880 KB |
Output is correct |
13 |
Correct |
49 ms |
3124 KB |
Output is correct |
14 |
Correct |
1 ms |
1880 KB |
Output is correct |
15 |
Correct |
1 ms |
1628 KB |
Output is correct |
16 |
Correct |
3 ms |
1880 KB |
Output is correct |
17 |
Correct |
14 ms |
1880 KB |
Output is correct |
18 |
Correct |
42 ms |
3440 KB |
Output is correct |
19 |
Correct |
36 ms |
3648 KB |
Output is correct |
20 |
Correct |
15 ms |
1880 KB |
Output is correct |
21 |
Correct |
44 ms |
3288 KB |
Output is correct |
22 |
Correct |
52 ms |
4308 KB |
Output is correct |
23 |
Correct |
62 ms |
7888 KB |
Output is correct |
24 |
Correct |
29 ms |
2396 KB |
Output is correct |
25 |
Correct |
46 ms |
3288 KB |
Output is correct |
26 |
Correct |
4 ms |
2140 KB |
Output is correct |
27 |
Correct |
3 ms |
2140 KB |
Output is correct |
28 |
Correct |
2 ms |
1624 KB |
Output is correct |
29 |
Correct |
3 ms |
2140 KB |
Output is correct |
30 |
Correct |
3 ms |
2140 KB |
Output is correct |
31 |
Correct |
1 ms |
1864 KB |
Output is correct |
32 |
Correct |
3 ms |
2140 KB |
Output is correct |
33 |
Correct |
3 ms |
2140 KB |
Output is correct |
34 |
Correct |
1 ms |
1624 KB |
Output is correct |
35 |
Correct |
1 ms |
1628 KB |
Output is correct |
36 |
Correct |
1 ms |
1628 KB |
Output is correct |
37 |
Correct |
60 ms |
8348 KB |
Output is correct |
38 |
Correct |
66 ms |
8392 KB |
Output is correct |
39 |
Correct |
43 ms |
3284 KB |
Output is correct |
40 |
Correct |
1 ms |
1628 KB |
Output is correct |
41 |
Correct |
2 ms |
1920 KB |
Output is correct |
42 |
Correct |
64 ms |
6352 KB |
Output is correct |
43 |
Correct |
65 ms |
8488 KB |
Output is correct |
44 |
Correct |
44 ms |
3288 KB |
Output is correct |
45 |
Correct |
30 ms |
2312 KB |
Output is correct |