#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#include "crocodile.h"
using namespace std;
vector <pair<int,int > > adj[100000];
ll IN[100000][2];
bool vis[100000];
int Ein[100000],v,x;
ll dis[100000],d;
ll val;
struct cmp{
bool operator() (const int &a, const int &b) const {
if (Ein[a] >= 2 && Ein[b] >= 2)
return (dis[a] != dis[b] ? dis[a] < dis[b] : a < b );
return (Ein[a] >= 2 ? 1 : Ein[b] >= 2 ? 0 : (a < b));//Ein[a] > Ein[b];
}
};
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) {
for (int i = 0; i < M; i++) {
adj[ R[i][0] ].push_back( { L [i], R[i][1] } );
adj[ R[i][1] ].push_back( { L[i] , R[i][0] });
}
for (int i = 0; i < 100000; i++)
dis[i] = 100000000000000;
set<int,cmp> s;
for (int i = 0; i < K; i++)
Ein[P[i]] = 2,dis[P[i]] = 0,s.insert (P[i]);
while (!s.empty()) {
v = *s.begin();
if (Ein[v] < 2) break;
s.erase(s.begin());
if (vis[v]) continue;
vis[v] = 1;
for (auto i : adj[v]) {
x = i.se;
if (vis[x]) continue;
s.erase(x);
d = i.fi + dis[v];
if (IN[x][0] == 0) IN[x][0] = d;
else if (IN[x][1] == 0) {
IN[x][1] = d;
if (IN[x][0] > IN[x][1]) swap(IN[x][0],IN[x][1]);
}
else if (IN[x][1] > d) {
IN[x][1] = d;
if (IN[x][0] > IN[x][1]) swap(IN[x][0],IN[x][1]);
}
Ein[x] ++;
if (IN[x][1] && dis[x] > IN[x][1]) {
dis[x] = IN[x][1];
}
s.insert (x);
}
}
return dis[0];
} /*
main() {
} */
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
3456 KB |
Output is correct |
2 |
Correct |
6 ms |
3456 KB |
Output is correct |
3 |
Correct |
6 ms |
3584 KB |
Output is correct |
4 |
Correct |
7 ms |
3584 KB |
Output is correct |
5 |
Correct |
7 ms |
3584 KB |
Output is correct |
6 |
Correct |
7 ms |
3584 KB |
Output is correct |
7 |
Correct |
7 ms |
3584 KB |
Output is correct |
8 |
Correct |
7 ms |
3584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
3456 KB |
Output is correct |
2 |
Correct |
6 ms |
3456 KB |
Output is correct |
3 |
Correct |
6 ms |
3584 KB |
Output is correct |
4 |
Correct |
7 ms |
3584 KB |
Output is correct |
5 |
Correct |
7 ms |
3584 KB |
Output is correct |
6 |
Correct |
7 ms |
3584 KB |
Output is correct |
7 |
Correct |
7 ms |
3584 KB |
Output is correct |
8 |
Correct |
7 ms |
3584 KB |
Output is correct |
9 |
Correct |
10 ms |
3712 KB |
Output is correct |
10 |
Correct |
6 ms |
3456 KB |
Output is correct |
11 |
Correct |
7 ms |
3584 KB |
Output is correct |
12 |
Correct |
12 ms |
3840 KB |
Output is correct |
13 |
Correct |
11 ms |
3968 KB |
Output is correct |
14 |
Correct |
7 ms |
3456 KB |
Output is correct |
15 |
Correct |
9 ms |
3584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
3456 KB |
Output is correct |
2 |
Correct |
6 ms |
3456 KB |
Output is correct |
3 |
Correct |
6 ms |
3584 KB |
Output is correct |
4 |
Correct |
7 ms |
3584 KB |
Output is correct |
5 |
Correct |
7 ms |
3584 KB |
Output is correct |
6 |
Correct |
7 ms |
3584 KB |
Output is correct |
7 |
Correct |
7 ms |
3584 KB |
Output is correct |
8 |
Correct |
7 ms |
3584 KB |
Output is correct |
9 |
Correct |
10 ms |
3712 KB |
Output is correct |
10 |
Correct |
6 ms |
3456 KB |
Output is correct |
11 |
Correct |
7 ms |
3584 KB |
Output is correct |
12 |
Correct |
12 ms |
3840 KB |
Output is correct |
13 |
Correct |
11 ms |
3968 KB |
Output is correct |
14 |
Correct |
7 ms |
3456 KB |
Output is correct |
15 |
Correct |
9 ms |
3584 KB |
Output is correct |
16 |
Correct |
1300 ms |
41208 KB |
Output is correct |
17 |
Correct |
105 ms |
12536 KB |
Output is correct |
18 |
Correct |
179 ms |
13816 KB |
Output is correct |
19 |
Correct |
1758 ms |
45924 KB |
Output is correct |
20 |
Correct |
555 ms |
37496 KB |
Output is correct |
21 |
Correct |
61 ms |
7416 KB |
Output is correct |
22 |
Correct |
565 ms |
33144 KB |
Output is correct |