QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#152627#6654. 大纲qzhwlzyWA 38ms8476kbC++14984b2023-08-28 15:28:032023-08-28 15:28:03

Judging History

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

  • [2023-08-28 15:28:03]
  • 评测
  • 测评结果:WA
  • 用时:38ms
  • 内存:8476kb
  • [2023-08-28 15:28:03]
  • 提交

answer

#include<iostream>
#include<cstdio>
#define maxn 100005
#define inf 2000000000
using namespace std;
int T,n,u,v,val[maxn]; struct node{int to,nex;}a[maxn]; int head[maxn],cnt=0; bool top[maxn];
void add(int from,int to){a[++cnt].to=to; a[cnt].nex=head[from]; head[from]=cnt;}
bool dfs(int p){
	if(!head[p]){if(val[p]==-1) val[p]=0,top[p]=1; return 1;}
	int mmax=-1,num=1; bool flag=0; for(int i=head[p];i;i=a[i].nex){
		if(!dfs(a[i].to)) return 0; flag|=top[a[i].to];
		if(val[a[i].to]>mmax) mmax=val[a[i].to],cnt=1; else if(val[a[i].to]==mmax) cnt++;
	} int res=mmax+(cnt>1);
	if(val[p]==-1){if(flag) top[p]=1; val[p]=res; return 1;}
	if(res>val[p]) return 0; if(!flag&&val[p]!=res) return 0; return 1;
}
int main(){
	scanf("%d",&T); while(T--){
		scanf("%d",&n); cnt=0; for(int i=1;i<=n;i++) scanf("%d",&val[i]),head[i]=0;
		for(int i=1;i<n;i++) scanf("%d%d",&u,&v),add(u,v);
		if(dfs(1)) printf("Reasonable\n"); else printf("Unreasonable\n");
	} return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 24ms
memory: 4852kb

input:

2
65535
-1 1000000000 -1 1000000000 1000000000 1000000000 -1 -1 -1 -1 -1 -1 1000000000 1000000000 1000000000 1000000000 -1 1000000000 1000000000 -1 1000000000 -1 1000000000 1000000000 -1 -1 -1 -1 -1 -1 -1 -1 -1 1000000000 1000000000 -1 1000000000 -1 -1 -1 1000000000 1000000000 1000000000 1000000000 ...

output:

Reasonable
Unreasonable

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 26ms
memory: 4736kb

input:

2
65535
1000000000 -1 -1 -1 1000000000 -1 -1 -1 -1 -1 1000000000 1000000000 -1 1000000000 -1 -1 -1 -1 1000000000 -1 1000000000 1000000000 -1 1000000000 1000000000 -1 1000000000 -1 1000000000 -1 1000000000 1000000000 -1 -1 1000000000 -1 -1 1000000000 1000000000 1000000000 -1 -1 -1 -1 1000000000 10000...

output:

Unreasonable
Reasonable

result:

ok 2 lines

Test #3:

score: 0
Accepted
time: 38ms
memory: 8476kb

input:

2
99999
49999 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -...

output:

Reasonable
Reasonable

result:

ok 2 lines

Test #4:

score: -100
Wrong Answer
time: 29ms
memory: 3652kb

input:

100000
2
503237730 503237730
1 2
2
940454426 940454426
1 2
2
248079005 -1
1 2
2
74614856 74614857
1 2
2
64379558 64379558
1 2
2
306909809 -1
1 2
2
-1 966615641
1 2
2
698391106 698391107
1 2
2
223750421 -1
1 2
2
705201637 705201637
1 2
2
256204065 -1
1 2
2
723177111 168932444
1 2
2
228089673 22808967...

output:

Reasonable
Reasonable
Reasonable
Unreasonable
Reasonable
Reasonable
Reasonable
Unreasonable
Reasonable
Reasonable
Reasonable
Reasonable
Reasonable
Unreasonable
Reasonable
Reasonable
Unreasonable
Reasonable
Reasonable
Reasonable
Reasonable
Reasonable
Reasonable
Reasonable
Reasonable
Reasonable
Reason...

result:

wrong answer 12th lines differ - expected: 'Unreasonable', found: 'Reasonable'