답안 #897392

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
897392 2024-01-03T03:26:17 Z Faisal_Saqib 꿈 (IOI13_dreaming) C++17
컴파일 오류
0 ms 0 KB
#pragma once
#include <iostream>
#include <vector>
using namespace std; 
const int N=1e5+200;
vector<pair<int,int>> ma[N];
bool vis[N];
int dp_down[N][2];
int dp_up[N];
int mxx[N];
int n,m,l;
void dfs_down(int x,int 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);
			int 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;
			}
		}
	}
}
int vertex=-1;
int dist=2e9;
int cp=-1;
void dfs_up(int x,int p=-1)
{
	mxx[x]=max(dp_up[x],dp_down[x][0]);
	cp=max(cp,mxx[x]);
	if(mxx[x]<dist)
	{
		dist=mxx[x];
		vertex=x;
	}
	for(auto [w,y]:ma[x])
	{
		if(y!=p)
		{
			dp_up[y]=max(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]){
			int bv=vertex;
			int bd=dist;
			vertex=-1;
			dist=2e9;
			dfs_down(i);
			dfs_up(i);
			if(bv!=-1)
			{
				ma[bv].push_back({l,vertex});
				ma[vertex].push_back({l,bv});
				if(dist<=bd)
				{
					vertex=bv;
					dist=bd;
				}
			}
		}
	}
	cp=-1;
	dfs_down(0);
	dfs_up(0);
	return cp;
}

Compilation message

dreaming.cpp:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
/usr/bin/ld: /tmp/ccimNR5C.o: in function `main':
grader.c:(.text.startup+0xd1): undefined reference to `travelTime'
collect2: error: ld returned 1 exit status