Language: C++

#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

int N, M, inf=a#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

int N, M, inf=1e9;
typedef pair<int, int> P;
typedef pair<int, P> PP;
map <P, vector<PP>> mp;
map <P, int> cost;

void dijkstra(P start){
    priority_queue < PP, vector<PP>, greater<PP> > q;
    for (auto itr = mp.begin(); itr != mp.end(); itr++) {
        cost[itr->first] = inf;
    }
    cost[start] = 0;
    q.push(PP(0, start));
    while (q.size()) {
        PP p = q.top();
        q.pop();
        P current_station = p.second;

        for (PP next : mp[current_station]) {
            P next_station = next.second;
            int c = next.first;
            if (cost[next_station] > cost[current_station] + c) {
                cost[next_station] = cost[current_station] + c;
                q.push(PP(cost[next_station], next_station));
            }
        }
    }
}

int main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        int p, q, c;
        cin >> p >> q >> c;
        mp[P(p, 0)].push_back(PP(1, P(p, c))); // 駅pで路線cに入る
        mp[P(p, c)].push_back(PP(0, P(q, c))); // 路線cでp->q
        mp[P(q, c)].push_back(PP(0, P(q, 0))); // 駅qで路線cから出る
        mp[P(q, 0)].push_back(PP(1, P(q, c))); // 駅qで路線cに入る
        mp[P(q, c)].push_back(PP(0, P(p, c))); // 路線cでq->p
        mp[P(p, c)].push_back(PP(0, P(p, 0))); // 駅pで路線cから出る
    }

    dijkstra(P(1, 0));

    int ans = cost[P(N, 0)] == 0 || cost[P(N, 0)] == inf ? -1 : cost[P(N, 0)];
    cout << ans << "\n";
    return 0;
};
typedef pair<int, int> P;
typedef pair<P, int> PP;
map <P, vector<PP>> mp;
map <P, int> cost;

void dijkstra(P start){
    priority_queue < P, vector<P>, greater<P> > q;
    map<P, vector<PP>>::iterator itr;
    for (itr = mp.begin(); itr != mp.end(); itr++) cost[itr->first] = inf;
    cost[start] = 0;
    q.push(start);
    while (q.size()) {
        P current_station = q.top();
        q.pop();
        for (PP next : mp[current_station]) {
            P next_station = next.first;
            int c = next.second;
            if (cost[next_station] > cost[current_station] + c) {
                cost[next_station] = cost[current_station] + c;
                q.push(next_station);
            }
        }
    }
}

int main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        int p, q, c;
        cin >> p >> q >> c;
        mp[P(p, 0)].push_back(PP(P(p, c), 1)); // 駅pで路線cに入る
        mp[P(p, c)].push_back(PP(P(q, c), 0)); // 路線cでp->q
        mp[P(q, c)].push_back(PP(P(q, 0), 0)); // 駅qで路線cから出る
        mp[P(q, 0)].push_back(PP(P(q, c), 1)); // 駅qで路線cに入る
        mp[P(q, c)].push_back(PP(P(p, c), 0)); // 路線cでq->p
        mp[P(p, c)].push_back(PP(P(p, 0), 0)); // 駅pで路線cから出る
    }

    dijkstra(P(1, 0));

    int ans = cost[P(N, 0)] == 0 || cost[P(N, 0)] == inf ? -1 : cost[P(N, 0)];
    cout << ans << "\n";
    return 0;
}

Compiler output:
a.cc:16:16: error: stray '#' in program
   16 | int N, M, inf=a#include <algorithm>
      |                ^
a.cc:16:15: error: 'a' was not declared in this scope
   16 | int N, M, inf=a#include <algorithm>
      |               ^
a.cc:31:5: error: redefinition of 'int N'
   31 | int N, M, inf=1e9;
      |     ^
a.cc:16:5: note: 'int N' previously declared here
   16 | int N, M, inf=a#include <algorithm>
      |     ^
a.cc:31:8: error: redefinition of 'int M'
   31 | int N, M, inf=1e9;
      |        ^
a.cc:16:8: note: 'int M' previously declared here
   16 | int N, M, inf=a#include <algorithm>
      |        ^
a.cc:31:11: error: redefinition of 'int inf'
   31 | int N, M, inf=1e9;
      |           ^~~
a.cc:16:11: note: 'int inf' previously defined here
   16 | int N, M, inf=a#include <algorithm>
      |           ^~~
a.cc:82:22: error: conflicting declaration 'typedef struct std::pair<std::pair<int, int>, int> PP'
   82 | typedef pair<P, int> PP;
      |                      ^~
a.cc:33:22: note: previous declaration as 'typedef struct std::pair<int, std::pair<int, int> > PP'
   33 | typedef pair<int, P> PP;
      |                      ^~
a.cc:83:21: error: redefinition of 'std::map<std::pair<int, int>, std::vector<std::pair<int, std::pair<int, int> > > > mp'
   83 | map <P, vector<PP>> mp;
      |                     ^~
a.cc:34:21: note: 'std::map<std::pair<int, int>, std::vector<std::pair<int, std::pair<int, int> > > > mp' previously declared here
   34 | map <P, vector<PP>> mp;
      |                     ^~
a.cc:84:14: error: redefinition of 'std::map<std::pair<int, int>, int> cost'
   84 | map <P, int> cost;
      |              ^~~~
a.cc:35:14: note: 'std::map<std::pair<int, int>, int> cost' previously declared here
   35 | map <P, int> cost;
      |              ^~~~
a.cc:86:6: error: redefinition of 'void dijkstra(P)'
   86 | void dijkstra(P start){
      |      ^~~~~~~~
a.cc:37:6: note: 'void dijkstra(P)' previously defined here
   37 | void dijkstra(P start){
      |      ^~~~~~~~
a.cc: In function 'void dijkstra(P)':
a.cc:96:35: error: conversion from 'int' to non-scalar type 'P' {aka 'std::pair<int, int>'} requested
   96 |             P next_station = next.first;
      |                              ~~~~~^~~~~
a.cc:97:26: error: cannot convert 'std::pair<int, int>' to 'int' in initialization
   97 |             int c = next.second;
      |                     ~~~~~^~~~~~
      |                          |
      |                          std::pair<int, int>
a.cc: At global scope:
a.cc:106:5: error: redefinition of 'int main()'
  106 | int main() {
      |     ^~~~
a.cc:60:5: note: 'int main()' previously defined here
   60 | int main() {
      |     ^~~~
a.cc: In function 'int main()':
a.cc:113:44: error: no matching function for call to 'std::pair<int, std::pair<int, int> >::pair(P, int)'
  113 |         mp[P(p, 0)].push_back(PP(P(p, c), 1)); // 駅pで路線cに入る
      |                                            ^
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/algorithm:60,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_pair.h:913:28: note: candidate: 'template<class _U1, class _U2, typename std::enable_if<(std::_PCC<((! std::is_same<int, _U1>::value) || (! std::is_same<std::pair<int, int>, _U2>::value)), int, std::pair<int, int> >::_MoveConstructiblePair<_U1, _U2>() && (! std::_PCC<((! std::is_same<int, _U1>::value) || (! std::is_same<std::pair<int, int>, _U2>::value)), int, std::pair<int, int> >::_ImplicitlyMoveConvertiblePair<_U1, _U2>())), bool>::type <anonymous> > constexpr std::pair<_T1, _T2>::pair(std::pair<_U1, _U2>&&) [with _U2 = _U1; typename std::enable_if<(std::_PCC<((! std::is_same<_T1, _U1>::value) || (! std::is_same<_T2, _U2>::value)), _T1, _T2>::_MoveConstructiblePair<_U1, _U2>() && (! std::_PCC<((! std::is_same<_T1, _U1>::value) || (! std::is_same<_T2, _U2>::value)), _T1, _T2>::_ImplicitlyMoveConvertiblePair<_U1, _U2>())), bool>::type <anonymous> = _U2; _T1 = int; _T2 = std::pair<int, int>]'
  913 |         explicit constexpr pair(pair<_U1, _U2>&& __p)
      |                            ^~~~
/usr/include/c++/14/bits/stl_pair.h:913:28: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_pair.h:902:19: note: candidate: 'template<class _U1, class _U2, typename std::enable_if<(std::_PCC<((! std::is_same<int, _U1>::value) || (! std::is_same<std::pair<int, int>, _U2>::value)), int, std::pair<int, int> >::_MoveConstructiblePair<_U1, _U2>() && std::_PCC<((! std::is_same<int, _U1>::value) || (! std::is_same<std::pair<int, int>, _U2>::value)), int, std::pair<int, int> >::_ImplicitlyMoveConvertiblePair<_U1, _U2>()), bool>::type <anonymous> > constexpr std::pair<_T1, _T2>::pair(std::pair<_U1, _U2>&&) [with _U2 = _U1; typename std::enable_if<(std::_PCC<((! std::is_same<_T1, _U1>::value) || (! std::is_same<_T2, _U2>::value)), _T1, _T2>::_MoveConstructiblePair<_U1, _U2>() && std::_PCC<((! std::is_same<_T1, _U1>::value) || (! std::is_same<_T2, _U2>::value)), _T1, _T2>::_ImplicitlyMoveConvertiblePair<_U1, _U2>()), bool>::type <anonymous> = _U2; _T1 = int; _T2 = std::pair<int, int>]'
  902 |         constexpr pair(pair<_U1, _U2>&& __p)
      |                   ^~~~
/usr/include/c++/14/bits/stl_pair.h:902:19: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_pair.h:891:28: note: candidate: 'template<class _U1, class _U2, typename std::enable_if<(_MoveConstructiblePair<_U1, _U2>() && (! _ImplicitlyMoveConvertiblePair<_U1, _U2>())), bool>::type <anonymous> > constexpr std::pair<_T1, _T2>::pair(_U1&&, _U2&&) [with _U2 = _U1; typename std::enable_if<(std::_PCC<true, _T1, _T2>::_MoveConstructiblePair<_U1, _U2>() && (! std::_PCC<true, _T1, _T2>::_ImplicitlyMoveConvertiblePair<_U1, _U2>())), bool>::type <anonymous> = _U2; _T1 = int; _T2 = std::pair<int, int>]'
  891 |         explicit constexpr pair(_U1&& __x, _U2&& __y)
      |                            ^~~~
/usr/include/c++/14/bits/stl_pair.h:891:28: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_pair.h:890:38: error: no type named 'type' in 'struct std::enable_if<false, bool>'
  890 |                          bool>::type=false>
      |                                      ^~~~~
/usr/include/c++/14/bits/stl_pair.h:881:19: note: candidate: 'template<class _U1, class _U2, typename std::enable_if<(_MoveConstructiblePair<_U1, _U2>() && _ImplicitlyMoveConvertiblePair<_U1, _U2>()), bool>::type <anonymous> > constexpr std::pair<_T1, _T2>::pair(_U1&&, _U2&&) [with _U2 = _U1; typename std::enable_if<(std::_PCC<true, _T1, _T2>::_MoveConstructiblePair<_U1, _U2>() && std::_PCC<true, _T1, _T2>::_ImplicitlyMoveConvertiblePair<_U1, _U2>()), bool>::type <anonymous> = _U2; _T1 = int; _T2 = std::pair<int, int>]'
  881 |         constexpr pair(_U1&& __x, _U2&& __y)
      |                   ^~~~
/usr/include/c++/14/bits/stl_pair.h:881:19: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_pair.h:880:38: error: no type named 'type' in 'struct std::enable_if<false, bool>'
  880 |                          bool>::type=true>
      |                                      ^~~~
/usr/include/c++/14/bits/stl_pair.h:869:9: note: candidate: 'template<class _U2, typename std::enable_if<std::__and_<std::is_pointer<int>, std::__not_<std::is_reference<_Tp> >, std::is_constructible<std::pair<int, int>, _U2>, std::__not_<std::is_constructible<std::pair<int, int>, const _U1&> >, std::__not_<std::is_convertible<_U2, std::pair<int, int> > > >::value, bool>::type <anonymous> > constexpr std::pair<_T1, _T2>::pair(__zero_as_null_pointer_constant, _U2&&, ...) [with typename std::enable_if<std::__and_<std::is_pointer<_Tp>, std::__not_<std::is_reference<_U1> >, std::is_constructible<_T2, _U2>, std::__not_<std::is_constructible<_T1, const _U1&> >, std::__not_<std::is_convertible<_U2, _T2> > >::value, bool>::type <anonymous> = _U2; _T1 = int; _T2 = std::pair<int, int>]'
  869 |         pair(__zero_as_null_pointer_constant, _U2&& __y, ...)
      |         ^~~~
/usr/include/c++/14/bits/stl_pair.h:869:9: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_pair.h:866:38: error: no type named 'type' in 'struct std::enable_if<false, bool>'
  866 |                              bool> = false>
      |                                      ^~~~~
/usr/include/c++/14/bits/stl_pair.h:856:9: note: candidate: 'template<class _U2, typename std::enable_if<std::__and_<std::is_pointer<int>, std::__not_<std::is_reference<_Tp> >, std::is_constructible<std::pair<int, int>, _U2>, std::__not_<std::is_constructible<std::pair<int, int>, const _U1&> >, std::is_convertible<_U2, std::pair<int, int> > >::value, bool>::type <anonymous> > constexpr std::pair<_T1, _T2>::pair(__zero_as_null_pointer_constant, _U2&&, ...) [with typename std::enable_if<std::__and_<std::is_pointer<_Tp>, std::__not_<std::is_reference<_U1> >, std::is_constructible<_T2, _U2>, std::__not_<std::is_constructible<_T1, const _U1&> >, std::is_convertible<_U2, _T2> >::value, bool>::type <anonymous> = _U2; _T1 = int; _T2 = std::pair<int, int>]'
  856 |         pair(__zero_as_null_pointer_constant, _U2&& __y, ...)
      |         ^~~~
/usr/include/c++/14/bits/stl_pair.h:856:9: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_pair.h:853:38: error: no type named 'type' in 'struct std::enable_if<false, bool>'
  853 |                              bool> = true>
      |                                      ^~~~
/usr/include/c++/14/bits/stl_pair.h:843:9: note: candidate: 'template<class _U1, typename std::enable_if<std::__and_<std::__not_<std::is_reference<_Tp> >, std::is_pointer<std::pair<int, int> >, std::is_constructible<int, _U1>, std::__not_<std::is_constructible<int, const _U1&> >, std::__not_<std::is_convertible<_U1, int> > >::value, bool>::type <anonymous> > constexpr std::pair<_T1, _T2>::pair(_U1&&, __zero_as_null_pointer_constant, ...) [with typename std::enable_if<std::__and_<std::__not_<std::is_reference<_U1> >, std::is_pointer<_T2>, std::is_constructible<_T1, _U1>, std::__not_<std::is_constructible<_T1, const _U1&> >, s