// 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>
#define fi first
#define se second
#define pb push_back
#define pf push_front
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll Nmax=5e3, inf=(ll)1e18;
int n, m, k, q, st, p[5];
bool fn[Nmax];
ll dist[32][Nmax];
vector<pii> ad[Nmax];
struct info{
int 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;
int nr;
for (int i=0; i<k; i++){
cin>>nr;
fn[nr]=1;
}
int 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++){
int newtip=(crt.tip | (1<<t));
ll newcost=crt.cost+it.se-(ll)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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1884 KB |
Output is correct |
2 |
Correct |
2 ms |
1884 KB |
Output is correct |
3 |
Correct |
3 ms |
1884 KB |
Output is correct |
4 |
Correct |
0 ms |
604 KB |
Output is correct |
5 |
Correct |
0 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1884 KB |
Output is correct |
2 |
Correct |
2 ms |
1884 KB |
Output is correct |
3 |
Correct |
3 ms |
1884 KB |
Output is correct |
4 |
Correct |
0 ms |
604 KB |
Output is correct |
5 |
Correct |
0 ms |
604 KB |
Output is correct |
6 |
Correct |
18 ms |
2040 KB |
Output is correct |
7 |
Correct |
17 ms |
1884 KB |
Output is correct |
8 |
Correct |
36 ms |
2036 KB |
Output is correct |
9 |
Correct |
0 ms |
604 KB |
Output is correct |
10 |
Correct |
0 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1884 KB |
Output is correct |
2 |
Correct |
2 ms |
1884 KB |
Output is correct |
3 |
Correct |
3 ms |
1884 KB |
Output is correct |
4 |
Correct |
0 ms |
604 KB |
Output is correct |
5 |
Correct |
0 ms |
604 KB |
Output is correct |
6 |
Correct |
18 ms |
2040 KB |
Output is correct |
7 |
Correct |
17 ms |
1884 KB |
Output is correct |
8 |
Correct |
36 ms |
2036 KB |
Output is correct |
9 |
Correct |
0 ms |
604 KB |
Output is correct |
10 |
Correct |
0 ms |
600 KB |
Output is correct |
11 |
Correct |
9 ms |
1884 KB |
Output is correct |
12 |
Correct |
11 ms |
1884 KB |
Output is correct |
13 |
Correct |
11 ms |
1884 KB |
Output is correct |
14 |
Correct |
0 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1884 KB |
Output is correct |
2 |
Correct |
2 ms |
1884 KB |
Output is correct |
3 |
Correct |
3 ms |
1884 KB |
Output is correct |
4 |
Correct |
0 ms |
604 KB |
Output is correct |
5 |
Correct |
0 ms |
604 KB |
Output is correct |
6 |
Correct |
48 ms |
4048 KB |
Output is correct |
7 |
Correct |
5 ms |
1884 KB |
Output is correct |
8 |
Correct |
9 ms |
2520 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1884 KB |
Output is correct |
2 |
Correct |
2 ms |
1884 KB |
Output is correct |
3 |
Correct |
3 ms |
1884 KB |
Output is correct |
4 |
Correct |
0 ms |
604 KB |
Output is correct |
5 |
Correct |
0 ms |
604 KB |
Output is correct |
6 |
Correct |
18 ms |
2040 KB |
Output is correct |
7 |
Correct |
17 ms |
1884 KB |
Output is correct |
8 |
Correct |
36 ms |
2036 KB |
Output is correct |
9 |
Correct |
0 ms |
604 KB |
Output is correct |
10 |
Correct |
0 ms |
600 KB |
Output is correct |
11 |
Correct |
48 ms |
4048 KB |
Output is correct |
12 |
Correct |
5 ms |
1884 KB |
Output is correct |
13 |
Correct |
9 ms |
2520 KB |
Output is correct |
14 |
Execution timed out |
1064 ms |
4044 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
1884 KB |
Output is correct |
2 |
Correct |
9 ms |
1880 KB |
Output is correct |
3 |
Correct |
8 ms |
1884 KB |
Output is correct |
4 |
Correct |
26 ms |
2116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
604 KB |
Output is correct |
2 |
Correct |
3 ms |
604 KB |
Output is correct |
3 |
Correct |
3 ms |
604 KB |
Output is correct |
4 |
Correct |
3 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1884 KB |
Output is correct |
2 |
Correct |
2 ms |
1884 KB |
Output is correct |
3 |
Correct |
3 ms |
1884 KB |
Output is correct |
4 |
Correct |
0 ms |
604 KB |
Output is correct |
5 |
Correct |
0 ms |
604 KB |
Output is correct |
6 |
Correct |
18 ms |
2040 KB |
Output is correct |
7 |
Correct |
17 ms |
1884 KB |
Output is correct |
8 |
Correct |
36 ms |
2036 KB |
Output is correct |
9 |
Correct |
0 ms |
604 KB |
Output is correct |
10 |
Correct |
0 ms |
600 KB |
Output is correct |
11 |
Correct |
9 ms |
1884 KB |
Output is correct |
12 |
Correct |
11 ms |
1884 KB |
Output is correct |
13 |
Correct |
11 ms |
1884 KB |
Output is correct |
14 |
Correct |
0 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
48 ms |
4048 KB |
Output is correct |
17 |
Correct |
5 ms |
1884 KB |
Output is correct |
18 |
Correct |
9 ms |
2520 KB |
Output is correct |
19 |
Execution timed out |
1064 ms |
4044 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |