#include "crocodile.h"
#include <bits/stdc++.h>
#define fi first
#define se second
#define nmax 100008
const long long inf = 1e18;
using namespace std;
typedef pair<long long, long long> pii;
pii operator+(pii x, long long y){
return (y <= x.fi) ? make_pair(y, x.fi) : ((y < x.se) ? make_pair(x.fi, y) : x);
}
int n, m;
bool kt[nmax];
pii f[nmax];
vector<pii> l[nmax];
priority_queue<pii, vector<pii>, greater<pii> > s;
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]){
n = N;
m = M;
fill(f, f + n + 1, make_pair(inf, inf));
fill(kt, kt + n + 1, false);
for (int i = 0; i < n; i++){
int u = R[i][0], v = R[i][1], w = L[i];
l[u].push_back({v, w});
l[v].push_back({u, w});
}
for (int i = 0; i < K; i++)
f[P[i]] = {0, 0};
while (f[0].se >= inf){
int sp = -1;
for (int i = 0; i <= n; i++)
if (kt[i] || f[i].se == inf)
continue;
else{
if (sp == -1 || f[i].se < f[sp].se)
sp = i;
}
if (sp == -1)
break;
kt[sp] = true;
for (pii it : l[sp]){
if (kt[it.fi])
continue;
f[it.fi] = f[it.fi] + (f[sp].se + it.se);
}
}
return f[0].se;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |