제출 #1069910

#제출 시각아이디문제언어결과실행 시간메모리
1069910vjudge1Petrol stations (CEOI24_stations)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; long long int size[1002]; int vis[1002]; vector<pair<int,long long int>> adjl[1002]; void dfs(int s){ vis[s]++; for(int i = 0; i < adjl[s].size(); i++){ if(vis[adjl[s][i].first] == 0){ dfs(adjl[s][i].first); size[s] += size[adjl[s][i].first]; } } size[s]++; } int main() { int n, k; cin >> n >> k; for(int i = 0; i < (n - 1); i++){ int u, v; cin >> u >> v; long long int l; cin >> l; adjl[u].push_back({v,l}); adjl[v].push_back({u, l}); } long long int ans[n]; for(int i = 0; i < n; i++){ ans[i] = 0; } for(int i = 0; i < n; i++){ long long int cap[n]; for(int j = 0; j < n; j++){ size[j] = 0; cap[j] = 0; vis[j] = 0; } dfs(i); cap[i] = k; for(int j = 0; j < n; j++){ vis[j] = 0; } queue<int>q; q.push(i); vis[i]++; while(!q.empty()){ int a = q.front(); q.pop(); for(int j = 0; j < adjl[a].size(); j++){ pair<int,long long int> p = adjl[a][j]; int x = p.first; long long int dist = p.second; if(vis[x] == 0){ if(cap[a] >= dist){ cap[x] = cap[a] - dist; }else{ ans[a] += size[x]; cap[x] = k - dist; } q.push(x); vis[x]++; } } } } for(int i = 0; i < n; i++){ cout << ans[i] << endl; } }

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'void dfs(int)':
Main.cpp:8:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |     for(int i = 0; i < adjl[s].size(); i++){
      |                    ~~^~~~~~~~~~~~~~~~
Main.cpp:11:13: error: reference to 'size' is ambiguous
   11 |             size[s] += size[adjl[s][i].first];
      |             ^~~~
In file included from /usr/include/c++/10/string:54,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from Main.cpp:2:
/usr/include/c++/10/bits/range_access.h:254:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  254 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:245:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  245 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
Main.cpp:4:15: note:                 'long long int size [1002]'
    4 | long long int size[1002];
      |               ^~~~
Main.cpp:11:24: error: reference to 'size' is ambiguous
   11 |             size[s] += size[adjl[s][i].first];
      |                        ^~~~
In file included from /usr/include/c++/10/string:54,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from Main.cpp:2:
/usr/include/c++/10/bits/range_access.h:254:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  254 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:245:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  245 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
Main.cpp:4:15: note:                 'long long int size [1002]'
    4 | long long int size[1002];
      |               ^~~~
Main.cpp:14:5: error: reference to 'size' is ambiguous
   14 |     size[s]++;
      |     ^~~~
In file included from /usr/include/c++/10/string:54,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from Main.cpp:2:
/usr/include/c++/10/bits/range_access.h:254:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  254 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:245:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  245 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
Main.cpp:4:15: note:                 'long long int size [1002]'
    4 | long long int size[1002];
      |               ^~~~
Main.cpp: In function 'int main()':
Main.cpp:36:12: error: reference to 'size' is ambiguous
   36 |            size[j] = 0;
      |            ^~~~
In file included from /usr/include/c++/10/string:54,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from Main.cpp:2:
/usr/include/c++/10/bits/range_access.h:254:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  254 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:245:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  245 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
Main.cpp:4:15: note:                 'long long int size [1002]'
    4 | long long int size[1002];
      |               ^~~~
Main.cpp:51:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |            for(int j = 0; j < adjl[a].size(); j++){
      |                           ~~^~~~~~~~~~~~~~~~
Main.cpp:59:34: error: reference to 'size' is ambiguous
   59 |                        ans[a] += size[x];
      |                                  ^~~~
In file included from /usr/include/c++/10/string:54,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from Main.cpp:2:
/usr/include/c++/10/bits/range_access.h:254:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  254 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:245:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  245 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
Main.cpp:4:15: note:                 'long long int size [1002]'
    4 | long long int size[1002];
      |               ^~~~