#include "crocodile.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
#define f first
#define s second
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);
#define all(x) x.begin(),x.end()
const int maxn = 100010;
int state[maxn];
int dist[maxn], distreal[maxn];
vector <pi> adjlist[maxn];
int n, e;
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) {
n = N; e = M;
for (int i =0;i<e;i++) {
int a = R[i][0], b = R[i][1], c = L[i];
adjlist[a].push_back(pi(b,c));
adjlist[b].push_back(pi(a,c));
}
priority_queue <pi, vector<pi>, greater<pi>> pq;
memset(dist,-1,sizeof dist);
memset(distreal,-1,sizeof distreal);
for (int i =0;i<K;i++) {
pq.push(pi(0, P[i]));
distreal[P[i]] = 0;
state[P[i]] = 2;
}
while (!pq.empty()) {
auto [d,x] = pq.top(); pq.pop();
if (d != distreal[x]) continue;
for (auto [i,c] : adjlist[x]) {
if (state[i] == 0) {
state[i] = 1;
dist[i] = c + d;
} else if (state[i] == 1) {
if (distreal[i] == -1 or distreal[i] > c + d) {
distreal[i] = c + d;
if (distreal[i] < dist[i]) swap(dist[i],distreal[i]);
pq.push(pi(distreal[i],i));
}
}
}
}
return distreal[0];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3348 KB |
Output is correct |
2 |
Correct |
3 ms |
3404 KB |
Output is correct |
3 |
Correct |
3 ms |
3404 KB |
Output is correct |
4 |
Correct |
3 ms |
3424 KB |
Output is correct |
5 |
Correct |
4 ms |
3532 KB |
Output is correct |
6 |
Correct |
3 ms |
3404 KB |
Output is correct |
7 |
Correct |
3 ms |
3532 KB |
Output is correct |
8 |
Correct |
3 ms |
3404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3348 KB |
Output is correct |
2 |
Correct |
3 ms |
3404 KB |
Output is correct |
3 |
Correct |
3 ms |
3404 KB |
Output is correct |
4 |
Correct |
3 ms |
3424 KB |
Output is correct |
5 |
Correct |
4 ms |
3532 KB |
Output is correct |
6 |
Correct |
3 ms |
3404 KB |
Output is correct |
7 |
Correct |
3 ms |
3532 KB |
Output is correct |
8 |
Correct |
3 ms |
3404 KB |
Output is correct |
9 |
Correct |
4 ms |
3660 KB |
Output is correct |
10 |
Correct |
3 ms |
3420 KB |
Output is correct |
11 |
Correct |
3 ms |
3532 KB |
Output is correct |
12 |
Correct |
6 ms |
3916 KB |
Output is correct |
13 |
Correct |
6 ms |
3916 KB |
Output is correct |
14 |
Correct |
3 ms |
3404 KB |
Output is correct |
15 |
Correct |
4 ms |
3432 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3348 KB |
Output is correct |
2 |
Correct |
3 ms |
3404 KB |
Output is correct |
3 |
Correct |
3 ms |
3404 KB |
Output is correct |
4 |
Correct |
3 ms |
3424 KB |
Output is correct |
5 |
Correct |
4 ms |
3532 KB |
Output is correct |
6 |
Correct |
3 ms |
3404 KB |
Output is correct |
7 |
Correct |
3 ms |
3532 KB |
Output is correct |
8 |
Correct |
3 ms |
3404 KB |
Output is correct |
9 |
Correct |
4 ms |
3660 KB |
Output is correct |
10 |
Correct |
3 ms |
3420 KB |
Output is correct |
11 |
Correct |
3 ms |
3532 KB |
Output is correct |
12 |
Correct |
6 ms |
3916 KB |
Output is correct |
13 |
Correct |
6 ms |
3916 KB |
Output is correct |
14 |
Correct |
3 ms |
3404 KB |
Output is correct |
15 |
Correct |
4 ms |
3432 KB |
Output is correct |
16 |
Correct |
447 ms |
45056 KB |
Output is correct |
17 |
Correct |
77 ms |
11856 KB |
Output is correct |
18 |
Correct |
95 ms |
13140 KB |
Output is correct |
19 |
Correct |
588 ms |
48332 KB |
Output is correct |
20 |
Correct |
293 ms |
38336 KB |
Output is correct |
21 |
Correct |
39 ms |
7880 KB |
Output is correct |
22 |
Incorrect |
314 ms |
33424 KB |
Output isn't correct |