답안 #29794

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
29794 2017-07-20T19:55:19 Z kavun 꿈 (IOI13_dreaming) C++14
컴파일 오류
0 ms 0 KB
#include "dreaming.h"
#include <bits/stdc++.h>
#define pb push_back

using namespace std;
typedef pair<int,int> ii;
vector <ii> adj[100010];
bool mk[100010];
int maxDist, end,ans;
ii p[100010];
vector <int> r;

void dfs(int v, int par, int len, int flag)
{
  if(flag)
    mk[v] = true;

  if(len > maxDist)
    {
      maxDist = len;
      end = v;
    }

  for(int i = 0; i < adj[v].size(); i++)
    {
      int u = adj[v][i].first;
      if(u == par) continue;
      int weight = adj[v][i].second;
      if(flag)
	p[u] = ii(v,weight);
      dfs(u,v,len+weight,flag);
    }
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
  for(int i = 0; i < M; i++)
    {
      adj[A[i]].pb(ii(B[i],T[i]));
      adj[B[i]].pb(ii(A[i],T[i]));
    }

  for(int i = 0; i < N; i++)
    {
      if(mk[i]) continue;
      maxDist = -1;
      dfs(i,i,0,0);
      maxDist = -1;
      int first = end;
      dfs(first,first,0,1);
      ans = max(ans,maxDist);
      int second = end;
      int halfdiam = maxDist / 2;
      int radius = 0;
      for(int ver = second; ver != first; ver = p[ver].first)
	{
	  if(radius + p[ver].second > halfdiam)
	    {
	      radius = max(radius,maxDist - radius);
	      break;
	    }
	  	  radius += p[ver].second;
	}
      r.pb(radius);
    }
    
  sort(r.begin(),r.end());
  reverse(r.begin(),r.end());

  if(r.size() == 1)
    return ans;
  if(r.size() == 2) 
    return max(ans,r[0] + r[1] + L);
  else 
    return max(ans,max(r[1] + r[2] + L + L,r[0] + r[1] + L));

}

Compilation message

dreaming.cpp: In function 'void dfs(int, int, int, int)':
dreaming.cpp:21:7: error: reference to 'end' is ambiguous
       end = v;
       ^~~
dreaming.cpp:9:14: note: candidates are: int end
 int maxDist, end,ans;
              ^~~
In file included from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:95:0,
                 from dreaming.cpp:2:
/usr/include/c++/7/valarray:1231:5: note:                 template<class _Tp> const _Tp* std::end(const std::valarray<_Tp>&)
     end(const valarray<_Tp>& __va)
     ^~~
/usr/include/c++/7/valarray:1221:5: note:                 template<class _Tp> _Tp* std::end(std::valarray<_Tp>&)
     end(valarray<_Tp>& __va)
     ^~~
In file included from /usr/include/c++/7/string:51:0,
                 from /usr/include/c++/7/bits/locale_classes.h:40,
                 from /usr/include/c++/7/bits/ios_base.h:41,
                 from /usr/include/c++/7/ios:42,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from dreaming.cpp:2:
/usr/include/c++/7/bits/range_access.h:97:5: note:                 template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])
     end(_Tp (&__arr)[_Nm])
     ^~~
/usr/include/c++/7/bits/range_access.h:78:5: note:                 template<class _Container> decltype (__cont.end()) std::end(const _Container&)
     end(const _Container& __cont) -> decltype(__cont.end())
     ^~~
/usr/include/c++/7/bits/range_access.h:68:5: note:                 template<class _Container> decltype (__cont.end()) std::end(_Container&)
     end(_Container& __cont) -> decltype(__cont.end())
     ^~~
In file included from /usr/include/c++/7/bits/range_access.h:36:0,
                 from /usr/include/c++/7/string:51,
                 from /usr/include/c++/7/bits/locale_classes.h:40,
                 from /usr/include/c++/7/bits/ios_base.h:41,
                 from /usr/include/c++/7/ios:42,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from dreaming.cpp:2:
/usr/include/c++/7/initializer_list:99:5: note:                 template<class _Tp> constexpr const _Tp* std::end(std::initializer_list<_Tp>)
     end(initializer_list<_Tp> __ils) noexcept
     ^~~
dreaming.cpp:24:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < adj[v].size(); i++)
                  ~~^~~~~~~~~~~~~~~
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:48:19: error: reference to 'end' is ambiguous
       int first = end;
                   ^~~
dreaming.cpp:9:14: note: candidates are: int end
 int maxDist, end,ans;
              ^~~
In file included from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:95:0,
                 from dreaming.cpp:2:
/usr/include/c++/7/valarray:1231:5: note:                 template<class _Tp> const _Tp* std::end(const std::valarray<_Tp>&)
     end(const valarray<_Tp>& __va)
     ^~~
/usr/include/c++/7/valarray:1221:5: note:                 template<class _Tp> _Tp* std::end(std::valarray<_Tp>&)
     end(valarray<_Tp>& __va)
     ^~~
In file included from /usr/include/c++/7/string:51:0,
                 from /usr/include/c++/7/bits/locale_classes.h:40,
                 from /usr/include/c++/7/bits/ios_base.h:41,
                 from /usr/include/c++/7/ios:42,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from dreaming.cpp:2:
/usr/include/c++/7/bits/range_access.h:97:5: note:                 template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])
     end(_Tp (&__arr)[_Nm])
     ^~~
/usr/include/c++/7/bits/range_access.h:78:5: note:                 template<class _Container> decltype (__cont.end()) std::end(const _Container&)
     end(const _Container& __cont) -> decltype(__cont.end())
     ^~~
/usr/include/c++/7/bits/range_access.h:68:5: note:                 template<class _Container> decltype (__cont.end()) std::end(_Container&)
     end(_Container& __cont) -> decltype(__cont.end())
     ^~~
In file included from /usr/include/c++/7/bits/range_access.h:36:0,
                 from /usr/include/c++/7/string:51,
                 from /usr/include/c++/7/bits/locale_classes.h:40,
                 from /usr/include/c++/7/bits/ios_base.h:41,
                 from /usr/include/c++/7/ios:42,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from dreaming.cpp:2:
/usr/include/c++/7/initializer_list:99:5: note:                 template<class _Tp> constexpr const _Tp* std::end(std::initializer_list<_Tp>)
     end(initializer_list<_Tp> __ils) noexcept
     ^~~
dreaming.cpp:51:20: error: reference to 'end' is ambiguous
       int second = end;
                    ^~~
dreaming.cpp:9:14: note: candidates are: int end
 int maxDist, end,ans;
              ^~~
In file included from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:95:0,
                 from dreaming.cpp:2:
/usr/include/c++/7/valarray:1231:5: note:                 template<class _Tp> const _Tp* std::end(const std::valarray<_Tp>&)
     end(const valarray<_Tp>& __va)
     ^~~
/usr/include/c++/7/valarray:1221:5: note:                 template<class _Tp> _Tp* std::end(std::valarray<_Tp>&)
     end(valarray<_Tp>& __va)
     ^~~
In file included from /usr/include/c++/7/string:51:0,
                 from /usr/include/c++/7/bits/locale_classes.h:40,
                 from /usr/include/c++/7/bits/ios_base.h:41,
                 from /usr/include/c++/7/ios:42,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from dreaming.cpp:2:
/usr/include/c++/7/bits/range_access.h:97:5: note:                 template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])
     end(_Tp (&__arr)[_Nm])
     ^~~
/usr/include/c++/7/bits/range_access.h:78:5: note:                 template<class _Container> decltype (__cont.end()) std::end(const _Container&)
     end(const _Container& __cont) -> decltype(__cont.end())
     ^~~
/usr/include/c++/7/bits/range_access.h:68:5: note:                 template<class _Container> decltype (__cont.end()) std::end(_Container&)
     end(_Container& __cont) -> decltype(__cont.end())
     ^~~
In file included from /usr/include/c++/7/bits/range_access.h:36:0,
                 from /usr/include/c++/7/string:51,
                 from /usr/include/c++/7/bits/locale_classes.h:40,
                 from /usr/include/c++/7/bits/ios_base.h:41,
                 from /usr/include/c++/7/ios:42,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from dreaming.cpp:2:
/usr/include/c++/7/initializer_list:99:5: note:                 template<class _Tp> constexpr const _Tp* std::end(std::initializer_list<_Tp>)
     end(initializer_list<_Tp> __ils) noexcept
     ^~~