QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#357425#3047. Wind of ChangeHarry27182Compile Error//C++143.1kb2024-03-18 21:10:572024-03-18 21:10:57

Judging History

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

  • [2024-03-18 21:10:57]
  • 评测
  • [2024-03-18 21:10:57]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,u,v,w,ans[250005],dis[105][250005];vector<int>now;
struct Tree
{
	struct edge{int v,w,nxt;}e[500005];
	int cnt,h[250005],siz[250005],mx[250005],rt,S,p[250005];
	int dep[250005],f[250005][20],vis[250005];vector<int>g[250005];
	void add(int u,int v,int w){e[++cnt]={v,w,h[u]};h[u]=cnt;}
	void find(int u,int fa)
	{
		siz[u]=1;mx[u]=0;
		for(int i=h[u];i;i=e[i].nxt)
		{
			int v=e[i].v;
			if(v==fa||vis[v])continue;
			find(v,u);siz[u]+=siz[v];mx[u]=max(mx[u],siz[v]);
		}
		mx[u]=max(mx[u],S-siz[u]);
		if(mx[u]<mx[rt])rt=u;
	}
	int get(int u,int fa)
	{
		int res=1;
		for(int i=h[u];i;i=e[i].nxt)
		{
			int v=e[i].v;
			if(v==fa||vis[v])continue;
			res+=get(v,u);
		}
		return res;
	}
	void solve(int u)
	{
		vis[u]=1;
		for(int i=h[u];i;i=e[i].nxt)
		{
			int v=e[i].v;
			if(vis[v])continue;
			mx[rt=0]=0x3f3f3f3f;S=get(v,u);find(v,u);
			p[rt]=u;g[u].emplace_back(rt);solve(rt);
		}
	}
	void main()
	{
		mx[rt=0]=0x3f3f3f3f;S=n;find(1,0);solve(rt);
	}
	void dfs(int u)
	{
		now.emplace_back(u);
		for(int i=0;i<g[u].size();i++)dfs(g[u][i]);
	}
	void init(int u,int fa)
	{
		f[u][0]=fa;
		for(int i=1;(1<<i)<=n;i++)f[u][i]=f[f[u][i-1]][i-1];
		for(int i=h[u];i;i=e[i].nxt)
		{
			int v=e[i].v;
			if(v==fa)continue;
			dep[v]=dep[u]+e[i].w;init(v,u);
		}
	}
	int lca(int u,int v)
	{
		if(dep[u]<dep[v])swap(u,v);
		for(int i=18;i>=0;i--)if(dep[f[u][i]]>=dep[v])u=f[u][i];
		if(u==v)return u;
		for(int i=18;i>=0;i--)if(f[u][i]!=f[v][i])u=f[u][i],v=f[v][i];
		return f[u][0];
	}
	int dis(int u,int v){return dep[u]+dep[v]-2*dep[lca(u,v)];}
}T1,T2;
struct node{int w,x;}mn[250005][2];
bool operator ==(node x,node y){return x.w==y.w&&x.x==y.x;}
bool operator <(node x,node y){return x.w<y.w;}
signed main()
{
	cin.tie(0)->sync_with_stdio(0);
	cin>>n;
	for(int i=1;i<n;i++)
	{
		cin>>u>>v>>w;
		T1.add(u,v,w);T1.add(v,u,w);
	}
	for(int i=1;i<n;i++)
	{
		cin>>u>>v>>w;
		T2.add(u,v,w);T2.add(v,u,w);
	}
	T1.init(1,0);T2.init(1,0); 
	T1.main();T2.main();
	for(int i=1;i<=n;i++)mn[i][0]=mn[i][1]={0x3f3f3f3f3f3f3f3f,0},ans[i]=0x3f3f3f3f3f3f3f3f;
	for(int u=1;u<=n;u++)
	{
		for(int x=u,o=0;x;x=T2.p[x],o++)dis[o][u]=T2.dis(u,x);
	}
	for(int i=1;i<=n;i++)
	{
		now.clear();now.shrink_to_fit();
		T1.dfs(i);
		for(int j=0;j<now.size();j++)
		{
			int x=now[j],d1=T1.dis(x,i);
			for(int k=x,o=0;k;k=T2.p[k],o++)
			{
				node now={d1+dis[o][x],x};
				if(now<mn[k][0])mn[k][1]=mn[k][0],mn[k][0]=now;
				else if(now<mn[k][1])mn[k][1]=now;
			}
		}
		for(int j=0;j<now.size();j++)
		{
			int x=now[j],d1=T1.dis(x,i);
			for(int k=x,o=0;k;k=T2.p[k],o++)
			{
				node now={d1+dis[o][x],x};
				if(mn[k][0]==now)ans[x]=min(ans[x],mn[k][1].w+now.w),ans[mn[k][1].second]=min(ans[mn[k][1].second],mn[k][1].w+now.w);
				else ans[x]=min(ans[x],mn[k][0].w+now.w),ans[mn[k][0].second]=min(ans[mn[k][0].second],mn[k][0].w+now.w);
			}
		}
		for(int j=0;j<now.size();j++)
		{
			int x=now[j];
			for(int k=x;k;k=T2.p[k])mn[k][0]=mn[k][1]={0x3f3f3f3f3f3f3f3f,0};
		}
	}
	for(int i=1;i<=n;i++)cout<<ans[i]<<'\n';
	return 0;
}

Details

answer.code: In function ‘int main()’:
answer.code:119:99: error: ‘struct node’ has no member named ‘second’
  119 |                                 if(mn[k][0]==now)ans[x]=min(ans[x],mn[k][1].w+now.w),ans[mn[k][1].second]=min(ans[mn[k][1].second],mn[k][1].w+now.w);
      |                                                                                                   ^~~~~~
answer.code:119:124: error: ‘struct node’ has no member named ‘second’
  119 |                                 if(mn[k][0]==now)ans[x]=min(ans[x],mn[k][1].w+now.w),ans[mn[k][1].second]=min(ans[mn[k][1].second],mn[k][1].w+now.w);
      |                                                                                                                            ^~~~~~
answer.code:120:87: error: ‘struct node’ has no member named ‘second’
  120 |                                 else ans[x]=min(ans[x],mn[k][0].w+now.w),ans[mn[k][0].second]=min(ans[mn[k][0].second],mn[k][0].w+now.w);
      |                                                                                       ^~~~~~
answer.code:120:112: error: ‘struct node’ has no member named ‘second’
  120 |                                 else ans[x]=min(ans[x],mn[k][0].w+now.w),ans[mn[k][0].second]=min(ans[mn[k][0].second],mn[k][0].w+now.w);
      |                                                                                                                ^~~~~~