#include "crocodile.h"
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
typedef pair <int,int> ii;
const char nl='\n';
ii dp[100005][2];
vector <int > gg;
vector <ii> vt[100005];
int n;
int dijkstra()
{
for (int i=0;i<n;i++)
{
dp[i][0]=dp[i][1]={1e9+5,-1};
}
priority_queue<ii,vector <ii> ,greater <ii> > qu;
for (auto v:gg)
{
dp[v][0]=dp[v][1]={0,-1};
qu.push({0,v});
}
while (!qu.empty())
{
int aa=qu.top().fi;
int u=qu.top().se;
qu.pop();
if (u==0)
{
return aa;
}
if (aa!=dp[u][1].fi){continue;}
for (auto v:vt[u])
{
if (dp[v.fi][0].fi>dp[u][1].fi+v.se)
{
if (dp[v.fi][1].fi>dp[v.fi][0].fi)
{
dp[v.fi][1]=dp[v.fi][0];
dp[v.fi][0]={dp[u][1].fi+v.se,u};
qu.push({dp[v.fi][1].fi,v.fi});
}
else
{
dp[v.fi][0]={dp[u][1].fi+v.se,u};
}
}
else if (dp[v.fi][1].fi>dp[u][1].fi+v.se)
{
dp[v.fi][1]={dp[u][1].fi+v.se,u};
qu.push({dp[v.fi][1].fi,v.fi});
}
}
}
}
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
n=N;
for (int i=0;i<M;i++)
{
int aa=R[i][0];
int bb=R[i][1];
int cc=L[i];
vt[aa].pb({bb,cc});
vt[bb].pb({aa,cc});
}
for (int i=0;i<K;i++)
{
gg.pb(P[i]);
}
return dijkstra();
}
Compilation message
crocodile.cpp: In function 'int dijkstra()':
crocodile.cpp:20:51: warning: control reaches end of non-void function [-Wreturn-type]
20 | priority_queue<ii,vector <ii> ,greater <ii> > qu;
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
3 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
2 ms |
2644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
3 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
2 ms |
2644 KB |
Output is correct |
9 |
Correct |
3 ms |
2900 KB |
Output is correct |
10 |
Correct |
2 ms |
2644 KB |
Output is correct |
11 |
Correct |
2 ms |
2772 KB |
Output is correct |
12 |
Correct |
6 ms |
3028 KB |
Output is correct |
13 |
Correct |
5 ms |
3120 KB |
Output is correct |
14 |
Correct |
2 ms |
2644 KB |
Output is correct |
15 |
Correct |
4 ms |
2644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
3 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
2 ms |
2644 KB |
Output is correct |
9 |
Correct |
3 ms |
2900 KB |
Output is correct |
10 |
Correct |
2 ms |
2644 KB |
Output is correct |
11 |
Correct |
2 ms |
2772 KB |
Output is correct |
12 |
Correct |
6 ms |
3028 KB |
Output is correct |
13 |
Correct |
5 ms |
3120 KB |
Output is correct |
14 |
Correct |
2 ms |
2644 KB |
Output is correct |
15 |
Correct |
4 ms |
2644 KB |
Output is correct |
16 |
Correct |
356 ms |
41408 KB |
Output is correct |
17 |
Correct |
61 ms |
11216 KB |
Output is correct |
18 |
Correct |
71 ms |
12484 KB |
Output is correct |
19 |
Correct |
445 ms |
45596 KB |
Output is correct |
20 |
Correct |
253 ms |
36608 KB |
Output is correct |
21 |
Correct |
42 ms |
6484 KB |
Output is correct |
22 |
Correct |
283 ms |
32076 KB |
Output is correct |