#include "crocodile.h"
#include <bits/stdc++.h>
#define pii pair<long long, int>
using namespace std;
int N, M;
long long ans;
vector<pii> adj[100005];
long long dist[100005], dist2[100005];
bool can[100005];
priority_queue<pii, vector<pii>, greater<pii>> pq;
void BFS() {
for(int i = 0; i < N; i++) {
if(can[i]) pq.emplace(0, i), can[i] = 0;
else dist[i] = 1000000000000, dist2[i] = 1000000000000;
}
int u, v;
long long len, w;
while(!pq.empty()) {
u = pq.top().second;
len = pq.top().first;
pq.pop();
if(can[u]) continue;
can[u] = 1;
for(pii now : adj[u]) {
v = now.second;
w = now.first;
if(dist2[u] + w < dist[v]) {
dist2[v] = dist[v];
dist[v] = dist2[u] + w;
pq.emplace(dist2[v], v);
}else if(dist2[u] + w < dist2[v]) {
dist2[v] = dist2[u] + w;
pq.emplace(dist2[v], v);
}
}
}
}
int travel_plan(int n, int m, int r[][2], int l[], int k, int p[]){
N = n, M = m;
for(int i = 0; i < k; i++) can[p[i]] = 1;
for(int i = 0; i < m; i++) {
adj[r[i][0]].emplace_back(l[i], r[i][1]);
adj[r[i][1]].emplace_back(l[i], r[i][0]);
}
BFS();
return dist2[0];
}
Compilation message
crocodile.cpp: In function 'void BFS()':
crocodile.cpp:19:13: warning: variable 'len' set but not used [-Wunused-but-set-variable]
long long len, w;
^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2688 KB |
Output is correct |
2 |
Correct |
2 ms |
2688 KB |
Output is correct |
3 |
Correct |
2 ms |
2688 KB |
Output is correct |
4 |
Correct |
3 ms |
2816 KB |
Output is correct |
5 |
Correct |
3 ms |
2816 KB |
Output is correct |
6 |
Correct |
2 ms |
2816 KB |
Output is correct |
7 |
Correct |
3 ms |
2816 KB |
Output is correct |
8 |
Correct |
3 ms |
2816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2688 KB |
Output is correct |
2 |
Correct |
2 ms |
2688 KB |
Output is correct |
3 |
Correct |
2 ms |
2688 KB |
Output is correct |
4 |
Correct |
3 ms |
2816 KB |
Output is correct |
5 |
Correct |
3 ms |
2816 KB |
Output is correct |
6 |
Correct |
2 ms |
2816 KB |
Output is correct |
7 |
Correct |
3 ms |
2816 KB |
Output is correct |
8 |
Correct |
3 ms |
2816 KB |
Output is correct |
9 |
Correct |
4 ms |
3200 KB |
Output is correct |
10 |
Correct |
2 ms |
2688 KB |
Output is correct |
11 |
Correct |
3 ms |
2816 KB |
Output is correct |
12 |
Correct |
6 ms |
3456 KB |
Output is correct |
13 |
Correct |
6 ms |
3456 KB |
Output is correct |
14 |
Correct |
2 ms |
2688 KB |
Output is correct |
15 |
Correct |
3 ms |
2816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2688 KB |
Output is correct |
2 |
Correct |
2 ms |
2688 KB |
Output is correct |
3 |
Correct |
2 ms |
2688 KB |
Output is correct |
4 |
Correct |
3 ms |
2816 KB |
Output is correct |
5 |
Correct |
3 ms |
2816 KB |
Output is correct |
6 |
Correct |
2 ms |
2816 KB |
Output is correct |
7 |
Correct |
3 ms |
2816 KB |
Output is correct |
8 |
Correct |
3 ms |
2816 KB |
Output is correct |
9 |
Correct |
4 ms |
3200 KB |
Output is correct |
10 |
Correct |
2 ms |
2688 KB |
Output is correct |
11 |
Correct |
3 ms |
2816 KB |
Output is correct |
12 |
Correct |
6 ms |
3456 KB |
Output is correct |
13 |
Correct |
6 ms |
3456 KB |
Output is correct |
14 |
Correct |
2 ms |
2688 KB |
Output is correct |
15 |
Correct |
3 ms |
2816 KB |
Output is correct |
16 |
Correct |
601 ms |
73168 KB |
Output is correct |
17 |
Correct |
121 ms |
19952 KB |
Output is correct |
18 |
Correct |
167 ms |
22436 KB |
Output is correct |
19 |
Correct |
792 ms |
81892 KB |
Output is correct |
20 |
Correct |
354 ms |
59512 KB |
Output is correct |
21 |
Correct |
56 ms |
10492 KB |
Output is correct |
22 |
Correct |
389 ms |
55420 KB |
Output is correct |