QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#454731#2002. RaceIshar-zdlCompile Error//C++171.6kb2024-06-25 11:55:322024-06-25 11:55:32

Judging History

你现在查看的是最新测评结果

  • [2024-06-25 11:55:32]
  • 评测
  • [2024-06-25 11:55:32]
  • 提交

answer

#include<bits/stdc++.h>
//#define int long long
using namespace std;
const int N=1e6+10;
int n,k,rt,tot,t,ans=197255101;
int head[N],nxt[N],to[N],val[N];
int siz[N],dis[N],dep[N],l[N],r[N];
bool vis[N];
map<int,int>mp;
inline void add(int u,int v,int w)
{
	nxt[++tot]=head[u];
	head[u]=tot;
	to[tot]=v;
	val[tot]=w;
	return ;
}
inline void fr(int x,int fa,int cnt)
{
	siz[x]=1;
	int mx=0;
	for(int i=head[x],y;i;i=nxt[i])
		if(!vis[y=to[i]]&&y!=fa)
		{
			fr(y,x,cnt);
			siz[x]+=siz[y];
			mx=max(mx,siz[y]);
		}
	mx=max(mx,cnt-siz[x]);
	if(mx<=cnt/2)
		rt=x;
	return ;
}
inline void calc(int x,int fa)
{
	dep[++t]=x;
	l[x]=l[fa]+1;
	for(int i=head[x],y;i;i=nxt[i])
		if(!vis[y=to[i]]&&y!=fa)
		{
			dis[y]=dis[x]+val[i];
			calc(y,x);
		}
	return ;
}
inline void solve(int x,int fa)
{
	vis[x]=mp[0]=1;
	r[0]=l[x]=0;
	for(int i=head[x],y;i;i=nxt[i])
		if(!vis[y=to[i]]&&y!=fa)
		{
			dis[y]=val[i];
			calc(y,x);
			for(int j=1;j<=t;j++)
				if(mp.count(k-dis[dep[j]]))
					ans=min(ans,l[dep[j]]+r[k-dis[dep[j]]]);
			for(int j=1;j<=t;j++)
			{
				mp[dis[dep[j]]]=1;
				r[dis[dep[j]]]=l[dep[j]];
			}
			t=0;
		}
	mp.clear();
	for(int i=head[x],y;i;i=nxt[i])
		if(!vis[y=to[i]]&&y!=fa)
		{
			fr(y,x,siz[y]);
			fr(rt,0,siz[y]);
			solve(y,x);
		}
	return ;
}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin>>n>>k;
	for(int i=1,u,v,w;i<=n-1;i++)
	{
		cin>>u>>v>>w;
		u++; v++;
		add(u,v,w);
		add(v,u,w);
	}
	fr(1,0,n);
	fr(rt,0,n);
	solve(rt,0);
	cout<<(ans==197255101?-1:ans);
	return 0;
}

詳細信息

/usr/bin/ld: /tmp/ccs4eTv8.o: in function `main':
answer.code:(.text.startup+0x0): multiple definition of `main'; /tmp/ccwe71T7.o:implementer.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccwe71T7.o: in function `main':
implementer.cpp:(.text.startup+0x25): undefined reference to `best_path(int, int, int (*) [2], int*)'
collect2: error: ld returned 1 exit status