#include <bits/stdc++.h>
using namespace std;
#ifndef wambule
#include "crocodile.h"
#endif
const int N = 100005;
vector<pair<int, int>> v[N];
long long p[N][2];
set<pair<long long, int>> s;
void D(int x, long long y) {
long long z = p[x][1];
if(p[x][0] == -1 || y < p[x][0]) {
p[x][1] = p[x][0];
p[x][0] = y;
} else if(p[x][1] == -1 || y < p[x][1]) {
p[x][1] = y;
}
if(z != p[x][1]) {
if(z != -1) s.erase(s.find({z, x}));
s.insert({p[x][1], x});
}
}
void G(int x) {
for(int i = 0; i < (int)v[x].size(); ++i) {
D(v[x][i].first, p[x][1] + v[x][i].second);
}
}
int travel_plan(int n, int m, int r[][2], int l[], int k, int c[]) {
for(int i = 0; i < n; ++i) {
p[i][0] = p[i][1] = -1;
}
for(int i = 0; i < m; ++i) {
v[r[i][0]].push_back({r[i][1], l[i]});
v[r[i][1]].push_back({r[i][0], l[i]});
}
for(int i = 0; i < k; ++i) {
p[c[i]][0] = p[c[i]][1] = 0;
G(c[i]);
}
long long bb = 0;
while(s.size()) {
if((*s.begin()).first < bb) exit(1);
G((*s.begin()).second);
bb = (*s.begin()).first;
s.erase(s.begin());
}
if(p[0][1] == -1) exit(1);
return p[0][1];
}
#ifdef wambule
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
// for(int i = 0; i < N; ++i) {
// p[i][0] = p[i][1] = -1;
// }
// while(1) {
// int x, y;
// cin >> x;
// cout << "[] " << p[x][0] << " " << p[x][1] << endl;
// cin >> y;
// D(x, y);
// cout << "[] " << p[x][0] << " " << p[x][1] << endl;
// }
int n = 5;
int m = 7;
int k = 2;
int r[][2] = {0, 2, 0, 3, 3, 2, 2, 1, 0, 1, 0, 4, 3, 4};
int l[] = {4, 3, 2, 10, 100, 7, 9};
int c[] = {1, 3};
cout << travel_plan(n, m, r, l, k, c) << endl;
return 0;
}
#endif
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2668 KB |
Output is correct |
2 |
Correct |
2 ms |
2668 KB |
Output is correct |
3 |
Correct |
2 ms |
2668 KB |
Output is correct |
4 |
Correct |
3 ms |
2796 KB |
Output is correct |
5 |
Correct |
3 ms |
2796 KB |
Output is correct |
6 |
Correct |
2 ms |
2796 KB |
Output is correct |
7 |
Correct |
3 ms |
2796 KB |
Output is correct |
8 |
Correct |
3 ms |
2796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2668 KB |
Output is correct |
2 |
Correct |
2 ms |
2668 KB |
Output is correct |
3 |
Correct |
2 ms |
2668 KB |
Output is correct |
4 |
Correct |
3 ms |
2796 KB |
Output is correct |
5 |
Correct |
3 ms |
2796 KB |
Output is correct |
6 |
Correct |
2 ms |
2796 KB |
Output is correct |
7 |
Correct |
3 ms |
2796 KB |
Output is correct |
8 |
Correct |
3 ms |
2796 KB |
Output is correct |
9 |
Runtime error |
13 ms |
5740 KB |
Execution killed with signal 6 |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2668 KB |
Output is correct |
2 |
Correct |
2 ms |
2668 KB |
Output is correct |
3 |
Correct |
2 ms |
2668 KB |
Output is correct |
4 |
Correct |
3 ms |
2796 KB |
Output is correct |
5 |
Correct |
3 ms |
2796 KB |
Output is correct |
6 |
Correct |
2 ms |
2796 KB |
Output is correct |
7 |
Correct |
3 ms |
2796 KB |
Output is correct |
8 |
Correct |
3 ms |
2796 KB |
Output is correct |
9 |
Runtime error |
13 ms |
5740 KB |
Execution killed with signal 6 |
10 |
Halted |
0 ms |
0 KB |
- |