#include <bits/stdc++.h>
// mrrrow meeow :3
// go play vivid/stasis now! it's free on steam
#define fo(i, a, b) for (auto i = (a); i < (b); i++)
#define of(i, a, b) for (auto i = (b); i-- > (a);)
#define f first
#define s second
#define pb push_back
#define pob pop_back
#define lb lower_bound
#define ub upper_bound
#define be(a) a.begin(), a.end()
using namespace std;
int ____init = [] {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
return 0;
}();
vector<pair<int, int>> adj[100000];
set<int> exits;
bool vis[100000];
int dfs(int i, int p = -1) {
if (exits.count(i)) return 0;
vis[i] = true;
int resa = 1000000000;
int resb = 1000000000;
for (auto [j, l] : adj[i]) {
if (vis[j]) continue;
resb = min(resb, dfs(j, i) + l);
if (resb < resa) swap(resa, resb);
}
vis[i] = false;
return resb;
}
int travel_plan(int n, int m, int r[][2], int l[], int k, int p[]) {
fo(i, 0, m) {
adj[r[i][0]].pb({r[i][1], l[i]});
adj[r[i][1]].pb({r[i][0], l[i]});
}
fo(i, 0, k) exits.insert(p[i]);
return dfs(0);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |