#include "crocodile.h"
#include <bits/stdc++.h>
//#define int long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define sc second
#define endl "\n"
#define pii pair<int,int>
using namespace std;
const int MAXN = 1e5+5;
const int mod7 = 1e9+7;
const long long inf = 1e9;
int n;
vector<long long> dist(MAXN, inf);
int cnt[MAXN];
vector<vector<pii>> graf(MAXN);
set<pii> pq;
void dikstra()
{
while(!pq.empty())
{
auto it = pq.begin();
int u = it-> sc;
int d = it-> fi;
pq.erase(it);
if(dist[u] != inf)continue;
cnt[u]++;
if(cnt[u] == 2)
{
dist[u] = d;
for(auto x: graf[u])
{
pq.insert({d+x.sc, x.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++)
{
graf[R[i][0]].pb({R[i][1], L[i]});
graf[R[i][1]].pb({R[i][0], L[i]});
}
for(int i = 0; i<K; i++)
{
for(auto x: graf[P[i]])
{
pq.insert(mp(x.sc, x.fi));
}
dist[P[i]] = 0;
}
//for(auto x: pq)cout << x.fi << " " << x.sc << endl;
dikstra();
return dist[0];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3416 KB |
Output is correct |
2 |
Correct |
2 ms |
3420 KB |
Output is correct |
3 |
Correct |
2 ms |
3420 KB |
Output is correct |
4 |
Incorrect |
2 ms |
3676 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3416 KB |
Output is correct |
2 |
Correct |
2 ms |
3420 KB |
Output is correct |
3 |
Correct |
2 ms |
3420 KB |
Output is correct |
4 |
Incorrect |
2 ms |
3676 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3416 KB |
Output is correct |
2 |
Correct |
2 ms |
3420 KB |
Output is correct |
3 |
Correct |
2 ms |
3420 KB |
Output is correct |
4 |
Incorrect |
2 ms |
3676 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |