Advertisement
Guest User

435ertert

a guest
Jul 26th, 2020
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.00 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <utility>
  4. #include <limits>
  5. #include <map>
  6. #include <set>
  7. #include <deque>
  8.  
  9. constexpr auto Inf = std::numeric_limits <int64_t>::max ();
  10. using Ip = std::pair <int, int>;
  11. using VIp = std::vector <Ip>;
  12. using VVIp = std::vector <VIp>;
  13. using Vi = std::vector <int>;
  14. using Vi64 = std::vector <int64_t>;
  15. using STi = std::set <int>;
  16. using Hsi64i = std::map <int64_t, int>;
  17. using DQi = std::deque <int>;
  18.  
  19.  
  20. int n, m, u, v, w;
  21. VVIp Graph, TGraph;
  22. Vi64 DistanceX, DistanceY;
  23. Vi Tag;
  24. DQi DQ;
  25. Hsi64i Hash;
  26. STi Store;
  27.  
  28.  
  29. inline void DEsopoPape (const int& src, Vi64& Distance, const VVIp& Graph) {
  30.     Tag.assign (n + 1, 2);
  31.     DQ.push_back (src), Distance[src] = 0LL;
  32.     while (!DQ.empty ()) {
  33.         int u = DQ.front ();
  34.         DQ.pop_front (), Tag[u] = 0;
  35.         for (const auto& e: Graph[u])
  36.             if (Distance[e.first] > Distance[u] + e.second) {
  37.                 Distance[e.first] = Distance[u] + e.second;
  38.                 if (Tag[e.first] == 2)
  39.                     Tag[e.first] = 1, DQ.push_back (e.first);
  40.                 else if (!Tag[e.first])
  41.                     Tag[e.first] = 1, DQ.push_front (e.first);
  42.             }
  43.     }
  44. }
  45.  
  46.  
  47. int main () {
  48.     std::cin >> n >> m;
  49.     Graph.resize (n + 1), TGraph.resize (n + 1);
  50.     DistanceX.assign (n + 1, Inf), DistanceY.assign (n + 1, Inf);
  51.     for (int i = 1; i <= m; ++ i)
  52.         std::cin >> u >> v >> w,
  53.         Graph[u].emplace_back (std::make_pair (v, w)),
  54.         TGraph[v].emplace_back (std::make_pair (u, w));
  55.  
  56.     DEsopoPape (1, DistanceX, Graph), DEsopoPape (n, DistanceY, TGraph);
  57.     for (int u = 1; u <= n; ++ u)
  58.         if (DistanceX[n] == DistanceX[u] + DistanceY[u])
  59.             ++ Hash[DistanceX[u]];
  60.     for (int u = 1; u <= n; ++ u)
  61.         if (DistanceX[n] == DistanceX[u] + DistanceY[u] && Hash[DistanceX[u]] == 1)
  62.             Store.insert (u);
  63.  
  64.     std::cout << Store.size () << "\n";
  65.     for (const auto& u: Store)
  66.         std::cout << u << " ";
  67.  
  68.     return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement