#include <bits/stdc++.h>
#include "crocodile.h"
using namespace std;
#define ll long long
const int N = 1e5 + 5;
const int INF = 2e9;
struct ura{
ll x, c;
bool operator <(const ura &other) const{
return c > other.c;
}
};
vector <ura> g[N];
ll d[N];
int bagat[N];
priority_queue <ura> pq;
int cost[N][2];
int q[N];
int travel_plan(int n, int m, int r[][2], int l[], int k, int p[])
{
int i, j, inc = 1, sf = 0;
for (i = 0; i < m ; i++)
for (j = 0; j < 2; j++)
g[r[i][j]].push_back({r[i][1 - j], l[i]});
for (i = 0; i < n; i++)
cost[i][0] = cost[i][1] = d[i] = INF;
for (i = 0; i < k; i++)
{
d[p[i]] = 0;
q[++sf] = p[i];
cost[p[i]][0] = 0;
cost[p[i]][1] = 0;
bagat[p[i]] = 1;
}
while (inc <= sf)
{
int x = q[inc++];
int c = d[x];
for (auto u : g[x])
{
if (bagat[u.x])
continue;
int costnow = u.c + c;
if (cost[u.x][1] < costnow)
continue;
if (costnow < cost[u.x][0])
{
cost[u.x][1] = cost[u.x][0];
cost[u.x][0] = costnow;
}
else
if (costnow < cost[u.x][1])
cost[u.x][1] = costnow;
pq.push({u.x, cost[u.x][1]});
}
if (inc > sf)
{
int ok = 1;
while (ok && !pq.empty())
{
int x = pq.top().x;
pq.pop();
if (bagat[x])
continue;
ok = 0;
bagat[x] = 1;
q[++sf] = x;
d[x] = cost[x][1];
}
}
}
return d[0];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
3 ms |
2576 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
3 ms |
2764 KB |
Output is correct |
5 |
Correct |
3 ms |
2804 KB |
Output is correct |
6 |
Correct |
3 ms |
2764 KB |
Output is correct |
7 |
Correct |
3 ms |
2764 KB |
Output is correct |
8 |
Correct |
3 ms |
2764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
3 ms |
2576 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
3 ms |
2764 KB |
Output is correct |
5 |
Correct |
3 ms |
2804 KB |
Output is correct |
6 |
Correct |
3 ms |
2764 KB |
Output is correct |
7 |
Correct |
3 ms |
2764 KB |
Output is correct |
8 |
Correct |
3 ms |
2764 KB |
Output is correct |
9 |
Correct |
4 ms |
3020 KB |
Output is correct |
10 |
Correct |
3 ms |
2672 KB |
Output is correct |
11 |
Correct |
3 ms |
2764 KB |
Output is correct |
12 |
Correct |
6 ms |
3316 KB |
Output is correct |
13 |
Correct |
5 ms |
3444 KB |
Output is correct |
14 |
Correct |
2 ms |
2636 KB |
Output is correct |
15 |
Correct |
3 ms |
2764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
3 ms |
2576 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
3 ms |
2764 KB |
Output is correct |
5 |
Correct |
3 ms |
2804 KB |
Output is correct |
6 |
Correct |
3 ms |
2764 KB |
Output is correct |
7 |
Correct |
3 ms |
2764 KB |
Output is correct |
8 |
Correct |
3 ms |
2764 KB |
Output is correct |
9 |
Correct |
4 ms |
3020 KB |
Output is correct |
10 |
Correct |
3 ms |
2672 KB |
Output is correct |
11 |
Correct |
3 ms |
2764 KB |
Output is correct |
12 |
Correct |
6 ms |
3316 KB |
Output is correct |
13 |
Correct |
5 ms |
3444 KB |
Output is correct |
14 |
Correct |
2 ms |
2636 KB |
Output is correct |
15 |
Correct |
3 ms |
2764 KB |
Output is correct |
16 |
Correct |
576 ms |
85136 KB |
Output is correct |
17 |
Correct |
114 ms |
20368 KB |
Output is correct |
18 |
Correct |
146 ms |
22816 KB |
Output is correct |
19 |
Correct |
784 ms |
93828 KB |
Output is correct |
20 |
Correct |
341 ms |
68172 KB |
Output is correct |
21 |
Correct |
50 ms |
10556 KB |
Output is correct |
22 |
Correct |
366 ms |
64852 KB |
Output is correct |