#include<bits/stdc++.h>
using namespace std;
#include<fstream>
#define ll long long
#define vt vector
#define pb push_back
#define fi first
#define se second
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
typedef unsigned long long ull;
#define pii pair<int, int>
const ll mod = 1e9 + 7;
#include<fstream>
ifstream fin("timeline.in");
ofstream fout("timeline.out");
const int mxn = 1e5;
const int inf = 1e9 + 3;
vt<pii>adj[mxn + 1];
pii d[mxn + 1]; // best and second best
struct ch{
int u, d;
};
struct cmp{
bool operator()(ch a, ch b){
return(a.d > b.d);
}
};
int travel_plan(int n, int m, int r[][2], int l[], int k, int p[]){
for(int i = 0; i < n; i++){
d[i].fi = d[i].se = inf;
}
for(int i = 0; i < m; i++){
int u = r[i][0], v = r[i][1], w = l[i];
adj[u].pb({v, w}); adj[v].pb({u, w});
}
priority_queue<ch, vt<ch>, cmp>pq;
for(int i = 0; i < k; i++){
d[p[i]].fi = d[p[i]].se = 0;
pq.push({p[i], 0});
}
while(!pq.empty()){
ch nw = pq.top(); pq.pop();
int u = nw.u, dd = nw.d;
if(d[u].se < dd)continue;
if(u == 0)return(dd);
for(auto i: adj[u]){
int v = i.fi, w = i.se;
if(dd + w < d[v].se){
d[v].se = dd + w;
if(d[v].fi > d[v].se)swap(d[v].fi, d[v].se);
if(d[v].se != inf){
pq.push({v, d[v].se});
}
}
}
}
assert(false);
return(69);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
2 ms |
2644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
2 ms |
2644 KB |
Output is correct |
9 |
Correct |
2 ms |
2900 KB |
Output is correct |
10 |
Correct |
1 ms |
2644 KB |
Output is correct |
11 |
Correct |
3 ms |
2644 KB |
Output is correct |
12 |
Correct |
4 ms |
3028 KB |
Output is correct |
13 |
Correct |
4 ms |
3028 KB |
Output is correct |
14 |
Correct |
1 ms |
2644 KB |
Output is correct |
15 |
Correct |
2 ms |
2644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
2 ms |
2644 KB |
Output is correct |
9 |
Correct |
2 ms |
2900 KB |
Output is correct |
10 |
Correct |
1 ms |
2644 KB |
Output is correct |
11 |
Correct |
3 ms |
2644 KB |
Output is correct |
12 |
Correct |
4 ms |
3028 KB |
Output is correct |
13 |
Correct |
4 ms |
3028 KB |
Output is correct |
14 |
Correct |
1 ms |
2644 KB |
Output is correct |
15 |
Correct |
2 ms |
2644 KB |
Output is correct |
16 |
Correct |
319 ms |
41060 KB |
Output is correct |
17 |
Correct |
56 ms |
10444 KB |
Output is correct |
18 |
Correct |
67 ms |
11716 KB |
Output is correct |
19 |
Correct |
386 ms |
44804 KB |
Output is correct |
20 |
Correct |
222 ms |
36664 KB |
Output is correct |
21 |
Correct |
30 ms |
6260 KB |
Output is correct |
22 |
Incorrect |
236 ms |
31744 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |