#include<iostream>
#include<algorithm>
#include<vector>
#include "crocodile.h"
using namespace std;
typedef pair<int, int> pii;
vector<pii> a[100001];
int d[100001];
int n, m, k;
int inf = 1e9 + 100;
int f(int x) {
if (d[x] != -1) return d[x];
d[x] = inf;
vector<pii> tmp;
for (int i = 0; i < a[x].size(); i++) {
tmp.push_back(pii(f(a[x][i].first) + a[x][i].second, a[x][i].first));
}
sort(tmp.begin(), tmp.end());
if (a[x].size() != 1) d[x] = min(d[x], tmp[1].first);
return d[x];
}
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
n = N;
m = M;
for (int i = 0; i < m; i++) {
a[R[i][0]].push_back(pii(R[i][1], L[i]));
a[R[i][1]].push_back(pii(R[i][0], L[i]));
}
k = K;
for (int i = 0; i < n; i++) d[i] = -1;
for (int i = 0; i < K; i++) d[P[i]] = 0;
return f(0);
}
/*
int main() {
scanf("%d%d%d", &n, &m, &k);
for (int i = 0; i < m; i++) {
int t0, t1, t2;
scanf("%d%d%d", &t0, &t1, &t2);
a[t0].push_back(pii(t1, t2));
a[t1].push_back(pii(t0, t2));
}
for (int i = 0; i < n; i++) d[i] = -1;
for (int i = 0; i < k; i++) {
int t0;
scanf("%d", &t0);
d[t0] = 0;
}
printf("%d\n", f(0));
return 0;
}
*/
Compilation message
crocodile.cpp: In function 'int f(int)':
crocodile.cpp:17:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | for (int i = 0; i < a[x].size(); i++) {
| ~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6488 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
2 ms |
6488 KB |
Output is correct |
5 |
Correct |
2 ms |
6488 KB |
Output is correct |
6 |
Correct |
1 ms |
6488 KB |
Output is correct |
7 |
Correct |
2 ms |
6492 KB |
Output is correct |
8 |
Correct |
2 ms |
6492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6488 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
2 ms |
6488 KB |
Output is correct |
5 |
Correct |
2 ms |
6488 KB |
Output is correct |
6 |
Correct |
1 ms |
6488 KB |
Output is correct |
7 |
Correct |
2 ms |
6492 KB |
Output is correct |
8 |
Correct |
2 ms |
6492 KB |
Output is correct |
9 |
Correct |
3 ms |
6748 KB |
Output is correct |
10 |
Incorrect |
1 ms |
6492 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6488 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
2 ms |
6488 KB |
Output is correct |
5 |
Correct |
2 ms |
6488 KB |
Output is correct |
6 |
Correct |
1 ms |
6488 KB |
Output is correct |
7 |
Correct |
2 ms |
6492 KB |
Output is correct |
8 |
Correct |
2 ms |
6492 KB |
Output is correct |
9 |
Correct |
3 ms |
6748 KB |
Output is correct |
10 |
Incorrect |
1 ms |
6492 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |