#include <bits/stdc++.h>
#define ll long long
#define MAXN 5010
#define llinf 1e17
using namespace std;
ll n,k,t[MAXN],p[10];
vector<pair<ll,ll> > G[MAXN];
ll dist[MAXN][50];
void Dijkstra()
{
for (ll i=1;i<=n;i++)
{
for (ll j=0;j<(1<<5);j++)
dist[i][j]=llinf;
}
priority_queue<pair<ll,pair<ll,ll> >,vector<pair<ll,pair<ll,ll> > >,greater<pair<ll,pair<ll,ll> > > > q;
for (ll i=1;i<=k;i++)
{
for (ll j=0;j<(1<<5);j++)
{
ll price=0;
bool ok=true;
for (ll l=0;l<5;l++)
{
if (((1<<l)&j) && p[l]==-1)
{
ok=false;
break;
}
if (((1<<l)&j))
price+=p[l];
}
if (!ok)
continue;
dist[t[i]][j]=price;
q.push({price,{t[i],j}});
}
}
while (!q.empty())
{
ll cur=q.top().first,i=q.top().second.first,j=q.top().second.second;
q.pop();
if (dist[i][j]!=cur)
continue;
for (auto next : G[i])
{
if (dist[next.first][j]>cur+next.second)
{
dist[next.first][j]=cur+next.second;
q.push({dist[next.first][j],{next.first,j}});
}
for (ll l=0;l<5;l++)
{
if (!((1<<l)&j))
continue;
if (dist[next.first][j^(1<<l)]>cur+next.second*(9-l)/10)
{
dist[next.first][j^(1<<l)]=cur+next.second*(9-l)/10;
q.push({dist[next.first][j^(1<<l)],{next.first,j^(1<<l)}});
}
}
}
}
}
int main()
{
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
ll e,u,v,c,q,s;
cin >> n >> e >> k;
for (ll i=1;i<=k;i++)
{
cin >> t[i];
t[i]++;
}
for (ll i=1;i<=e;i++)
{
cin >> u >> v >> c;
u++;
v++;
G[v].push_back({u,c});
}
cin >> q;
while (q--)
{
cin >> s;
s++;
for (ll i=0;i<5;i++)
cin >> p[i];
Dijkstra();
cout << (dist[s][0]==llinf?-1 : dist[s][0]) << "\n";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |