Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <utility>
- #include <limits>
- #include <map>
- #include <set>
- #include <deque>
- constexpr auto Inf = std::numeric_limits <int64_t>::max ();
- using Ip = std::pair <int, int>;
- using VIp = std::vector <Ip>;
- using VVIp = std::vector <VIp>;
- using Vi = std::vector <int>;
- using Vi64 = std::vector <int64_t>;
- using STi = std::set <int>;
- using Hsi64i = std::map <int64_t, int>;
- using DQi = std::deque <int>;
- int n, m, u, v, w;
- VVIp Graph, TGraph;
- Vi64 DistanceX, DistanceY;
- Vi Tag;
- DQi DQ;
- Hsi64i Hash;
- STi Store;
- inline void DEsopoPape (const int& src, Vi64& Distance, const VVIp& Graph) {
- Tag.assign (n + 1, 2);
- DQ.push_back (src), Distance[src] = 0LL;
- while (!DQ.empty ()) {
- int u = DQ.front ();
- DQ.pop_front (), Tag[u] = 0;
- for (const auto& e: Graph[u])
- if (Distance[e.first] > Distance[u] + e.second) {
- Distance[e.first] = Distance[u] + e.second;
- if (Tag[e.first] == 2)
- Tag[e.first] = 1, DQ.push_back (e.first);
- else if (!Tag[e.first])
- Tag[e.first] = 1, DQ.push_front (e.first);
- }
- }
- }
- int main () {
- std::cin >> n >> m;
- Graph.resize (n + 1), TGraph.resize (n + 1);
- DistanceX.assign (n + 1, Inf), DistanceY.assign (n + 1, Inf);
- for (int i = 1; i <= m; ++ i)
- std::cin >> u >> v >> w,
- Graph[u].emplace_back (std::make_pair (v, w)),
- TGraph[v].emplace_back (std::make_pair (u, w));
- DEsopoPape (1, DistanceX, Graph), DEsopoPape (n, DistanceY, TGraph);
- for (int u = 1; u <= n; ++ u)
- if (DistanceX[n] == DistanceX[u] + DistanceY[u])
- ++ Hash[DistanceX[u]];
- for (int u = 1; u <= n; ++ u)
- if (DistanceX[n] == DistanceX[u] + DistanceY[u] && Hash[DistanceX[u]] == 1)
- Store.insert (u);
- std::cout << Store.size () << "\n";
- for (const auto& u: Store)
- std::cout << u << " ";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement