QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#292687#7419. Jiry MatchingsClonothWA 8ms41892kbC++203.5kb2023-12-28 11:11:092023-12-28 11:11:10

Judging History

This is the latest submission verdict.

  • [2024-06-05 15:26:21]
  • hack成功,自动添加数据
  • (/hack/645)
  • [2023-12-28 11:11:10]
  • Judged
  • Verdict: WA
  • Time: 8ms
  • Memory: 41892kb
  • [2023-12-28 11:11:09]
  • Submitted

answer

#include<stdio.h>
#include<bits/stdc++.h>
#define fir first
#define sec second
#define all(x) begin(x),end(x)
using namespace std;
typedef long long ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef __int128 int128;
typedef __uint128_t uint128;
typedef pair<int,int> pii;
template<typename type>
inline void chmin(type &x,const type &y)
{
	if(y<x)
		x=y;
}
template<typename type>
inline void chmax(type &x,const type &y)
{
	if(x<y)
		x=y;
}
constexpr int Max=2e5+10;
constexpr ll inf=1e18;
vector<int>merge(vector<int>a,vector<int>b)
{
	vector<int>c(a.size()+b.size());
	merge(all(a),all(b),c.begin(),greater<int>());
	return c;
}
vector<int>check(vector<int>a,vector<int>b)
{
	if(a.size()<b.size())
		a.swap(b);
	partial_sum(all(a),a.begin()),partial_sum(all(b),b.begin());
	for(int i=0;i<(int)b.size();++i)
		chmax(a[i],b[i]);
	adjacent_difference(all(a),a.begin());
	return a;
}
vector<pii>e[Max];
int fa[Max],depth[Max],n;
int son[Max],siz[Max],rk[Max],top[Max],order;
int num[Max];
void init(int u,int from)
{
	if(from)
		for(auto it=e[u].begin();it!=e[u].end();++it)
			if(it->fir==from)
			{
				e[u].erase(it);
				break;
			}
	depth[u]=depth[from]+1,fa[u]=from,siz[u]=1;
	for(auto [v,w]:e[u])
	{
		num[v]=w;
		init(v,u);
		siz[u]+=siz[v];
		if(siz[v]>siz[son[u]])
			son[u]=v;
	}
}
vector<int>f[Max][2];
vector<int>g[Max][2][2];//down -> up
void solve(int l,int r)
{
	if(l==r)
		return;
	int mid=(l+r)>>1;
	solve(l,mid),solve(mid+1,r);
	vector<int>ans[2][2];
	for(auto y1:{0,1})
		for(auto x2:{0,1})
		{
			if(y1&&x2)
				continue;
			for(auto x1:{0,1})
				for(auto y2:{0,1})
					ans[y2][x1]=check(ans[y2][x1],merge(g[l][y1][x1],g[mid+1][y2][x2]));
		}
	for(auto x:{0,1})
		for(auto y:{0,1})
			g[l][x][y]=ans[x][y];
}
void dfs(int u,int t)
{
	top[u]=t;
	rk[u]=++order;
	if(son[u])
		dfs(son[u],t);
	for(auto [v,w]:e[u])
		if(v!=son[u])
			dfs(v,v);
	priority_queue<pii,vector<pii>,greater<pii>>q;
	q.emplace(0,u);
	for(auto [v,w]:e[u])
		if(v!=son[u])
			q.emplace((int)(f[v][0].size()+f[v][1].size()),v);
	while(q.size()>1)
	{
		auto [s1,x]=q.top();
		q.pop();
		auto [s2,y]=q.top();
		q.pop();
		f[x][1]=check(merge(f[x][0],f[y][1]),merge(f[x][1],f[y][0]));
		f[x][0]=merge(f[x][0],f[y][0]);
		q.emplace((int)(f[x][0].size()+f[x][1].size()),x);
	}
	swap(f[u],f[q.top().sec]);
	g[rk[u]][0][0]=f[u][0];
	g[rk[u]][1][0]=f[u][1];
	if(fa[u])
		g[rk[u]][1][1]=merge(f[u][0],{num[u]});
//	cerr<<"\n";
//	cerr<<"f "<<u<<" 0 : ";
//	for(auto i:f[u][0])
//		cerr<<i<<" ";
//	cerr<<"\n";
//	cerr<<"f "<<u<<" 1 : ";
//	for(auto i:f[u][1])
//		cerr<<i<<" ";
//	cerr<<"\n";
	if(fa[u]&&top[u]==u)
	{
		int v=u;
		while(son[v])
			v=son[v];
		solve(rk[u],rk[v]);
		f[u][0]=check(g[rk[u]][0][0],g[rk[u]][1][0]);
		f[u][1]=check(g[rk[u]][0][1],g[rk[u]][1][1]);
	}
//	cerr<<"\n";
//	cerr<<"f "<<u<<" 0 : ";
//	for(auto i:f[u][0])
//		cerr<<i<<" ";
//	cerr<<"\n";
//	cerr<<"f "<<u<<" 1 : ";
//	for(auto i:f[u][1])
//		cerr<<i<<" ";
//	cerr<<"\n";
}
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr),cout.tie(nullptr);
	cin>>n;
	for(int i=1,u,v,w;i<n;++i)
		cin>>u>>v>>w,e[u].emplace_back(v,w),e[v].emplace_back(u,w);
	init(1,0);
	son[1]=0;
	dfs(1,1);
	vector<int>ans=check(f[1][0],f[1][1]);
	partial_sum(all(ans),ans.begin());
	for(int i=0;i<n-1;++i)
	{
		if(i>=(int)ans.size())
			cout<<"? ";
		else
			cout<<ans[i]<<" ";
	}
	cout<<"\n";
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 41892kb

input:

5
1 2 3
2 3 5
2 4 4
3 5 2

output:

5 6 ? ? 

result:

ok single line: '5 6 ? ? '

Test #2:

score: 0
Accepted
time: 0ms
memory: 41888kb

input:

10
2 8 -5
5 10 5
3 4 -5
1 6 5
3 9 5
1 7 -3
4 8 -5
10 8 -5
1 8 -3

output:

5 10 15 10 ? ? ? ? ? 

result:

ok single line: '5 10 15 10 ? ? ? ? ? '

Test #3:

score: 0
Accepted
time: 8ms
memory: 41772kb

input:

2
1 2 35

output:

35 

result:

ok single line: '35 '

Test #4:

score: -100
Wrong Answer
time: 4ms
memory: 41788kb

input:

100
75 98 770328247
87 98 -219729992
98 35 578758971
98 93 -348642106
63 98 -638036803
83 25 -744163505
21 98 810313834
97 25 131957988
19 98 -711567435
8 25 68874404
43 98 184473508
28 94 171940607
92 28 971759198
51 98 -674532123
28 6 797727320
98 95 1154600
98 58 683765502
28 12 358426364
4 42 65...

output:

990461444 1951945471 -1388620893 2024628585 189727407 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 

result:

wrong answer 1st lines differ - expected: '990461444 1951945471 290634640...? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?', found: '990461444 1951945471 -13886208... ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? '