답안 #964526

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
964526 2024-04-17T05:11:11 Z UmairAhmadMirza 꿈 (IOI13_dreaming) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
int const NN=1e5+5;
vector<int> adj[NN];
map<pair<int,int>,int> wei;
int n;
multiset<int> dist[NN];
bool vis[NN];
int max_d[NN];
void dfs(int node){
	vis[node]=1;
	dist[node].insert(0);
	dist[node].insert(0);
	for (auto i:adj[node])
		if(vis[i]==0){
			dfs(i);
			dist[node].insert(*(dist[i].rbegin())+wei[{node,i}]);
		}
}
void change_root(int u,int v){
	dist[v].erase(dist[v].find(*(dist[u].rbegin())+wei[{u,v}]));
	dist[u].insert(*(dist[v].rbegin())+wei[{u,v}]);
}
int find_r=1e9;
int ans1=0;
void reroot(int node,int par){
	max_d[node]=*(dist[node].rbegin());
	find_r=min(find_r,max_d[node]);
	auto p=dist[node].end();
	p--;p--;
	ans1=max(ans1,max_d[node]+(*(p)));
	for (auto i:adj[node])
		if(i!=par){
			change_root(i,node);
			reroot(i,node);
			change_root(node,i);
		}
}
int travelTime(int nn, int mm, int L, int A[], int B[], int T[]){
	n=nn;
	for (int i = 0; i < mm; ++i)
	{
		int u=A[i];
		int v=B[i];
		adj[u].push_back(v);
		adj[v].push_back(u);
		wei[{u,v}]=T[i];
		wei[{v,u}]=T[i];
	}
	int ans=L;
	int cnt=0;
	vector<int> vec;
	for (int i = 0; i < n; ++i)
		if(vis[i]==0){
			dfs(i);
			find_r=*(dist[i].rbegin());
			reroot(i,-1);
			vec.push_back(find_r);
			cnt++;
		}
	sort(vec.begin(), vec.end());
	if(cnt==1)
		return ans1;
	ans+=vec[cnt-1]+vec[cnt-2];
	if(cnt==2)
		return max(ans,ans1);
	ans=max(ans,vec[cnt-2]+vec[cnt-3]+L+L);
	// for (int i = 0; i < n; ++i)
	// 	cout<<max_d[i]<<endl;
	return max(ans,ans1);
}

Compilation message

/usr/bin/ld: /tmp/ccWOFTp2.o: in function `main':
grader.c:(.text.startup+0xd1): undefined reference to `travelTime'
collect2: error: ld returned 1 exit status