QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#104607#3041. Dead Cacti Societygrass8wocWA 7ms13252kbC++143.2kb2023-05-11 12:06:002023-05-11 12:06:03

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-11 12:06:03]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:13252kb
  • [2023-05-11 12:06:00]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll I=1e17;
int n,m,fa[201000],dfn[201000],low[200100],sta[200100],top;
ll rv[201000];
ll p1[210000],p2[200100],p1_[201000],p2_[201000];
struct ed{int v;ll w1,w2;};
vector<ed>g[200100],g2[200100];
int N;
void dfs(int x){
	dfn[x]=low[x]=++dfn[0],sta[++top]=x;
	for(ed t:g[x])if(t.v!=x){
		int v=t.v;
		if(!dfn[v]){
			fa[v]=x,p1[v]=t.w1,p2[v]=t.w2,dfs(v),low[x]=min(low[x],low[v]);
			if(low[v]==dfn[x]){
				if(sta[top]==v)g2[x].push_back(t),top--;
				else{
					N++;g2[x].push_back((ed){N,p1_[sta[top]],p2_[sta[top]]});
					while(sta[top]!=v)g2[N].push_back((ed){sta[top],p1[sta[top]],p2[sta[top]]}),top--;
					g2[N].push_back((ed){sta[top],p1[sta[top]],p2[sta[top]]}),top--;
				}
			}
		}
		else{
			low[x]=min(low[x],dfn[v]);
			if(fa[x]!=v)p1_[x]=t.w1,p2_[x]=t.w2;
		}
	}
}
bool oh;
ll qz[200100],qz2[200100],qz3[201000];
bool qz4[200100];
ll hz[200100],hz2[201000],hz3[200100];
bool hz4[200100];
int id[200100];
ll d[201000];
ll D;
void dfs2(int x){
	if(!oh)return;
	d[x]=0;
	for(ed t:g[x])if(t.v==x){
		ll o=t.w2+rv[x];
		if(o*2<=D)d[x]=max(d[x],o);
		else{oh=0;return;}
	}
	for(ed t:g2[x]){
		if(!oh)return;
		int v=t.v;
		if(v<=n){
			dfs2(v);
			if(d[x]+d[v]+t.w1>D){oh=0;return;}
			d[x]=max(d[x],d[v]+t.w1);
		}
		else{
			for(ed t2:g2[v])dfs2(t2.v);
			if(!oh)return;
			int sz=g2[v].size();
			for(int i=0;i<sz;i++)id[i]=g2[v][i].v,p1[i]=g2[v][i].w1,p2[i]=g2[v][i].w2;
			qz[0]=0,qz2[0]=qz3[0]=d[id[0]],qz4[0]=(d[id[0]]<=D);
			for(int i=1;i<sz;i++){
				qz[i]=qz[i-1]+p1[i-1];ll z=d[id[i]];
				qz2[i]=max(qz2[i-1],qz[i]+z);
				qz3[i]=max(qz3[i-1]+p1[i-1],z);
				qz4[i]=qz4[i-1];
				if(d[id[i]]+qz3[i-1]+p1[i-1]>D)qz4[i]=0;
			}
			hz[sz-1]=0,hz2[sz-1]=hz3[sz-1]=d[id[sz-1]];
			hz4[sz-1]=(d[id[sz-1]]<=D);
			for(int i=sz-2;i>=0;i--){
				ll z=d[id[i]];
				hz[i]=hz[i+1]+p1[i];
				hz2[i]=max(hz2[i+1],hz[i]+z);
				hz3[i]=max(hz3[i+1]+p1[i],z);
				hz4[i]=hz4[i+1];
				if(d[id[i]]+hz3[i+1]+p1[i]>D)hz4[i]=0;
			}
			ll OP=I+10,a1=t.w1,a2=p1[sz-1];
			for(int i=0;i+1<sz;i++)
				if(qz4[i]&&hz4[i+1]){
					ll o1=p2[i]+rv[id[i]],o2=p2[i]+rv[id[i+1]];
					if(o1+qz3[i]<=D&&o2+hz3[i+1]<=D){
						ll m1=max(qz2[i],o1+qz[i])+a1,m2=max(hz2[i+1],o2+hz[i+1])+a2;
						if(m1+m2<=D)OP=min(OP,max(m1,m2)); 
					}
				}
			if(qz4[sz-1]){
				ll o1=rv[id[sz-1]]+p2[sz-1],o2=rv[x]+p2[sz-1];
				if(o1+qz3[sz-1]<=D){
					ll m1=max(qz2[sz-1],o1+qz[sz-1])+a1,m2=o2;
					if(m1+m2<=D)OP=min(OP,max(m1,m2));
				}
			}
			if(hz4[0]){
				ll o1=rv[id[0]]+t.w2,o2=rv[x]+t.w2;
				if(o1+hz3[0]<=D){
					ll m1=max(hz2[0],o1+hz[0])+a2,m2=o2;
					if(m1+m2<=D)OP=min(OP,max(m1,m2));
				}
			}
			if(d[x]+OP>D)oh=0;
			else d[x]=max(d[x],OP);
		}
	}
}
bool chk(){
	oh=1,dfs2(1);
	return oh;
} 
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)scanf("%lld",&rv[i]);
	for(int i=1,u,v;i<=m;i++){
		ll w1,w2;scanf("%d%d%lld%lld",&u,&v,&w1,&w2);
		g[u].push_back((ed){v,w1,w2});
		g[v].push_back((ed){u,w1,w2});
	}
	N=n,dfs(1);
	ll l=0,r=I,ans=0;
	while(l<=r){
		D=(l+r)>>1;
		if(chk())ans=D,r=D-1;
		else l=D+1;
	}
	printf("%lld",ans);
	return 0;
}

詳細信息

Test #1:

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

input:

3 3
1 2 3
3 1 2 3
1 2 1 2
2 3 3 1

output:

10

result:

ok answer is '10'

Test #2:

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

input:

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

output:

22

result:

ok answer is '22'

Test #3:

score: 0
Accepted
time: 2ms
memory: 13208kb

input:

10 11
648052322 565910647 660564399 692596305 919489008 212738520 617650098 677929920 808272788 791544831
10 8 425278193 551233171
4 10 947118708 675103129
6 3 843388555 979992603
2 7 89886505 298201903
6 9 596198105 80916490
1 6 607631290 761815117
1 5 727447345 664950926
4 1 416196154 17044633
2 4...

output:

4595167732

result:

ok answer is '4595167732'

Test #4:

score: 0
Accepted
time: 4ms
memory: 13092kb

input:

20 22
586027983 17626209 143089294 541063189 497266584 815531025 654472332 628305267 18777925 293631001 470245328 474349257 573662223 270526587 592273876 185008021 1753288 948699612 550397057 97390149
14 4 611644452 347910227
18 11 123114412 83716498
17 1 146068364 531802823
17 15 636910057 98773334...

output:

3974997198

result:

ok answer is '3974997198'

Test #5:

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

input:

20 22
83084779 123479070 425691499 255394401 125997543 920540786 201955937 945957738 254445790 568943703 500445883 327469615 874058013 644798455 477406417 521195348 468735946 923014331 675264083 113306608
9 18 35113807 965823918
19 7 579456290 232691941
10 1 917347936 658306553
8 2 58554231 26540606...

output:

6805282780

result:

ok answer is '6805282780'

Test #6:

score: 0
Accepted
time: 2ms
memory: 13224kb

input:

30 36
247525284 97674171 26852067 487010457 727929235 636987006 760946911 203385779 977415036 698821707 654961883 595288085 922370605 822983963 918997277 395083501 613607654 891617614 42445125 949747778 705274768 793806862 287472495 56044216 487997282 212507107 636523584 361944482 96922580 114436867...

output:

5644748866

result:

ok answer is '5644748866'

Test #7:

score: 0
Accepted
time: 4ms
memory: 12976kb

input:

40 48
750854831 471076290 587955727 498095394 786098053 825167545 179457243 829214029 797076810 710708422 293783554 777448279 902548779 327282136 18961111 34892803 900322755 272536057 207671630 790893788 937146089 367828234 297451611 597092025 401816497 123546714 370985631 442309657 241530494 670889...

output:

7521819716

result:

ok answer is '7521819716'

Test #8:

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

input:

60 70
504908017 500966899 405923079 361072564 767784887 946807327 588131654 949996368 795680905 150901980 363765972 24071027 945511686 168188504 956076858 942308497 24820353 470313508 719738974 762887852 549969912 579755773 62063921 828996712 826911990 784586331 853936727 423204438 847895099 8352365...

output:

7671558503

result:

ok answer is '7671558503'

Test #9:

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

input:

100 116
709859759 353642926 643199303 853426969 479322816 444064693 352827637 664302815 313185142 186975627 722681439 250133519 718839115 417346925 828935934 733633457 522385113 477229174 263560950 491959746 943503975 665316099 106727481 85978050 24016214 676654179 639296754 907064206 984998429 5216...

output:

11980434803

result:

ok answer is '11980434803'

Test #10:

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

input:

120 145
2635622 630993960 536599776 875593862 288845548 402004552 422513936 706800694 632768700 305689110 793642514 959905494 609112156 356608637 997538411 419315814 440152871 504921772 394090004 690342165 377990323 437858253 808979334 688991180 543459694 866127727 195798129 33544112 41860213 405404...

output:

11602034888

result:

ok answer is '11602034888'

Test #11:

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

input:

200 230
455093388 862046443 844762059 237644815 247538374 787691789 483060374 864522919 361021277 373237865 213009352 597144750 571871835 125250895 479447977 765061959 360456436 862028881 478399532 744407821 135724934 377878100 810345448 270534292 492035382 922708327 219160562 7269065 92191573 77190...

output:

15227135836

result:

ok answer is '15227135836'

Test #12:

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

input:

300 355
205420793 14744060 153612302 790864976 539525202 567920940 232313247 282480949 46721177 446884846 268187580 17778034 588738571 485418318 17954743 306433388 734520184 652664326 741319611 255027117 71697306 780396224 98702154 103883036 299072426 975624476 688996738 124531878 887608592 19881554...

output:

28288584556

result:

ok answer is '28288584556'

Test #13:

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

input:

300 354
870833340 36218712 871509192 756192538 540093068 710013783 305554332 445850736 219178563 866769559 258150937 826956186 605285341 371673829 853577218 868463162 390910062 917592208 185072037 471834701 364632288 92416713 335001291 464762239 388946090 736766302 675835340 882004733 109686463 9855...

output:

18067009894

result:

ok answer is '18067009894'

Test #14:

score: -100
Wrong Answer
time: 2ms
memory: 13108kb

input:

500 598
318238298 454564113 229456830 874542201 323702502 589826453 138046120 700423252 669327704 149936936 996296056 714750884 835565359 747379851 936076600 685303899 339777339 313384416 551281216 212209487 591447705 830900949 959826169 478300030 273570556 201014741 362118355 780969224 680079836 40...

output:

28671290532

result:

wrong answer expected '28910648446', found '28671290532'