Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define fi first
- #define se second
- using namespace std;
- typedef pair<int, int> ii;
- typedef vector<ii> vii;
- int N, m, a, b, t, nh;
- int h[10001];
- vii G[10001];
- int ans[10001];
- void dfs(int n, int sz, int ht)
- {
- ans[n] = min(ans[n], ht);
- for (int i = 0; i < G[n].size(); i++) {
- if (ht < ans[G[n][i].fi])
- {
- if (G[n][i].se + sz <= 600)
- dfs(G[n][i].fi, G[n][i].se + sz, ht); //nao descanso
- if (h[n] == 1)
- dfs(G[n][i].fi, G[n][i].se, ht + 1); //descanso
- }
- else if (ht == ans[G[n][i].fi])
- {
- }
- }
- }
- int main()
- {
- while (cin >> N && N)
- {
- for (int i = 0; i < N; i++) {
- G[i+1].clear();
- ans[i+1] = 1 << 30;
- }
- cin >> nh;
- memset(h, 0, sizeof h);
- for (int i = 0; i < nh; i++) {
- cin >> t; h[t] = 1;
- }
- cin >> m;
- for (int i = 0; i < m; i++) {
- cin >> a >> b >> t;
- G[a].push_back(ii(b, t));
- G[b].push_back(ii(a, t));
- }
- dfs(1, 0, 0);
- cout << (ans[N] == (1 << 30) ? -1 : ans[N]) << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement