QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#404677#8138. Alice and Her Lost CatHzweiAC ✓99ms98668kbC++145.5kb2024-05-04 14:13:552024-05-04 14:13:56

Judging History

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

  • [2024-05-04 14:13:56]
  • 评测
  • 测评结果:AC
  • 用时:99ms
  • 内存:98668kb
  • [2024-05-04 14:13:55]
  • 提交

answer

//Crimson flames tied through my ears
//Rollin' high and mighty traps
//Pounced with fire on flaming roads
//Using ideas as my maps
//"We'll meet on edges, soon," said I
//Proud 'neath heated brow
//Ah, but I was so much older then
//I'm younger than that now.
//
//Half-cracked prejudice leaped forth
//"Rip down all hate," I screamed
//Lies that life is black and white
//Spoke from my skull, I dreamed
//Romantic facts of musketeers
//Foundationed deep, somehow
//Ah, but I was so much older then
//I'm younger than that now.
//
//Girls' faces formed the forward path
//From phony jealousy
//To memorizing politics
//Of ancient history
//Flung down by corpse evangelists
//Unthought of, thought, somehow
//Ah, but I was so much older then
//I'm younger than that now.
//A self-ordained professor's tongue
//Too serious to fool
//Spouted out that liberty
//Is just equality in school
//"Equality," I spoke the word
//As if a wedding vow
//Ah, but I was so much older then
//I'm younger than that now.
//
//In a soldier's stance, I aimed my hand
//At the mongrel dogs who teach
//Fearing not that I'd become my enemy
//In the instant that I preach
//My existence led by confusion boats
//Mutiny from stern to bow
//Ah, but I was so much older then
//I'm younger than that now.
//
//Yes, my guard stood hard when abstract threats
//Too noble to neglect
//Deceived me into thinking
//I had something to protect
//Good and bad, I define these terms
//Quite clear, no doubt, somehow
//Ah, but I was so much older then
//I'm younger than that now.

#pragma GCC optimize("O3,unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
using namespace __gnu_pbds;
/*=====================================================================*/
#define ll long long
#define int ll
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pdd pair<double,double>
#define ull unsigned long long
#define pb push_back
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define all(s) (s).begin(),(s).end()
#define repd(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define forr(i,a,b,c) for(int i=(int)(a);i<=(int)(b);i+=(int)(c))
#define forn(i,p,n) for(int i=(int)(p);i<=(int)(n);++i)
#define ford(i,p,n) for(int i=(int)(n);i>=(int)(p);--i)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();++i)
#define INF 0x3f3f3f3f
#define PI acos(-1)
#define modcg(x) if(x>=mod)x-=mod;
#define modcl(x) if(x<0)x+=mod;
#define lowbit(x) ((x)&(-(x)))
#define ckmax(x,y) x=max(x,y)
#define ckmin(x,y) x=min(x,y)
/*=====================================================================*/
mt19937 GeN(chrono::system_clock::now().time_since_epoch().count());
int Rand(int l,int r)
{
	uniform_int_distribution<>RAND1(l,r);
	return RAND1(GeN);
}
struct Fastmod
{
	int mod,b;
	typedef __int128 lll;
	void init(int m)
	{
		mod=m;
		b=((lll)1<<64)/mod;
	}
	int operator()(ull a)
	{
		int q=((lll)a*b)>>64,r=a-q*mod;
		modcg(r);
		return r;
	}
}MOD;
int mul(int a,int b)
{
	return MOD(a*b);
}
/*======================================================================*/
//think twice,code once
//think once,debug forever
const int MAXN=2020;
int dp[MAXN][MAXN][3],f[MAXN][3],g[MAXN][3];
int n;
int a[MAXN],t[MAXN];
vi v[MAXN];
int sz[MAXN];
void dfs(int now,int fa)
{
	forn(i,0,n)
	{
		dp[now][i][0]=dp[now][i][1]=dp[now][i][2]=1e18;
	}
	sz[now]=v[now].size()==1&&fa;
	if(sz[now]==1)
	{
		dp[now][0][0]=a[now];
		dp[now][0][1]=0;
		dp[now][1][0]=0;
		return;
	}
	dp[now][0][0]=a[now];dp[now][0][1]=0;
	for(int u:v[now])
	{
		if(u==fa)
		{
			continue;
		}
		dfs(u,now);
		forn(i,0,sz[now]+sz[u])
		{
			f[i][0]=f[i][1]=f[i][2]=1e18;
		}
		forn(i,0,sz[now])
		{
			forn(j,0,sz[u])
			{
				f[i+j][0]=min(f[i+j][0],dp[now][i][0]+min(dp[u][j][0],dp[u][j][1]));
				f[i+j][1]=min(f[i+j][1],dp[now][i][1]+dp[u][j][0]);
				f[i+j][2]=min(f[i+j][2],dp[now][i][2]+dp[u][j][0]);
				f[i+j][2]=min(f[i+j][2],dp[now][i][1]+dp[u][j][1]);
			}
		}
		sz[now]+=sz[u];
		forn(i,0,sz[now])
		{
			dp[now][i][0]=f[i][0];
			dp[now][i][1]=f[i][1];
			dp[now][i][2]=f[i][2];
		}
	}
	forn(i,0,sz[now])
	{
		dp[now][i][0]=min(dp[now][i][0],dp[now][i][1]);
		dp[now][i][1]=dp[now][i][2];
	}
}
void solve()
{
	cin>>n;
	forn(i,1,n)
	{
		cin>>a[i];
	}
	forn(i,1,n)
	{
		cin>>t[i];
		v[i].clear();
	} 
	forn(i,1,n-1)
	{
		int x,y;
		cin>>x>>y;
		v[x].pb(y);
		v[y].pb(x);
	}
	dfs(1,0);
//	forn(i,1,n)
//	{
//		forn(j,0,n)
//		{
//			if(dp[i][j][0]==1e18)
//			{
//				cout<<"x ";
//				continue; 
//			}
//			cout<<dp[i][j][0]<<" ";
//		}
//		cout<<endl;
//	}
//	cout<<endl;
//	forn(i,1,n)
//	{
//		forn(j,0,n)
//		{
//			if(dp[i][j][1]==1e18)
//			{
//				cout<<"x ";
//				continue; 
//			}
//			cout<<dp[i][j][1]<<" ";
//		}
//		cout<<endl;
//	}
//	cout<<endl;
//	cout<<sz[1]<<endl;
	int ans=1e18;
	forn(i,0,n)
	{
		ans=min(ans,min(dp[1][i][1],dp[1][i][0])+t[i]);
	}
	cout<<ans<<endl;
}
/*======================================================================*/
signed main()
{
    cin.tie(0);
    cout.tie(0);
	std::ios::sync_with_stdio(false);
//#define Hank2007
#ifdef Hank2007
	freopen("input.txt","r",stdin);
	freopen("output1.txt","w",stdout);
#endif
  	/*====================================================================*/
  	int TEST_CASE=1;
	cin>>TEST_CASE;
  	while(TEST_CASE--)
  	{
  		solve();
  	}
  	return 0;
}

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 5752kb

input:

2
8
4 2 5 2 4 2 3 2
5 5 6 7 8 9 10 13
1 2
2 3
1 4
1 5
4 6
3 7
5 8
8
4 2 3 3 2 4 4 3
4 6 8 8 9 9 14 17
1 2
2 3
3 4
3 5
4 6
3 7
3 8

output:

4
3

result:

ok 2 number(s): "4 3"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3708kb

input:

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

output:

0
0
2

result:

ok 3 number(s): "0 0 2"

Test #3:

score: 0
Accepted
time: 1ms
memory: 5800kb

input:

5
10
1 1 3 4 4 2 3 3 3 1
4 4 7 9 17 17 19 19 19 20
1 2
2 3
1 4
2 5
1 6
3 7
1 8
2 9
2 10
10
2 3 3 3 4 1 3 3 1 3
2 4 5 6 9 10 12 15 19 20
1 2
2 3
2 4
1 5
5 6
6 7
7 8
1 9
5 10
10
3 3 3 3 3 3 1 4 2 3
1 4 10 10 14 15 16 17 18 20
1 2
1 3
3 4
1 5
2 6
4 7
6 8
2 9
3 10
10
1 2 1 3 2 3 1 2 1 2
1 1 2 3 4 5 9 9 ...

output:

2
5
5
2
2

result:

ok 5 number(s): "2 5 5 2 2"

Test #4:

score: 0
Accepted
time: 1ms
memory: 5728kb

input:

5
20
3 5 1 1 3 4 7 8 3 7 1 1 7 1 3 3 5 1 5 7
1 14 25 27 30 34 39 42 45 48 50 50 55 61 63 69 74 87 89 100
1 2
1 3
3 4
1 5
2 6
6 7
6 8
1 9
7 10
5 11
7 12
7 13
12 14
12 15
1 16
5 17
4 18
9 19
2 20
20
3 8 2 4 7 6 1 1 2 2 7 5 1 1 2 6 4 5 7 1
2 10 24 25 26 28 28 37 47 47 52 64 79 80 84 86 90 93 96 100
1 2...

output:

10
9
17
11
9

result:

ok 5 number(s): "10 9 17 11 9"

Test #5:

score: 0
Accepted
time: 36ms
memory: 85936kb

input:

10
1400
9827328 3447883 6979832 2361516 3201742 9881490 185103 6613510 7140147 9824105 7999173 649272 9056196 6021519 9367368 8153964 9840232 5449142 8119900 4715774 987231 1057668 5380695 9747965 2253752 1322003 2341542 2845358 5610842 8241778 4692550 7564041 2602876 4842402 3872716 3869113 7268396...

output:

342781747
371288274
187920801
21955588
250360535
236318821
224802283
390524828
281444264
291421823

result:

ok 10 numbers

Test #6:

score: 0
Accepted
time: 28ms
memory: 92120kb

input:

10
453
5186175 1420962 8950921 3420584 8352122 1606964 3615305 1662335 7129112 3853538 6275884 9171435 3518623 3492528 7692505 896099 815548 2768295 8173599 7502498 2580478 8521940 1367535 3474343 5647192 5476807 9769184 4719283 7538595 7137045 9438506 1272015 1397402 2647766 1270571 1122883 2075228...

output:

206244715
341230840
244108106
365394739
358176901
115691440
169329823
18005551
319842026
69815045

result:

ok 10 numbers

Test #7:

score: 0
Accepted
time: 39ms
memory: 97844kb

input:

10
1505
6803198 9426809 954777 705060 3502503 3299671 7078275 6678392 7118077 4206683 8294418 7660830 1788411 930769 6017642 7380058 8049040 152984 8227298 321991 4173725 2309924 7387143 942545 2815224 3406202 7196826 6560441 9466349 6032311 4184462 4947221 3868216 6711306 8701195 4602061 623884 797...

output:

361208793
43741741
261474287
336596228
308022071
311882982
354011854
278470501
88889642
332327962

result:

ok 10 numbers

Test #8:

score: 0
Accepted
time: 98ms
memory: 98528kb

input:

10
2000
3006604 5311265 2859626 3609818 8193678 7844282 2223127 7294340 1308287 6762790 88400 7428240 18325 6641350 8972559 2660020 9868202 7449155 8047535 5532457 6643387 6091653 3134704 500907 6052842 9516604 8558965 1950203 3278845 9863131 9361606 5492957 9812317 7335192 339790 4364441 4093591 98...

output:

377336374
388737941
381821708
333910519
360165603
344789836
391740730
364782918
385405245
382161455

result:

ok 10 numbers

Test #9:

score: 0
Accepted
time: 98ms
memory: 98544kb

input:

10
2000
3115656 6928288 865473 5613675 5510922 2994662 3948601 4466366 66168 6718986 4150601 5672183 4765896 1103778 6410800 1017925 6384929 4715414 5432225 5553388 9495648 7684900 6889920 2778691 9811988 2975580 2779304 9377845 5152771 1823653 1998696 238912 9745699 9838775 8145154 1762297 1314593 ...

output:

330389721
372008389
369537673
368481583
364593955
355194354
347294289
366850614
363318922
379964359

result:

ok 10 numbers

Test #10:

score: 0
Accepted
time: 99ms
memory: 98628kb

input:

10
2000
3224709 2287136 8838552 7584764 6537222 8145042 5608539 7896568 5114994 6740719 4470978 7657949 3288059 5631742 3849042 9343062 9127064 5690730 2751378 5607087 2315141 9212611 645136 8765531 3505598 6369021 675932 6805487 768520 3751407 893963 4984868 3453673 8567765 2208694 5451097 8535594 ...

output:

406240490
396273822
373075313
373215271
366225425
372414756
349190757
388338626
357010416
385577925

result:

ok 10 numbers

Test #11:

score: 0
Accepted
time: 99ms
memory: 98668kb

input:

10
2000
3333761 3904159 3069807 5846797 3854466 3295422 1075837 1359538 131051 6729684 8533179 5934660 8068398 3835993 7578227 7668199 5611024 2924221 136067 5693554 5134633 805858 8109408 4785139 941032 3504285 4863504 4233129 2609678 5711928 9854766 3472648 7128879 1104115 14057 2848952 2047540 28...

output:

351661825
367417601
363942333
380444399
377825080
363473980
361578810
379150119
338648231
364417836

result:

ok 10 numbers

Extra Test:

score: 0
Extra Test Passed