Dennnhhhickk

Untitled

May 27th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. typedef long long ll;
  5. #define mp(a, b) make_pair(a, b)
  6.  
  7. int main()
  8. {
  9. ll n, m, a, b, dp[100010], x, y, w, INF = 1e15, temp;
  10. queue <ll> q;
  11. cin >> n >> m;
  12. for (ll i = 0; i < n; i++)
  13. dp[i] = INF;
  14. vector <vector <pair <ll, ll> > > g(n);
  15. for (ll i = 0; i < m; i++){
  16. cin >> x >> y >> w;
  17. g[x - 1].push_back(mp(w, y - 1));
  18. }
  19. cin >> a >> b;
  20. for (ll z = 0; z < n; z++)
  21. sort(g[z].begin(), g[z].end());
  22. dp[a - 1] = 0;
  23. q.push(a - 1);
  24. while (!q.empty()){
  25. temp = q.front();
  26. q.pop();
  27. for (ll i = 0; i < g[temp].size(); i++)
  28. if (dp[g[temp][i].second] > max(dp[temp], max((ll)g[temp].size() - 1 - i - 1,(ll) 0))){
  29. dp[g[temp][i].second] = max(dp[temp], max((ll)g[temp].size() - 1 - i - 1,(ll) 0));
  30. q.push(g[temp][i].second);
  31. }
  32. }
  33. if (dp[b - 1] == INF)
  34. cout << -1;
  35. else
  36. cout << dp[b - 1];
  37. cout << endl;
  38. return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment