Language: C++

#include <iostream>
#include <map>
#include <vector>

#define MAX_INT 100000000

using namespace std;

map<string, map<string, int>> data;
map<string, int> cals;

// 再帰関数で使用
map<string, bool> pass;
map<string, int> mins;

int min_value = MAX_INT;

void recursive(string curr, int cal)
{
    map<string, int>::iterator it = data[curr].begin();

    while (it != data[curr].end())
    {
        string key = (*it).first;
        int value = (*it).second;

        if (pass[key] == true) {
            ++it; continue;
        }

        int after = data[curr][key] + cal;
        if (key[0] != 'C' && after >= mins[key]) {
            ++it; continue;
        }

        int temp = mins[key];

        if (key[0] == 'C') {
            after -= cals[key];
            pass[key] = true;
        }
        mins[key] = after;

        if (key == "D" && mins["D"] < min_value) {
            min_value = mins["D"];
        }

        recursive(key, after);

        if (key[0] == 'C') pass[key] = false;
        mins[key] = temp;

        ++it;
    }
}

int main(void)
{
    for (;;) {
        int m, n, k, d;

        // 初期化
        min_value = MAX_INT;

        scanf("%d %d %d %d", &m, &n, &k, &d);

        if (m == 0 && n == 0 && k == 0 && d == 0) {
            break;
        }

        // 標準入力からデータを取得
        data.clear();
        cals.clear();

        for (int i = 0; i < m; i++) {
            int temp;
            scanf("%d", &temp);
            cals["C"+to_string(i+1)] = temp;
        }
        for (int i = 0; i < d; i++) {
            string s, t;
            int temp;
            cin >> s >> t >> temp;
            data[s][t] = temp * k;
            data[t][s] = temp * k;
        }

        // 再帰関数を使うための準備
        pass.clear();
        mins.clear();

        for (int i = 0; i < m; i++) {
            pass["C"+to_string(i+1)] = false;
        }
        for (int i = 0; i < (n + 2); i++) {
            switch (i) {
            case 0:  mins["H"] = MAX_INT; break;
            case 1:  mins["D"] = MAX_INT; break;
            default: mins["L"+to_string(i-1)] = MAX_INT;
            }
        }

        recursive("H", 0);
        cout << min_value << endl;
    }

    return 0;
}

Compiler output:
a.cc: In function 'void recursive(std::string, int)':
a.cc:20:37: error: reference to 'data' is ambiguous
   20 |     map<string, int>::iterator it = data[curr].begin();
      |                                     ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:9:31: note:                 'std::map<std::__cxx11::basic_string<char>, std::map<std::__cxx11::basic_string<char>, int> > data'
    9 | map<string, map<string, int>> data;
      |                               ^~~~
a.cc:22:18: error: reference to 'data' is ambiguous
   22 |     while (it != data[curr].end())
      |                  ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:9:31: note:                 'std::map<std::__cxx11::basic_string<char>, std::map<std::__cxx11::basic_string<char>, int> > data'
    9 | map<string, map<string, int>> data;
      |                               ^~~~
a.cc:31:21: error: reference to 'data' is ambiguous
   31 |         int after = data[curr][key] + cal;
      |                     ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:9:31: note:                 'std::map<std::__cxx11::basic_string<char>, std::map<std::__cxx11::basic_string<char>, int> > data'
    9 | map<string, map<string, int>> data;
      |                               ^~~~
a.cc: In function 'int main()':
a.cc:72:9: error: reference to 'data' is ambiguous
   72 |         data.clear();
      |         ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:9:31: note:                 'std::map<std::__cxx11::basic_string<char>, std::map<std::__cxx11::basic_string<char>, int> > data'
    9 | map<string, map<string, int>> data;
      |                               ^~~~
a.cc:84:13: error: reference to 'data' is ambiguous
   84 |             data[s][t] = temp * k;
      |             ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:9:31: note:                 'std::map<std::__cxx11::basic_string<char>, std::map<std::__cxx11::basic_string<char>, int> > data'
    9 | map<string, map<string, int>> data;
      |                               ^~~~
a.cc:85:13: error: reference to 'data' is ambiguous
   85 |             data[t][s] = temp * k;
      |             ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:9:31: note:                 'std::map<std::__cxx11::basic_string<char>, std::map<std::__cxx11::basic_string<char>, int> > data'
    9 | map<string, map<string, int>> data;
      |                               ^~~~