#include <crocodile.h>
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
#define itr ::iterator
typedef pair<ll,ll> pii;
const ll MAX=1e6;
const ll INF=2e9;
vector<pii> vec[MAX];
ll mark[MAX],dp[MAX],mn[MAX];
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
for(int A=0;A<M;A++)
{
vec[R[A][0]].pb(mp(R[A][1],L[A]));
vec[R[A][1]].pb(mp(R[A][0],L[A]));
}
for(int A=0;A<N;A++)
{
mn[A]=-1;
dp[A]=-1;
}
priority_queue<pii,vector<pii>,greater<pii>> pq;
for(int A=0;A<K;A++)
{
dp[P[A]]=0;
mn[P[A]]=0;
pq.push(mp(0,P[A]));
}
while(!pq.empty())
{
pii cur=pq.top();
pq.pop();
if(cur.first>dp[cur.second])
continue;
for(auto A:vec[cur.second])
{
if(dp[A.first]==-1)
{
dp[A.first]=INF;
mn[A.first]=cur.first+A.second;
}
else if(cur.first+A.second<dp[A.first])
{
dp[A.first]=cur.first+A.second;
if(dp[A.first]<mn[A.first])
swap(dp[A.first],mn[A.first]);
pq.push(mp(dp[A.first],A.first));
}
}
}
return dp[0];
}
/*signed main()
{
ios_base::sync_with_stdio(false);
int R[][2]={{0,2},{0,3},{3,2},{2,1},{0,1},{0,4},{3,4}};
int L[]={4,3,2,10,100,7,9};
int P[]={1,3};
cout<<travel_plan(5,7,R,L,2,P);
return 0;
}*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
23764 KB |
Output is correct |
2 |
Correct |
23 ms |
23912 KB |
Output is correct |
3 |
Correct |
26 ms |
24096 KB |
Output is correct |
4 |
Correct |
24 ms |
24096 KB |
Output is correct |
5 |
Correct |
24 ms |
24096 KB |
Output is correct |
6 |
Correct |
24 ms |
24096 KB |
Output is correct |
7 |
Correct |
26 ms |
24100 KB |
Output is correct |
8 |
Correct |
25 ms |
24172 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
23764 KB |
Output is correct |
2 |
Correct |
23 ms |
23912 KB |
Output is correct |
3 |
Correct |
26 ms |
24096 KB |
Output is correct |
4 |
Correct |
24 ms |
24096 KB |
Output is correct |
5 |
Correct |
24 ms |
24096 KB |
Output is correct |
6 |
Correct |
24 ms |
24096 KB |
Output is correct |
7 |
Correct |
26 ms |
24100 KB |
Output is correct |
8 |
Correct |
25 ms |
24172 KB |
Output is correct |
9 |
Correct |
29 ms |
24356 KB |
Output is correct |
10 |
Correct |
29 ms |
24356 KB |
Output is correct |
11 |
Correct |
25 ms |
24356 KB |
Output is correct |
12 |
Correct |
29 ms |
24684 KB |
Output is correct |
13 |
Correct |
34 ms |
24812 KB |
Output is correct |
14 |
Correct |
26 ms |
24812 KB |
Output is correct |
15 |
Correct |
26 ms |
24812 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
23764 KB |
Output is correct |
2 |
Correct |
23 ms |
23912 KB |
Output is correct |
3 |
Correct |
26 ms |
24096 KB |
Output is correct |
4 |
Correct |
24 ms |
24096 KB |
Output is correct |
5 |
Correct |
24 ms |
24096 KB |
Output is correct |
6 |
Correct |
24 ms |
24096 KB |
Output is correct |
7 |
Correct |
26 ms |
24100 KB |
Output is correct |
8 |
Correct |
25 ms |
24172 KB |
Output is correct |
9 |
Correct |
29 ms |
24356 KB |
Output is correct |
10 |
Correct |
29 ms |
24356 KB |
Output is correct |
11 |
Correct |
25 ms |
24356 KB |
Output is correct |
12 |
Correct |
29 ms |
24684 KB |
Output is correct |
13 |
Correct |
34 ms |
24812 KB |
Output is correct |
14 |
Correct |
26 ms |
24812 KB |
Output is correct |
15 |
Correct |
26 ms |
24812 KB |
Output is correct |
16 |
Correct |
948 ms |
87940 KB |
Output is correct |
17 |
Correct |
188 ms |
87940 KB |
Output is correct |
18 |
Correct |
194 ms |
87940 KB |
Output is correct |
19 |
Correct |
1032 ms |
94292 KB |
Output is correct |
20 |
Correct |
424 ms |
94292 KB |
Output is correct |
21 |
Correct |
108 ms |
94292 KB |
Output is correct |
22 |
Incorrect |
461 ms |
94292 KB |
Output isn't correct |