#include <bits/stdc++.h>
#include "crocodile.h"
using namespace std;
#define ff first
#define ss second
#define pii pair<int, int>
using ll = long long;
vector<bool> vis, vis2;
vector<ll> v;
vector<vector<pii>> E;
void dfs(int x) {
vis2[x] = true;
if (vis[x]) {
v[x] = 0;
return;
}
vector<int> u;
for (auto [i, w] : E[x]) {
if (vis2[i]) continue;
dfs(i);
u.push_back(v[i] + w);
}
sort(u.begin(), u.end());
if (1 < (int)u.size()) v[x] = u[1];
}
int travel_plan(int n, int M, int R[][2], int L[], int K, int P[]) {
E.assign(n, {});
for (int i = 0; i < M; i++) {
E[R[i][0]].push_back({R[i][1], L[i]});
E[R[i][1]].push_back({R[i][0], L[i]});
}
vis.assign(n, false);
for (int i = 0; i < K; i++)
vis[P[i]] = true;
vis2.assign(n, false);
v.assign(n, LLONG_MAX);
dfs(0);
return v[0];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4696 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4440 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4696 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4440 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Incorrect |
2 ms |
4696 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4696 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4440 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Incorrect |
2 ms |
4696 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |