#include "crocodile.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpi;
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)
#define pb push_back
#define rsz resize
#define sz(x) int(x.size())
#define all(x) begin(x), end(x)
#define fi first
#define se second
int const n=1e5+4;
vpi adj[n];
bitset<n> vis;
pii d[n];
int const INF=2e9;
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
F0R(i,M)
{
int u=R[i][0];
int v=R[i][1];
int w=L[i];
adj[u].pb({v,w});
adj[v].pb({u,w});
}
F0R(i,N)
{
d[i]={INF,INF};
}
priority_queue<pii>q;
F0R(i,K)
{
d[P[i]].fi=0;
d[P[i]].se=0;
q.push({0,P[i]});
}
while(!vis[0])
{
int u = q.top().se;
q.pop();
if(vis[u])continue;
vis[u]=1;
trav(e,adj[u])
{
int cand = d[u].se+e.se;
if(cand < d[e.fi].se)
{
if(cand<d[e.fi].fi)
{
d[e.fi].se=d[e.fi].fi;
d[e.fi].fi=cand;
}
else
{
d[e.fi].se=cand;
}
q.push({-d[e.fi].se,e.fi});
}
}
}
return d[0].se;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2652 KB |
Output is correct |
3 |
Correct |
2 ms |
2660 KB |
Output is correct |
4 |
Correct |
3 ms |
2672 KB |
Output is correct |
5 |
Correct |
3 ms |
2664 KB |
Output is correct |
6 |
Correct |
3 ms |
2664 KB |
Output is correct |
7 |
Correct |
3 ms |
2668 KB |
Output is correct |
8 |
Correct |
3 ms |
2672 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2652 KB |
Output is correct |
3 |
Correct |
2 ms |
2660 KB |
Output is correct |
4 |
Correct |
3 ms |
2672 KB |
Output is correct |
5 |
Correct |
3 ms |
2664 KB |
Output is correct |
6 |
Correct |
3 ms |
2664 KB |
Output is correct |
7 |
Correct |
3 ms |
2668 KB |
Output is correct |
8 |
Correct |
3 ms |
2672 KB |
Output is correct |
9 |
Correct |
4 ms |
2892 KB |
Output is correct |
10 |
Correct |
2 ms |
2764 KB |
Output is correct |
11 |
Correct |
3 ms |
2764 KB |
Output is correct |
12 |
Correct |
6 ms |
3172 KB |
Output is correct |
13 |
Correct |
5 ms |
3148 KB |
Output is correct |
14 |
Correct |
2 ms |
2636 KB |
Output is correct |
15 |
Correct |
3 ms |
2764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2652 KB |
Output is correct |
3 |
Correct |
2 ms |
2660 KB |
Output is correct |
4 |
Correct |
3 ms |
2672 KB |
Output is correct |
5 |
Correct |
3 ms |
2664 KB |
Output is correct |
6 |
Correct |
3 ms |
2664 KB |
Output is correct |
7 |
Correct |
3 ms |
2668 KB |
Output is correct |
8 |
Correct |
3 ms |
2672 KB |
Output is correct |
9 |
Correct |
4 ms |
2892 KB |
Output is correct |
10 |
Correct |
2 ms |
2764 KB |
Output is correct |
11 |
Correct |
3 ms |
2764 KB |
Output is correct |
12 |
Correct |
6 ms |
3172 KB |
Output is correct |
13 |
Correct |
5 ms |
3148 KB |
Output is correct |
14 |
Correct |
2 ms |
2636 KB |
Output is correct |
15 |
Correct |
3 ms |
2764 KB |
Output is correct |
16 |
Correct |
415 ms |
46600 KB |
Output is correct |
17 |
Correct |
116 ms |
14896 KB |
Output is correct |
18 |
Correct |
93 ms |
15868 KB |
Output is correct |
19 |
Correct |
508 ms |
51352 KB |
Output is correct |
20 |
Correct |
297 ms |
41144 KB |
Output is correct |
21 |
Correct |
43 ms |
8004 KB |
Output is correct |
22 |
Correct |
361 ms |
36672 KB |
Output is correct |