#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e5+4;
const int INF = 1e9+2;
vector<pair<int,int>> adj[N];
int vis[N];
int ex[N];
int ans[N];
int dfs(int i){
// cout<<i<<'\n';
vis[i] = 1;
if (ex[i]) return 0;
int b1=INF, b2=INF;
for (auto [c,w]: adj[i]){
if (vis[c] && ans[i] == -1) continue;
int v = (vis[c]||!ans[c])? w + ans[c] : w + dfs(c);
if (v<b1) b2=b1, b1=v;
else if (v<b2) b2=v;
}
// cout<<i<<' '<<b1<<' '<<b2<<'\n';
ans[i] = b2;
return b2;
}
signed travel_plan(signed n, signed m, signed r[][2], signed l[], signed k, signed p[]){
for (int i=0; i<m; i++){
adj[r[i][0]].push_back({r[i][1], l[i]});
adj[r[i][1]].push_back({r[i][0], l[i]});
}
for (int i=0; i<n; i++) ans[i] = -1;
for (int i=0; i<k; i++) ex[p[i]] = 1, ans[p[i]] = 0;
return (signed)dfs(0);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8536 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
1 ms |
8540 KB |
Output is correct |
4 |
Correct |
2 ms |
8656 KB |
Output is correct |
5 |
Correct |
1 ms |
8540 KB |
Output is correct |
6 |
Correct |
1 ms |
8648 KB |
Output is correct |
7 |
Correct |
1 ms |
8544 KB |
Output is correct |
8 |
Correct |
1 ms |
8544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8536 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
1 ms |
8540 KB |
Output is correct |
4 |
Correct |
2 ms |
8656 KB |
Output is correct |
5 |
Correct |
1 ms |
8540 KB |
Output is correct |
6 |
Correct |
1 ms |
8648 KB |
Output is correct |
7 |
Correct |
1 ms |
8544 KB |
Output is correct |
8 |
Correct |
1 ms |
8544 KB |
Output is correct |
9 |
Incorrect |
2 ms |
8804 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8536 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
1 ms |
8540 KB |
Output is correct |
4 |
Correct |
2 ms |
8656 KB |
Output is correct |
5 |
Correct |
1 ms |
8540 KB |
Output is correct |
6 |
Correct |
1 ms |
8648 KB |
Output is correct |
7 |
Correct |
1 ms |
8544 KB |
Output is correct |
8 |
Correct |
1 ms |
8544 KB |
Output is correct |
9 |
Incorrect |
2 ms |
8804 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |