답안 #517721

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
517721 2022-01-23T07:00:59 Z ivls Alias (COCI21_alias) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;

int n, m;
map<string, int> nn;
vector<int> g[5000];
int dst[5000][5000];

int dist(int st, int fi) {
    int dist[5000] = {};
    set<pair<int, int>> s;
    for (int i = 1; i <= n; i++) {
        dist[i] = (i == st ? 0 : 2000000000);
    }
    s.insert(dist[st], st);
    while (!s.empty()) {
        int v = (*s.begin()).second;
        s.erase(s.begin());
        for (int u : g[v]) {
            int len = dst[v][u];
            if (dist[v] + len < dist[u]) {
                s.erase(make_pair(dist[u], u));
                dist[u] = dist[v] + len;
                s.insert(make_pair(dist[u], u));
            }
        }
    }
    return dist[fi] == 2000000000 ? -1 : dist[fi];
}

int main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            dst[i][j] = 2000000000;
        }
    }
    int ii = 0;
    for (int i = 0; i < m; i++) {
        string u, v;
        cin >> u >> v;
        int t;
        cin >> t;
        if (nn[u] == 0) {
            nn[u] = ++ii;
        }
        if (nn[v] == 0) {
            nn[v] = ++ii;
        }
        g[nn[u]].push_back(nn[v]);
        dst[nn[u]][nn[v]] = min(dst[nn[u]][nn[v]], t);
    }
    int qq;
    cin >> qq;
    while (qq--) {
        string a, b;
        cin >> a >> b;
        if (nn[a] == 0) {
            nn[a] = ++ii;
        }
        if (nn[b] == 0) {
            nn[b] = ++ii;
        }
        int r = dist(nn[a], nn[b]);
        if (r == -1) {
            cout << "Roger" << '\n';
        }
        else {
            cout << r << '\n';
        }
    }

    return 0;
} 

Compilation message

In file included from /usr/include/c++/10/set:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:87,
                 from alias.cpp:1:
/usr/include/c++/10/bits/stl_set.h: In instantiation of 'void std::set<_Key, _Compare, _Alloc>::insert(_InputIterator, _InputIterator) [with _InputIterator = int; _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >]':
alias.cpp:16:26:   required from here
/usr/include/c++/10/bits/stl_set.h:567:31: error: no matching function for call to 'std::_Rb_tree<std::pair<int, int>, std::pair<int, int>, std::_Identity<std::pair<int, int> >, std::less<std::pair<int, int> >, std::allocator<std::pair<int, int> > >::_M_insert_range_unique(int&, int&)'
  567 |  { _M_t._M_insert_range_unique(__first, __last); }
      |    ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/10/map:60,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:81,
                 from alias.cpp:1:
/usr/include/c++/10/bits/stl_tree.h:1105:2: note: candidate: 'template<class _InputIterator> std::__enable_if_t<std::is_same<_Val, typename std::iterator_traits<_InputIterator>::value_type>::value> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_insert_range_unique(_InputIterator, _InputIterator) [with _InputIterator = _InputIterator; _Key = std::pair<int, int>; _Val = std::pair<int, int>; _KeyOfValue = std::_Identity<std::pair<int, int> >; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >]'
 1105 |  _M_insert_range_unique(_InputIterator __first, _InputIterator __last)
      |  ^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/10/bits/stl_tree.h:1105:2: note:   template argument deduction/substitution failed:
/usr/include/c++/10/bits/stl_tree.h: In substitution of 'template<class _InputIterator> std::__enable_if_t<std::is_same<std::pair<int, int>, typename std::iterator_traits< <template-parameter-1-1> >::value_type>::value, void> std::_Rb_tree<std::pair<int, int>, std::pair<int, int>, std::_Identity<std::pair<int, int> >, std::less<std::pair<int, int> >, std::allocator<std::pair<int, int> > >::_M_insert_range_unique<_InputIterator>(_InputIterator, _InputIterator) [with _InputIterator = int]':
/usr/include/c++/10/bits/stl_set.h:567:31:   required from 'void std::set<_Key, _Compare, _Alloc>::insert(_InputIterator, _InputIterator) [with _InputIterator = int; _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >]'
alias.cpp:16:26:   required from here
/usr/include/c++/10/bits/stl_tree.h:1105:2: error: no type named 'value_type' in 'struct std::iterator_traits<int>'
/usr/include/c++/10/bits/stl_set.h: In instantiation of 'void std::set<_Key, _Compare, _Alloc>::insert(_InputIterator, _InputIterator) [with _InputIterator = int; _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >]':
alias.cpp:16:26:   required from here
/usr/include/c++/10/bits/stl_tree.h:1114:2: note: candidate: 'template<class _InputIterator> std::__enable_if_t<(! std::is_same<_Val, typename std::iterator_traits<_InputIterator>::value_type>::value)> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_insert_range_unique(_InputIterator, _InputIterator) [with _InputIterator = _InputIterator; _Key = std::pair<int, int>; _Val = std::pair<int, int>; _KeyOfValue = std::_Identity<std::pair<int, int> >; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >]'
 1114 |  _M_insert_range_unique(_InputIterator __first, _InputIterator __last)
      |  ^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/10/bits/stl_tree.h:1114:2: note:   template argument deduction/substitution failed:
/usr/include/c++/10/bits/stl_tree.h: In substitution of 'template<class _InputIterator> std::__enable_if_t<(! std::is_same<std::pair<int, int>, typename std::iterator_traits< <template-parameter-1-1> >::value_type>::value), void> std::_Rb_tree<std::pair<int, int>, std::pair<int, int>, std::_Identity<std::pair<int, int> >, std::less<std::pair<int, int> >, std::allocator<std::pair<int, int> > >::_M_insert_range_unique<_InputIterator>(_InputIterator, _InputIterator) [with _InputIterator = int]':
/usr/include/c++/10/bits/stl_set.h:567:31:   required from 'void std::set<_Key, _Compare, _Alloc>::insert(_InputIterator, _InputIterator) [with _InputIterator = int; _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >]'
alias.cpp:16:26:   required from here
/usr/include/c++/10/bits/stl_tree.h:1113:52: error: no type named 'value_type' in 'struct std::iterator_traits<int>'
 1113 |  __enable_if_t<!__same_value_type<_InputIterator>::value>
      |                                                    ^~~~~