CSP-ST4 90分 WA on #14 #19
  • 板块学术版
  • 楼主Rain_chr
  • 当前回复1
  • 已保存回复1
  • 发布时间2023/10/24 21:37
  • 上次更新2023/11/2 11:31:41
查看原帖
CSP-ST4 90分 WA on #14 #19
684254
Rain_chr楼主2023/10/24 21:37

求告知错误原因或hack

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+10;
int a[N],b[N],c[N];
int t[N],h[N];
bool book[N];
vector<int> g[N];
int n;
void dfs(int x,int fa)
{
	book[x]=0;
	h[x]=t[x];
	for(int to:g[x])
	{
		if(to==fa) continue;
		dfs(to,x);
		h[x]=min(h[x],h[to]-1);
	}
}
priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > q;
bool check(int mid)
{
	for(int i=1;i<=n;i++)
	{
		int l=1,r=mid;
		t[i]=-1;
		while(l<=r)
		{
			int k=(l+r)>>1;
			int y=c[i]>=0?mid:(floorl(1.0*(1-b[i])/c[i]));
			__int128 tmp=c[i];
			tmp*=(k+y)*(y-k+1)/2;
			tmp+=b[i]*(y-k+1);
			tmp+=mid-y; 
			if(tmp>=a[i])
			{
				t[i]=k;
				l=k+1;
			}
			else
				r=k-1;
		}
		if(t[i]==-1)
			return 0;
	}
	dfs(1,0); 
	while(q.size()) q.pop();
	q.push(make_pair(h[1],1));
	int cnt=1;
	while(q.size())
	{
		int x=q.top().second;
		q.pop();
		book[x]=1;
		if(t[x]<cnt)
			return 0;
		cnt++;
		for(int i:g[x])
		{
			if(book[i]) continue;
			q.push(make_pair(h[i],i));
		}
	}
	return 1;
}
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i]>>b[i]>>c[i];
	for(int i=1;i<n;i++)
	{
		int x,y;
		cin>>x>>y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	int l=1,r=1e9,ans;
	while(l<=r)
	{
		int mid=(l+r)>>1;
		if(check(mid))
		{
			r=mid-1;
			ans=mid;
		}
		else
			l=mid+1;
	}
	cout<<ans;
	return 0;
}
2023/10/24 21:37
加载中...