답안 #897398

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
897398 2024-01-03T03:46:37 Z Faisal_Saqib 꿈 (IOI13_dreaming) C++17
컴파일 오류
0 ms 0 KB
// #include "dreaming.h"
#include <iostream>
#include <vector>
using namespace std; 
const long long N=1e5+200;
vector<pair<long long,long long>> ma[N];
bool vis[N];
bool tp=0;
long long dp_down[N][2];
long long dp_up[N];
long long mxx[N];
long long n,m,l;
void dfs_down(long long x,long long p=-1)
{
	vis[x]=1;
	dp_down[x][0]=dp_down[x][1]=0;
	for(auto [w,y]:ma[x])
	{
		if(y!=p)
		{
			dfs_down(y,x);
			long long cur=dp_down[y][0]+w;
			if(dp_down[x][0]<cur)
			{
				dp_down[x][1]=dp_down[x][0];
				dp_down[x][0]=cur;
			}
			else if(dp_down[x][1]<cur)
			{
				dp_down[x][1]=cur;
			}
		}
	}
	// if(tp)
	// {
	// 	cout<<"For "<<x<<' '<<p<<endl;
	// 	cout<<dp_down[x][0]<<' '<<dp_down[x][1]<<endl;
	// }
}
long long vertex=-1;
long long dist=1e18;
long long cp=-1;
void fill()
{
	for(int i=0;i<n;i++)
		dp_up[i]=0;
}
void dfs_up(long long x,long long p=-1)
{
	mxx[x]=max(dp_up[x],dp_down[x][0]);
	cp=max(cp,mxx[x]);
	// if(tp)
	// {
	// 	cout<<"For "<<x<<' '<<mxx[x]<<endl;
	// }
	if(mxx[x]<dist)
	{
		dist=mxx[x];
		vertex=x;
	}
	for(auto [w,y]:ma[x])
	{
		if(y!=p)
		{
			dp_up[y]=dp_up[x]+w;
			if(dp_down[x][0]==(dp_down[y][0]+w))
				dp_up[y]=max(dp_up[y],dp_down[x][1]+w);
			else
				dp_up[y]=max(dp_up[y],dp_down[x][0]+w);
			dfs_up(y,x);
		}
	}
}
int travelTime(int N, int M, int L, int a[], int b[], int t[])
{
	n=N;
	m=M;
	l=L;
	for(int i=0;i<m;i++)
	{
		ma[a[i]].push_back({t[i],b[i]});
		ma[b[i]].push_back({t[i],a[i]});
	}
	for(int i=0;i<n;i++)
	{
		if(!vis[i]){
			long long bv=vertex;
			long long bd=dist;
			vertex=-1;
			dist=1e18;
			dfs_down(i);
			dfs_up(i);
			if(bv!=-1)
			{
				ma[bv].push_back({l,vertex});
				ma[vertex].push_back({l,bv});
				long long stp=vertex;
				vertex=-1;
				dist=1e18;
				dfs_down(stp);
				fill();
				dfs_up(stp);
			}
		}
	}
	cp=-1;
	tp=1;
	dfs_down(0);
	fill();
	dfs_up(0);
	// cout<<"adj\n";
	// for(int i=0;i<n;i++)
	// {
	// 	cout<<"For "<<i<<' ';
	// 	for(auto [j,p]:ma[i]){
	// 		cout<<p<<' ';
	// 	}
	// 	cout<<endl;
	// 	cout<<"a\n";
	// }
	return cp;
}

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:88:14: warning: unused variable 'bd' [-Wunused-variable]
   88 |    long long bd=dist;
      |              ^~
/usr/bin/ld: /tmp/ccteHgzX.o: in function `main':
grader.c:(.text.startup+0xd1): undefined reference to `travelTime'
collect2: error: ld returned 1 exit status