QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#486497#6629. Travelling TraderRafi22#0 2ms16136kbC++202.8kb2024-07-21 20:42:362024-07-21 20:42:36

Judging History

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

  • [2024-07-21 20:42:36]
  • 评测
  • 测评结果:0
  • 用时:2ms
  • 内存:16136kb
  • [2024-07-21 20:42:36]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#ifdef DEBUG
auto&operator<<(auto&o,pair<auto,auto>p){return o<<"("<<p.first<<", "<<p.second<<")";}
auto operator<<(auto&o,auto x)->decltype(x.end(),o){o<<"{";int i=0;for(auto e:x)o<<","+!i++<<e;return o<<"}";}
#define debug(X...)cerr<<"["#X"]: ",[](auto...$){((cerr<<$<<"; "),...)<<endl;}(X)
#else
#define debug(...){}
#endif

#define ll long long
#define ld long double
#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define FOR(i,l,r) for(int i=(l);i<=(r);i++)
#define ROF(i,r,l) for(int i=(r);i>=(l);i--)
int inf=1000000007;
ll infl=1000000000000000007;
ll mod=1000000007;
ll mod1=998244353;

const int N=200007;

ll p[N];
vector<int>G[N];
int n;

ll DP0[N],DP1[N],DP2[N];
int zkad0a[N],zkad0b[N];
int zkad1[N];
int zkad2[N];
int O[N];

void dfs(int v,int o)
{
	O[v]=o;
	vector<int>X;
	for(auto u:G[v])
	{
		if(u==o) continue;
		dfs(u,v);
		X.pb(u);
	}
	//policzmy DP0
	DP0[v]=p[v];
	vector<pair<ll,int>>V;
	for(auto u:X) 
	{
		DP0[v]+=p[u];
		V.pb({DP1[u]-p[u],u});
	}
	sort(all(V),greater<pair<ll,int>>());
	ll mx=0;
	for(auto u:X) 
	{
		if(V[0].nd!=u)
		{
			if(DP0[u]-p[u]+V[0].st>=mx)
			{
				mx=DP0[u]-p[u]+V[0].st;
				zkad0a[v]=V[0].nd;
				zkad0b[v]=u;
			}
		}
		else if(sz(V)>1)
		{
			if(DP0[u]-p[u]+V[1].st>=mx)
			{
				mx=DP0[u]-p[u]+V[1].st;
				zkad0a[v]=V[1].nd;
				zkad0b[v]=u;
			}
		}
		else
		{
			if(DP0[u]-p[u]>=mx)
			{
				mx=DP0[u]-p[u];
				zkad0a[v]=0;
				zkad0b[v]=u;
			}
		}
	}
	DP0[v]+=mx;
	//policzmy DP1
	DP1[v]=p[v];
	for(auto u:X) DP1[v]+=p[u];
	for(auto u:X)
	{
		if(DP2[u]+p[v]>DP1[v])
		{
			DP1[v]=DP2[u]+p[v];
			zkad1[v]=u;
		}
	}
	//policzmy DP2
	mx=0;
	DP2[v]=p[v];
	for(auto u:X)
	{
		DP2[v]+=p[u];
		if(DP1[u]-p[u]>=mx)
		{
			mx=DP1[u]-p[u];
			zkad2[v]=u;
		}
	}
	DP2[v]+=mx;
}
vector<int>ans;

void calc1(int v);

void calc0(int v)
{
	ans.pb(v);
	if(zkad0a[v]) calc1(zkad0a[v]);
	for(auto u:G[v]) if(u!=O[v]&&u!=zkad0a[v]&&u!=zkad0b[v]) ans.pb(u);
	if(zkad0b[v]) calc0(zkad0b[v]);
}
void calc1(int v)
{
	if(zkad1[v]) calc1(zkad1[v]);
	else for(auto u:G[v]) if(u!=O[v]) ans.pb(u);
	ans.pb(v);
}
void calc2(int v)
{
	ans.pb(v);
	if(zkad2[v]) calc1(zkad2[v]);
	for(auto u:G[v]) if(u!=O[v]&&u!=zkad2[v]) ans.pb(u);
}

void k2()
{
	dfs(1,0);
	calc0(1);
	cout<<DP0[1]<<endl<<sz(ans)<<endl;
	for(auto x:ans) cout<<x<<" ";
	cout<<endl;
}

signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int k;
	cin>>n>>k;
	FOR(i,1,n-1)
	{
		int a,b;
		cin>>a>>b;
		G[a].pb(b);
		G[b].pb(a);
	}
	FOR(i,1,n) cin>>p[i];
	if(k==2) k2();
	
	
	return 0;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 7748kb

input:

2 1
1 2
255959470 961356354

output:


result:

wrong output format Unexpected end of file - int64 expected

Subtask #2:

score: 0
Wrong Answer

Test #12:

score: 7
Accepted
time: 0ms
memory: 16136kb

input:

2 2
2 1
243296356 635616793

output:

878913149
2
1 2 

result:

ok correct!

Test #13:

score: -7
Wrong Answer
time: 0ms
memory: 13892kb

input:

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

output:

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

result:

wrong answer dist(4, 7) = 5 > k = 2

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Wrong Answer

Test #83:

score: 0
Wrong Answer
time: 2ms
memory: 7756kb

input:

2000 3
1359 90
1703 163
158 188
360 1501
195 664
1414 215
1546 1756
536 1096
1726 1223
1150 104
1757 703
1982 282
1023 998
1180 419
576 1759
1496 1993
44 670
1703 952
855 849
1998 1399
1280 980
1533 1090
1270 678
1680 387
469 1734
1799 263
473 588
303 226
5 295
1489 1471
1094 1667
1912 210
1368 1360...

output:


result:

wrong output format Unexpected end of file - int64 expected

Subtask #6:

score: 0
Skipped

Dependency #5:

0%