답안 #109412

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
109412 2019-05-06T12:41:20 Z amiratou 꿈 (IOI13_dreaming) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define INF (int)(1e9)
using namespace std;
vector<vector<pair<int,int> > > vec;
bool vis[100005];
int maxi=0,A,idx=0;
pair<int,int> p[100005],center[100005];
vector<int> nodes;
void dfs(int node,int d){
	//debug(node);
	//debugs(d,maxi);
	nodes.push_back(node);
	if(d>maxi)
		A=node,maxi=d;
	vis[node]=1;
	for(auto child:vec[node])
		if(child.fi!=p[node].fi){
			vis[child.fi]=1;
			p[child.fi]={node,child.se};
			dfs(child.fi,d+child.se);
		}
}
vector<pair<int,int> > tree_d;
pair<int,int> findCenter(int node){
	maxi=0;
	dfs(node,0);
	//debug(maxi);
	for(auto i:nodes)
		p[i]={-1,-1};
	nodes.clear();
	int B=A,sum=0,mini=INF,c=node,sh=INF;
	maxi=0;
	dfs(B,0);
	nodes.clear();
	//debugs(node,maxi);debugs(A,B);
	for(;A!=-1;sum+=p[A].se,A=p[A].fi){
		//debugs(A,sum);
		if(abs(maxi/2-sum)<mini)
			mini=abs(maxi/2-sum),c=A,sh=sum;
	}
	//debugs(c,);
	//sep()
	tree_d.push_back({maxi,idx});
	return {c,max(maxi-sh,0)};
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
	vec.resize(N);
	for (int i = 0; i < M; ++i)
	{
		//debug(A[i]);
		vec[A[i]].push_back({B[i],T[i]});
		vec[B[i]].push_back({A[i],T[i]});
	}
	//debug(1);
	for (int i = 0; i < N; ++i)
		if(!vis[i])
			center[idx++]=findCenter(i);
	sort(tree_d.begin(),tree_d.end(),greater<pair<int,int> >());
	int centroid=center[0].first,ans=tree_d[0].fi,max_d=0;
	for (int i = 0; i < idx-1; ++i)
	{
		//max_d=max(max_d,center[tree_d[i+1].se].se);
		//max_d=max(max_d,center[tree_d[i].se].se);
		if(center[tree_d[i+1].se].se>center[tree_d[i].se].se)
			centroid=center[tree_d[i+1].se].fi;
		ans=max(ans,center[tree_d[i+1].se].se+center[tree_d[i].se].se+2);
		//debug(ans);
		//ans=max(ans,max_d)
	}
    return ans;
}

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:61:6: warning: variable 'centroid' set but not used [-Wunused-but-set-variable]
  int centroid=center[0].first,ans=tree_d[0].fi,max_d=0;
      ^~~~~~~~
dreaming.cpp:61:48: warning: unused variable 'max_d' [-Wunused-variable]
  int centroid=center[0].first,ans=tree_d[0].fi,max_d=0;
                                                ^~~~~
/tmp/ccjKYcHB.o: In function `main':
grader.c:(.text.startup+0xa2): undefined reference to `travelTime'
collect2: error: ld returned 1 exit status