#include<bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
using namespace std;
const int N=1e5+5;
long long d[N][2];
vector<pii>adj[N];
int travel_plan(int N,int M,int R[][2],int L[],int K,int P[])
{
for(int i=0;i<M;i++)
{
int u=R[i][0];
int v=R[i][1];
int w=L[i];
adj[u].push_back(mp(v,w));
adj[v].push_back(mp(u,w));
}
priority_queue<pair<long long,int>,vector<pair<long long,int>>,greater<pair<long long,int>>>pq;
for(int i=0;i<N;i++) d[i][0]=d[i][1]=1e18;
for(int i=0;i<K;i++)
{
d[P[i]][0]=d[P[i]][1]=0;
pq.push(mp(0,P[i]));
}
while(!pq.empty())
{
int u=pq.top().se;
long long dist=pq.top().fi;
pq.pop();
if(d[u][1]!=dist) continue;
for(auto&v:adj[u])
{
long long ndist=dist+v.se;
if(d[v.fi][0]>=ndist)
{
int pre=d[v.fi][1];
d[v.fi][1]=d[v.fi][0];
d[v.fi][0]=ndist;
if(d[v.fi][1]!=pre&&d[v.fi][1]!=1e18) pq.push(mp(d[v.fi][1],v.fi));
}
else if(d[v.fi][1]>ndist)
{
d[v.fi][1]=ndist;
pq.push(mp(d[v.fi][1],v.fi));
}
}
}
return d[0][1];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2688 KB |
Output is correct |
2 |
Correct |
2 ms |
2688 KB |
Output is correct |
3 |
Correct |
3 ms |
2688 KB |
Output is correct |
4 |
Correct |
3 ms |
2816 KB |
Output is correct |
5 |
Correct |
3 ms |
2816 KB |
Output is correct |
6 |
Correct |
3 ms |
2688 KB |
Output is correct |
7 |
Correct |
3 ms |
2816 KB |
Output is correct |
8 |
Correct |
3 ms |
2816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2688 KB |
Output is correct |
2 |
Correct |
2 ms |
2688 KB |
Output is correct |
3 |
Correct |
3 ms |
2688 KB |
Output is correct |
4 |
Correct |
3 ms |
2816 KB |
Output is correct |
5 |
Correct |
3 ms |
2816 KB |
Output is correct |
6 |
Correct |
3 ms |
2688 KB |
Output is correct |
7 |
Correct |
3 ms |
2816 KB |
Output is correct |
8 |
Correct |
3 ms |
2816 KB |
Output is correct |
9 |
Correct |
5 ms |
2944 KB |
Output is correct |
10 |
Correct |
2 ms |
2688 KB |
Output is correct |
11 |
Correct |
3 ms |
2816 KB |
Output is correct |
12 |
Correct |
6 ms |
3072 KB |
Output is correct |
13 |
Correct |
6 ms |
3072 KB |
Output is correct |
14 |
Correct |
3 ms |
2688 KB |
Output is correct |
15 |
Correct |
4 ms |
2816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2688 KB |
Output is correct |
2 |
Correct |
2 ms |
2688 KB |
Output is correct |
3 |
Correct |
3 ms |
2688 KB |
Output is correct |
4 |
Correct |
3 ms |
2816 KB |
Output is correct |
5 |
Correct |
3 ms |
2816 KB |
Output is correct |
6 |
Correct |
3 ms |
2688 KB |
Output is correct |
7 |
Correct |
3 ms |
2816 KB |
Output is correct |
8 |
Correct |
3 ms |
2816 KB |
Output is correct |
9 |
Correct |
5 ms |
2944 KB |
Output is correct |
10 |
Correct |
2 ms |
2688 KB |
Output is correct |
11 |
Correct |
3 ms |
2816 KB |
Output is correct |
12 |
Correct |
6 ms |
3072 KB |
Output is correct |
13 |
Correct |
6 ms |
3072 KB |
Output is correct |
14 |
Correct |
3 ms |
2688 KB |
Output is correct |
15 |
Correct |
4 ms |
2816 KB |
Output is correct |
16 |
Correct |
609 ms |
42480 KB |
Output is correct |
17 |
Correct |
95 ms |
11256 KB |
Output is correct |
18 |
Correct |
121 ms |
12664 KB |
Output is correct |
19 |
Correct |
742 ms |
47852 KB |
Output is correct |
20 |
Correct |
370 ms |
36696 KB |
Output is correct |
21 |
Correct |
51 ms |
6520 KB |
Output is correct |
22 |
Correct |
405 ms |
32376 KB |
Output is correct |