// IOI 2011 crocodile
#include "crocodile.h"
#include <bits/stdc++.h>
#define MX 100000
using namespace std;
int N, M, K;
vector<pair<int, int> > edges[MX + 1];
int dist1[MX + 1], dist2[MX + 1];
bool visited[MX + 1];
priority_queue<pair<int, int> > q;
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
for (int i = 0; i < M; i++) {
int a = R[i][0], b = R[i][1], c = L[i];
edges[a].push_back({b, c});
edges[b].push_back({a, c});
}
memset(dist1, 0x3f, sizeof(dist1));
memset(dist2, 0x3f, sizeof(dist2));
for (int i = 0; i < K; i++) {
int x = P[i];
dist1[x] = dist2[x] = 0;
q.push({0, x});
}
while (q.size()) {
int node = q.top().second;
q.pop();
if (visited[node]) continue;
visited[node] = true;
for (auto& edge : edges[node]) {
if (dist2[node] + edge.second < dist1[edge.first]) {
dist2[edge.first] = dist1[edge.first];
dist1[edge.first] = dist2[node] + edge.second;
q.push({-dist2[edge.first], edge.first});
}
else if (dist2[node] + edge.second < dist2[edge.first]) {
dist2[edge.first] = dist2[node] + edge.second;
q.push({-dist2[edge.first], edge.first});
}
}
}
return dist2[0];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3436 KB |
Output is correct |
2 |
Correct |
3 ms |
3436 KB |
Output is correct |
3 |
Correct |
3 ms |
3436 KB |
Output is correct |
4 |
Correct |
3 ms |
3564 KB |
Output is correct |
5 |
Correct |
3 ms |
3564 KB |
Output is correct |
6 |
Correct |
4 ms |
3564 KB |
Output is correct |
7 |
Correct |
3 ms |
3564 KB |
Output is correct |
8 |
Correct |
4 ms |
3564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3436 KB |
Output is correct |
2 |
Correct |
3 ms |
3436 KB |
Output is correct |
3 |
Correct |
3 ms |
3436 KB |
Output is correct |
4 |
Correct |
3 ms |
3564 KB |
Output is correct |
5 |
Correct |
3 ms |
3564 KB |
Output is correct |
6 |
Correct |
4 ms |
3564 KB |
Output is correct |
7 |
Correct |
3 ms |
3564 KB |
Output is correct |
8 |
Correct |
4 ms |
3564 KB |
Output is correct |
9 |
Correct |
5 ms |
3692 KB |
Output is correct |
10 |
Correct |
3 ms |
3436 KB |
Output is correct |
11 |
Correct |
4 ms |
3564 KB |
Output is correct |
12 |
Correct |
6 ms |
3820 KB |
Output is correct |
13 |
Correct |
6 ms |
3948 KB |
Output is correct |
14 |
Correct |
3 ms |
3564 KB |
Output is correct |
15 |
Correct |
3 ms |
3564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3436 KB |
Output is correct |
2 |
Correct |
3 ms |
3436 KB |
Output is correct |
3 |
Correct |
3 ms |
3436 KB |
Output is correct |
4 |
Correct |
3 ms |
3564 KB |
Output is correct |
5 |
Correct |
3 ms |
3564 KB |
Output is correct |
6 |
Correct |
4 ms |
3564 KB |
Output is correct |
7 |
Correct |
3 ms |
3564 KB |
Output is correct |
8 |
Correct |
4 ms |
3564 KB |
Output is correct |
9 |
Correct |
5 ms |
3692 KB |
Output is correct |
10 |
Correct |
3 ms |
3436 KB |
Output is correct |
11 |
Correct |
4 ms |
3564 KB |
Output is correct |
12 |
Correct |
6 ms |
3820 KB |
Output is correct |
13 |
Correct |
6 ms |
3948 KB |
Output is correct |
14 |
Correct |
3 ms |
3564 KB |
Output is correct |
15 |
Correct |
3 ms |
3564 KB |
Output is correct |
16 |
Correct |
473 ms |
42848 KB |
Output is correct |
17 |
Correct |
115 ms |
11752 KB |
Output is correct |
18 |
Correct |
118 ms |
13032 KB |
Output is correct |
19 |
Correct |
617 ms |
47144 KB |
Output is correct |
20 |
Correct |
300 ms |
37424 KB |
Output is correct |
21 |
Correct |
43 ms |
7404 KB |
Output is correct |
22 |
Correct |
317 ms |
32876 KB |
Output is correct |