#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)
{
d[v.fi][1]=d[v.fi][0];
d[v.fi][0]=ndist;
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 |
2 ms |
2688 KB |
Output is correct |
4 |
Correct |
3 ms |
2816 KB |
Output is correct |
5 |
Correct |
3 ms |
2752 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 |
2 ms |
2688 KB |
Output is correct |
4 |
Correct |
3 ms |
2816 KB |
Output is correct |
5 |
Correct |
3 ms |
2752 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 |
4 ms |
2944 KB |
Output is correct |
10 |
Correct |
4 ms |
2720 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 |
2 ms |
2688 KB |
Output is correct |
15 |
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 |
2 ms |
2688 KB |
Output is correct |
4 |
Correct |
3 ms |
2816 KB |
Output is correct |
5 |
Correct |
3 ms |
2752 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 |
4 ms |
2944 KB |
Output is correct |
10 |
Correct |
4 ms |
2720 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 |
2 ms |
2688 KB |
Output is correct |
15 |
Correct |
3 ms |
2816 KB |
Output is correct |
16 |
Correct |
580 ms |
44396 KB |
Output is correct |
17 |
Correct |
112 ms |
13424 KB |
Output is correct |
18 |
Correct |
138 ms |
14832 KB |
Output is correct |
19 |
Correct |
790 ms |
51724 KB |
Output is correct |
20 |
Correct |
338 ms |
36728 KB |
Output is correct |
21 |
Correct |
52 ms |
7168 KB |
Output is correct |
22 |
Incorrect |
372 ms |
32632 KB |
Output isn't correct |