// Author: Tanasescu Andrei-Rares
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <iomanip>
#include <vector>
#include <cassert>
#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define pf push_front
using namespace std;
ifstream fin ("");
ofstream fout ("");
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll Nmax=5e3, inf=(ll)1e18;
ll n, m, k, q, st, p[5];
bool fn[Nmax];
ll dist[32][Nmax];
vector<pll> ad[Nmax];
struct info{
ll nod, tip;
ll cost;
bool operator<(const info &nxt)const{
return cost>nxt.cost;
}
};
priority_queue<info> pq;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>m>>k;
ll nr;
for (int i=0; i<k; i++){
cin>>nr;
fn[nr]=1;
}
ll a, b, c;
for (int i=0; i<m; i++){
cin>>a>>b>>c;
ad[a].pb({b, c});
}
cin>>q;
while (q--){
cin>>st;
for (int i=0; i<5; i++)
cin>>p[i];
for (int i=0; i<n; i++)
for (int j=0; j<32; j++)
dist[j][i]=inf;
dist[0][st]=0;
pq.push({st, 0, 0});
while (!pq.empty() && !fn[pq.top().nod]){
info crt=pq.top();
pq.pop();
for (auto it:ad[crt.nod]){
if (dist[crt.tip][it.fi]>crt.cost+it.se){
dist[crt.tip][it.fi]=crt.cost+it.se;
pq.push({it.fi, crt.tip, crt.cost+it.se});
}
for (int t=0; t<5; t++){
ll newtip=(crt.tip | (1<<t));
ll newcost=crt.cost+it.se-it.se*(t+1)/10+p[t];
if (p[t]!=-1 && newtip!=crt.tip && dist[newtip][it.fi]>newcost){
dist[newtip][it.fi]=newcost;
pq.push({it.fi, newtip, newcost});
}
}
}
}
if (pq.empty())
cout<<"-1\n";
else{
cout<<pq.top().cost<<'\n';
while (!pq.empty())
pq.pop();
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1880 KB |
Output is correct |
2 |
Correct |
2 ms |
1884 KB |
Output is correct |
3 |
Correct |
4 ms |
2140 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
0 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1880 KB |
Output is correct |
2 |
Correct |
2 ms |
1884 KB |
Output is correct |
3 |
Correct |
4 ms |
2140 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
0 ms |
604 KB |
Output is correct |
6 |
Correct |
17 ms |
1880 KB |
Output is correct |
7 |
Correct |
15 ms |
1884 KB |
Output is correct |
8 |
Correct |
37 ms |
2140 KB |
Output is correct |
9 |
Correct |
0 ms |
604 KB |
Output is correct |
10 |
Correct |
0 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1880 KB |
Output is correct |
2 |
Correct |
2 ms |
1884 KB |
Output is correct |
3 |
Correct |
4 ms |
2140 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
0 ms |
604 KB |
Output is correct |
6 |
Correct |
17 ms |
1880 KB |
Output is correct |
7 |
Correct |
15 ms |
1884 KB |
Output is correct |
8 |
Correct |
37 ms |
2140 KB |
Output is correct |
9 |
Correct |
0 ms |
604 KB |
Output is correct |
10 |
Correct |
0 ms |
604 KB |
Output is correct |
11 |
Correct |
7 ms |
1884 KB |
Output is correct |
12 |
Correct |
9 ms |
1884 KB |
Output is correct |
13 |
Correct |
11 ms |
2140 KB |
Output is correct |
14 |
Correct |
0 ms |
604 KB |
Output is correct |
15 |
Correct |
0 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1880 KB |
Output is correct |
2 |
Correct |
2 ms |
1884 KB |
Output is correct |
3 |
Correct |
4 ms |
2140 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
0 ms |
604 KB |
Output is correct |
6 |
Correct |
53 ms |
5072 KB |
Output is correct |
7 |
Correct |
6 ms |
1880 KB |
Output is correct |
8 |
Correct |
10 ms |
2904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1880 KB |
Output is correct |
2 |
Correct |
2 ms |
1884 KB |
Output is correct |
3 |
Correct |
4 ms |
2140 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
0 ms |
604 KB |
Output is correct |
6 |
Correct |
17 ms |
1880 KB |
Output is correct |
7 |
Correct |
15 ms |
1884 KB |
Output is correct |
8 |
Correct |
37 ms |
2140 KB |
Output is correct |
9 |
Correct |
0 ms |
604 KB |
Output is correct |
10 |
Correct |
0 ms |
604 KB |
Output is correct |
11 |
Correct |
53 ms |
5072 KB |
Output is correct |
12 |
Correct |
6 ms |
1880 KB |
Output is correct |
13 |
Correct |
10 ms |
2904 KB |
Output is correct |
14 |
Execution timed out |
1039 ms |
5736 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
1880 KB |
Output is correct |
2 |
Correct |
7 ms |
2216 KB |
Output is correct |
3 |
Correct |
6 ms |
1884 KB |
Output is correct |
4 |
Correct |
27 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
604 KB |
Output is correct |
2 |
Correct |
3 ms |
860 KB |
Output is correct |
3 |
Correct |
3 ms |
600 KB |
Output is correct |
4 |
Correct |
2 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
588 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1880 KB |
Output is correct |
2 |
Correct |
2 ms |
1884 KB |
Output is correct |
3 |
Correct |
4 ms |
2140 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
0 ms |
604 KB |
Output is correct |
6 |
Correct |
17 ms |
1880 KB |
Output is correct |
7 |
Correct |
15 ms |
1884 KB |
Output is correct |
8 |
Correct |
37 ms |
2140 KB |
Output is correct |
9 |
Correct |
0 ms |
604 KB |
Output is correct |
10 |
Correct |
0 ms |
604 KB |
Output is correct |
11 |
Correct |
7 ms |
1884 KB |
Output is correct |
12 |
Correct |
9 ms |
1884 KB |
Output is correct |
13 |
Correct |
11 ms |
2140 KB |
Output is correct |
14 |
Correct |
0 ms |
604 KB |
Output is correct |
15 |
Correct |
0 ms |
604 KB |
Output is correct |
16 |
Correct |
53 ms |
5072 KB |
Output is correct |
17 |
Correct |
6 ms |
1880 KB |
Output is correct |
18 |
Correct |
10 ms |
2904 KB |
Output is correct |
19 |
Execution timed out |
1039 ms |
5736 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |