QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#152424#6654. 大纲rsjWA 115ms15276kbC++141020b2023-08-28 08:17:582023-08-28 08:17:58

Judging History

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

  • [2023-08-28 08:17:58]
  • 评测
  • 测评结果:WA
  • 用时:115ms
  • 内存:15276kb
  • [2023-08-28 08:17:58]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+5;
struct edge {
	int to;
	edge *nex;
}*head[N];
int l[N],r[N],ok;
void add(int u,int v) {
	edge *cur=new edge;
	cur->to=v;
	cur->nex=head[u];
	head[u]=cur;
}
void dfs(int u) {
	int L=0,R=2e9;
	int a1=0,a2=0;
	for(edge *cur=head[u];cur;cur=cur->nex) {
		dfs(cur->to);
		L=max(L,l[cur->to]);
		R=min(R,r[cur->to]);
	}
	for(edge *cur=head[u];cur;cur=cur->nex) {
		if(L==l[cur->to]) a1++;
		if(R==r[cur->to]) a2++;
	}
	if(a1>1) L++;
	if(a2>1) R++;
	l[u]=max(l[u],L);
	r[u]=min(r[u],R);
	if(l[u]>r[u]) ok=0;
}
void get() {
	ok=1;
	int n,i,u,v;
	cin>>n;
	for(i=1;i<=n;i++) {
		cin>>l[i],head[i]=0;
		if(l[i]==-1) l[i]=0,r[i]=2e9;
		else r[i]=l[i];
	}
	for(i=1;i<n;i++) cin>>u>>v,add(u,v);
	dfs(1);
	if(ok) cout<<"Reasonable\n"; else cout<<"Unreasonable\n";
}
signed main() {
	// freopen("1.in","r",stdin);
	int T; cin>>T;
	while(T--) get();
	return 0;
}
/*
1
3
0 -1 0
1 2
2 3

1
3
0 -1 0
1 2
1 3
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 65ms
memory: 8712kb

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: 56ms
memory: 8768kb

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: -100
Wrong Answer
time: 115ms
memory: 15276kb

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:

Unreasonable
Unreasonable

result:

wrong answer 1st lines differ - expected: 'Reasonable', found: 'Unreasonable'