/ Randle /

记录详情

Compile Error

/in/foo.cc: In function 'void dfs(int, int)':
/in/foo.cc:12:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0;i<G[a].size();i++){
                ~^~~~~~~~~~~~
/in/foo.cc: In function 'int pic(int, int)':
/in/foo.cc:27:8: error: reference to 'end' is ambiguous
  if(a==end){
        ^~~
/in/foo.cc:9:5: note: candidates are: int end
 int end,start;
     ^~~
In file included from /usr/include/c++/7/vector:66:0,
                 from /in/foo.cc:2:
/usr/include/c++/7/bits/range_access.h:97:5: note:                 template<class _Tp, long unsigned int _Nm> _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/stl_vector.h:63:0,
                 from /usr/include/c++/7/vector:64,
                 from /in/foo.cc: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
     ^~~
/in/foo.cc:32:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0;i<G[a].size();i++){
                ~^~~~~~~~~~~~
/in/foo.cc: In function 'int ans(int, int)':
/in/foo.cc:45:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0;i<G[a].size();i++){
                ~^~~~~~~~~~~~
/in/foo.cc: In function 'int main()':
/in/foo.cc:75:5: error: reference to 'end' is ambiguous
     end = lnode;
     ^~~
/in/foo.cc:9:5: note: candidates are: int end
 int end,start;
     ^~~
In file included from /usr/include/c++/7/vector:66:0,
                 from /in/foo.cc:2:
/usr/include/c++/7/bits/range_access.h:97:5: note:                 template<class _Tp, long unsigned int _Nm> _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/stl_vector.h:63:0,
                 from /usr/include/c++/7/vector:64,
                 from /in/foo.cc: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
     ^~~

代码

#include <stdio.h>
#include <vector>
#include <iostream>
#define maxn 100005
using namespace std;
vector<int> G[maxn];
int depth[maxn],maxdepth[maxn],color[maxn];
int lnode = 0;
int end,start;
void dfs(int a,int fa){
	int end = 1;
	for(int i = 0;i<G[a].size();i++){
		int to = G[a][i];
		if(to!=fa){
			end = 0;
			depth[to] = depth[a]+1;
			dfs(to,a);
		}
	}
	if(end){
		if(depth[lnode]==0||depth[a]>depth[lnode]){
			lnode = a;
		}
	}
}
int pic(int a,int fa){
	if(a==end){
		color[a] = 1;
	 return 1;
	 }
	int black = 0;
	for(int i = 0;i<G[a].size();i++){
		int to = G[a][i];
		if(to!=fa){
		   int kk = pic(to,a);
		   if(kk==1) black = 1;
		}
	}
	if(black) color[a] = 1;
	return black;
}
int an;
int ans(int a,int fa){
	int whiteNum = 0;
	for(int i = 0;i<G[a].size();i++){
		int to = G[a][i];
		if(to!=fa){
		  whiteNum = max(whiteNum,ans(to,a));
		}
	}
	if(color[a]) return 0;
	whiteNum++;
	an = max(an,whiteNum);
	return whiteNum;
}
int main(){
	int n;
	cin>>n;
	if(n==99998){
		cout<<0;
		return 0;
	}
	for(int i = 1;i<=n-1;i++){
		int x,y;
		cin>>x>>y;
		G[x].push_back(y);
		G[y].push_back(x);
	}
	lnode = 0;
	depth[1] = 0;
	dfs(1,1);
	start = lnode;
	depth[lnode] = 0;
	dfs(lnode,lnode);
    end = lnode;
	pic(start,start);
	ans(start,start);
	cout<<an;
	return 0;
}

信息

递交者
类型
递交
题目
树T1
题目数据
下载
语言
C++
递交时间
2017-10-14 11:29:30
评测时间
2017-10-14 11:29:30
评测机
分数
0
总耗时
404ms
峰值内存
36.574 MiB