#include "crocodile.h"
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll INF = 1e18;
struct Comp {
int nod;
ll val;
bool operator <(const Comp &other) const {
return val > other.val;
}
};
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) {
vector < vector < pair <int, int> > > g(N);
for(int i = 0; i < M; i++) {
g[R[i][0]].push_back({R[i][1], L[i]});
g[R[i][1]].push_back({R[i][0], L[i]});
}
priority_queue <Comp> pq;
vector <ll> dst(N, INF);
vector <int> cnt(N);
for(int i = 0; i < K; i++) {
dst[P[i]] = 0;
pq.push({P[i], 0});
cnt[P[i]] = 1;
}
while(pq.size()) {
auto cur = pq.top();
pq.pop();
if(cnt[cur.nod] == 2) {
continue;
}
cnt[cur.nod]++;
dst[cur.nod] = cur.val;
if(cnt[cur.nod] == 2) {
for(auto it : g[cur.nod]) {
pq.push({it.first, cur.val + it.second});
}
}
}
return (int) dst[0];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
488 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
488 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
3 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
1024 KB |
Output is correct |
10 |
Correct |
2 ms |
304 KB |
Output is correct |
11 |
Correct |
4 ms |
512 KB |
Output is correct |
12 |
Correct |
12 ms |
1408 KB |
Output is correct |
13 |
Correct |
9 ms |
1532 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
488 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
3 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
1024 KB |
Output is correct |
10 |
Correct |
2 ms |
304 KB |
Output is correct |
11 |
Correct |
4 ms |
512 KB |
Output is correct |
12 |
Correct |
12 ms |
1408 KB |
Output is correct |
13 |
Correct |
9 ms |
1532 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
384 KB |
Output is correct |
16 |
Correct |
1478 ms |
87676 KB |
Output is correct |
17 |
Correct |
109 ms |
14104 KB |
Output is correct |
18 |
Correct |
177 ms |
15776 KB |
Output is correct |
19 |
Correct |
1467 ms |
92424 KB |
Output is correct |
20 |
Correct |
805 ms |
80332 KB |
Output is correct |
21 |
Correct |
61 ms |
6136 KB |
Output is correct |
22 |
Correct |
704 ms |
45580 KB |
Output is correct |