QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#153150#6654. 大纲jiangtaizhe001AC ✓14ms11876kbC++141.9kb2023-08-29 14:52:392023-08-29 14:52:40

Judging History

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

  • [2023-08-29 14:52:40]
  • 评测
  • 测评结果:AC
  • 用时:14ms
  • 内存:11876kb
  • [2023-08-29 14:52:39]
  • 提交

answer

#include<cstdio>
#include<iostream>
#define db double
#define pc putchar
#define ll long long
#define Tp template<typename _T>
Tp _T mabs(_T a){ return a<0?-a:a; }
Tp _T mmax(_T a,_T b){ return a<b?b:a; }
Tp _T mmin(_T a,_T b){ return a<b?a:b; }
Tp void mswap(_T &a,_T &b){ _T t=a; a=b; b=t; return; }
using namespace std;
struct IO{
	char buf[1<<21],*p1,*p2;
	char gc(){ return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++; }
	IO & operator >> (char &x){ x=gc(); while(x=='\r'||x=='\n'||x==' ') x=gc(); return *this; }
	Tp IO & operator >> (_T &x){
		x=0; char c=gc(); bool f=0; while(c<'0'||c>'9'){ if(c=='-') f^=1; c=gc(); }
		while('0'<=c&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=gc(); f?x=-x:0; return *this;
	}
	int st[39],top;
	IO & operator << (char x) { pc(x); return *this; }
	Tp IO & operator << (_T x){
		if(x<0) x=-x,pc('-'); if(x==0){ pc('0'); return *this; }
		top=0; while(x) st[++top]=x%10,x/=10;
		while(top--) pc(st[top+1]+48); return *this;
	}
}fin;
#define maxn 100039
int n,u,v,head[maxn],to[maxn],nex[maxn],kkk;
#define add(x,y) nex[++kkk]=head[x]; head[x]=kkk; to[kkk]=y
int l[maxn],r[maxn],a[maxn],flag;
void dfs(int x){
	int i,cl=0,cr=0; l[x]=r[x]=-1;
	for(i=head[x];i;i=nex[i]){
		dfs(to[i]);
		if(l[x]==l[to[i]]) cl=1; else if(l[x]<l[to[i]]) cl=0,l[x]=l[to[i]];
		if(r[x]==r[to[i]]) cr=1; else if(r[x]<r[to[i]]) cr=0,r[x]=r[to[i]];
	} if(!head[x]) l[x]=0,r[x]=2e9;
	if(cr) r[x]++; if(cl) l[x]++;
	if(a[x]!=-1){
		if(a[x]<l[x]||a[x]>r[x]) flag=0;
		l[x]=r[x]=a[x];
	} return;
}
void work(){
	fin>>n; int i; kkk=0; for(i=1;i<=n;i++) head[i]=0;
	for(i=1;i<=n;i++) fin>>a[i]; for(i=1;i<n;i++){ fin>>u>>v; add(u,v); }
	flag=1; dfs(1); puts(flag?"Reasonable":"Unreasonable"); return;
}
int main(){
#ifdef LOCAL
	freopen("1.in","r",stdin);
	//freopen(".out","w",stdout);
#endif
	int T; fin>>T; while(T--) work(); return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 6ms
memory: 7836kb

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: 3ms
memory: 7528kb

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: 8ms
memory: 11876kb

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: 0
Accepted
time: 10ms
memory: 7200kb

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
Unreasonable
Reasonable
Unreasonable
Reasonable
Reasonable
Unreasonable
Reasonable
Reasonable
Reasonable
Unreasonable
Reasonable
Reasonable
Reasonable
Reasonable
Reasonable
Un...

result:

ok 100000 lines

Test #5:

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

input:

66666
3
530204916 -1 -1
2 3
1 2
3
476528072 476528072 476528072
1 2
2 3
3
-1 841888306 841888306
1 3
1 2
3
319191766 319191766 -1
3 2
1 3
3
177048577 531221023 -1
1 2
1 3
3
598759147 991100533 416954424
1 3
3 2
3
210423414 263192668 -1
1 2
1 3
3
902429034 -1 961317874
1 3
1 2
3
662280681 -1 33815376...

output:

Reasonable
Reasonable
Reasonable
Reasonable
Unreasonable
Unreasonable
Unreasonable
Unreasonable
Unreasonable
Unreasonable
Unreasonable
Unreasonable
Unreasonable
Reasonable
Reasonable
Reasonable
Reasonable
Reasonable
Reasonable
Unreasonable
Unreasonable
Reasonable
Unreasonable
Unreasonable
Reasonable...

result:

ok 66666 lines

Test #6:

score: 0
Accepted
time: 10ms
memory: 5808kb

input:

50000
3
-1 6 6
1 3
1 2
5
0 -1 -1 0 -1
4 5
4 2
2 3
1 4
3
859025665 859025665 859025665
1 2
2 3
4
1 1 1 1
3 2
2 4
1 3
3
2 -1 -1
3 2
1 3
4
2 1 1 2
4 2
1 4
4 3
2
2 2
1 2
3
-1 1 2
1 3
3 2
3
1 1 1
1 3
3 2
2
-1 8
1 2
4
4 4 296285101 1
2 3
1 2
1 4
4
-1 -1 -1 0
2 4
1 2
2 3
5
-1 0 0 0 0
1 4
1 2
1 5
1 3
4
-1 6...

output:

Reasonable
Unreasonable
Reasonable
Reasonable
Reasonable
Reasonable
Reasonable
Unreasonable
Reasonable
Reasonable
Unreasonable
Reasonable
Reasonable
Reasonable
Reasonable
Reasonable
Unreasonable
Reasonable
Reasonable
Unreasonable
Reasonable
Reasonable
Unreasonable
Unreasonable
Reasonable
Unreasonabl...

result:

ok 50000 lines

Test #7:

score: 0
Accepted
time: 10ms
memory: 7752kb

input:

20000
9
2 1 1 2 0 2 2 2 0
9 5
6 9
6 2
4 7
1 4
8 6
6 3
7 8
5
14672963 -1 14672966 -1 -1
5 3
2 5
4 2
1 4
18
3 2 0 3 0 0 0 2 1 -1 2 2 1 0 0 0 2 0
4 13
4 14
4 16
4 11
4 12
4 10
4 17
8 18
4 9
14 5
4 7
8 2
1 8
18 3
1 4
4 15
4 6
12
-1 3 -1 -1 -1 1 -1 -1 -1 0 -1 0
8 9
12 5
10 7
4 2
4 12
2 10
3 4
2 11
1 3
2 ...

output:

Reasonable
Unreasonable
Reasonable
Reasonable
Reasonable
Reasonable
Unreasonable
Unreasonable
Reasonable
Reasonable
Reasonable
Unreasonable
Unreasonable
Unreasonable
Unreasonable
Unreasonable
Reasonable
Unreasonable
Reasonable
Reasonable
Reasonable
Unreasonable
Unreasonable
Reasonable
Reasonable
Rea...

result:

ok 20000 lines

Test #8:

score: 0
Accepted
time: 5ms
memory: 6164kb

input:

5000
54
-1 -1 0 -1 -1 0 -1 3 -1 -1 -1 -1 -1 -1 0 -1 -1 -1 0 -1 -1 -1 -1 -1 -1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 1 -1 -1 -1 0 0 0 -1 0 -1 0 -1 -1 -1 -1 -1 -1
12 53
45 15
38 5
22 17
16 38
50 3
53 34
32 47
36 50
35 36
13 32
25 10
24 16
3 48
6 39
42 7
41 23
15 20
8 14
49 28
26 11
34 18
28 8
17 24
47 40
...

output:

Reasonable
Unreasonable
Reasonable
Unreasonable
Reasonable
Unreasonable
Reasonable
Unreasonable
Unreasonable
Unreasonable
Reasonable
Reasonable
Unreasonable
Reasonable
Unreasonable
Reasonable
Reasonable
Reasonable
Reasonable
Unreasonable
Unreasonable
Unreasonable
Reasonable
Unreasonable
Unreasonable...

result:

ok 5000 lines

Test #9:

score: 0
Accepted
time: 9ms
memory: 6464kb

input:

2000
93
-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 2 -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
22 21
27 51
73 ...

output:

Reasonable
Unreasonable
Reasonable
Unreasonable
Reasonable
Unreasonable
Unreasonable
Reasonable
Unreasonable
Reasonable
Reasonable
Reasonable
Reasonable
Unreasonable
Reasonable
Unreasonable
Reasonable
Reasonable
Unreasonable
Unreasonable
Reasonable
Reasonable
Unreasonable
Reasonable
Unreasonable
Unr...

result:

ok 2000 lines

Test #10:

score: 0
Accepted
time: 5ms
memory: 8064kb

input:

500
185
7 1 1 -1 1 -1 -1 -1 1 0 -1 1 0 1 1 -1 1 1 0 0 2 2 1 2 2 1 1 1 1 0 -1 7 -1 0 -1 -1 1 1 1 -1 -1 0 -1 0 -1 2 -1 0 0 1 1 -1 0 2 -1 -1 1 2 1 1 0 2 0 -1 -1 1 2 4 -1 4 0 -1 0 1 3 2 -1 -1 0 -1 3 2 0 2 2 0 0 0 0 2 -1 -1 -1 0 -1 2 1 -1 1 -1 7 0 1 -1 1 -1 0 1 0 1 5 1 2 1 1 -1 2 0 2 2 -1 0 -1 1 1 2 1 1 ...

output:

Unreasonable
Unreasonable
Reasonable
Reasonable
Unreasonable
Reasonable
Unreasonable
Reasonable
Unreasonable
Unreasonable
Unreasonable
Unreasonable
Reasonable
Unreasonable
Unreasonable
Reasonable
Unreasonable
Unreasonable
Reasonable
Unreasonable
Unreasonable
Unreasonable
Reasonable
Unreasonable
Reas...

result:

ok 500 lines

Test #11:

score: 0
Accepted
time: 9ms
memory: 6132kb

input:

200
1068
-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 -1 -1 ...

output:

Reasonable
Unreasonable
Reasonable
Unreasonable
Unreasonable
Unreasonable
Reasonable
Reasonable
Unreasonable
Unreasonable
Unreasonable
Unreasonable
Reasonable
Unreasonable
Unreasonable
Unreasonable
Unreasonable
Reasonable
Unreasonable
Unreasonable
Reasonable
Unreasonable
Unreasonable
Unreasonable
Re...

result:

ok 200 lines

Test #12:

score: 0
Accepted
time: 9ms
memory: 6380kb

input:

50
6555
10 -1 2 1 1 -1 2 2 2 2 2 -1 2 1 1 0 1 2 2 0 0 0 2 1 3 0 0 0 -1 1 1 1 -1 0 1 1 1 0 2 -1 2 -1 1 2 1 1 -1 2 2 0 2 2 -1 1 2 -1 2 0 2 -1 1 0 3 1 0 1 0 1 0 -1 2 0 2 1 -1 1 0 1 0 2 1 1 2 1 1 2 2 2 1 -1 -1 -1 2 1 4 0 -1 -1 1 1 -1 -1 1 -1 1 0 2 0 1 2 0 2 2 0 -1 -1 2 0 -1 2 0 -1 0 0 4 2 2 2 1 1 1 1 -1...

output:

Reasonable
Reasonable
Unreasonable
Reasonable
Unreasonable
Unreasonable
Unreasonable
Unreasonable
Reasonable
Reasonable
Unreasonable
Unreasonable
Unreasonable
Unreasonable
Reasonable
Unreasonable
Unreasonable
Reasonable
Unreasonable
Unreasonable
Reasonable
Reasonable
Reasonable
Unreasonable
Reasonab...

result:

ok 50 lines

Test #13:

score: 0
Accepted
time: 11ms
memory: 7696kb

input:

20
14327
-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 0 -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 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...

output:

Reasonable
Unreasonable
Unreasonable
Unreasonable
Reasonable
Unreasonable
Unreasonable
Reasonable
Unreasonable
Unreasonable
Unreasonable
Unreasonable
Reasonable
Reasonable
Unreasonable
Reasonable
Reasonable
Unreasonable
Reasonable
Reasonable

result:

ok 20 lines

Test #14:

score: 0
Accepted
time: 10ms
memory: 8136kb

input:

8
35399
-1 -1 4 1 4 2 -1 4 -1 2 1 1 -1 2 3 -1 3 4 -1 -1 6 0 0 3 -1 5 -1 5 3 0 -1 -1 -1 -1 0 -1 1 5 3 4 4 2 1 6 2 2 -1 4 -1 0 -1 -1 4 1 0 0 5 -1 0 -1 2 2 2 1 1 6 2 2 2 3 -1 3 4 4 -1 -1 2 -1 3 0 0 2 -1 -1 3 -1 3 1 2 2 -1 6 4 0 -1 -1 -1 -1 3 -1 -1 1 -1 1 4 3 4 2 -1 6 3 -1 2 -1 2 3 -1 0 -1 -1 1 6 2 6 -1...

output:

Unreasonable
Unreasonable
Reasonable
Reasonable
Unreasonable
Unreasonable
Reasonable
Reasonable

result:

ok 8 lines

Test #15:

score: 0
Accepted
time: 12ms
memory: 8116kb

input:

4
28617
-1 -1 15040626 -1 -1 68730989 68730991 -1 68730984 8635907 68730988 -1 -1 -1 -1 68730983 68730993 68730992 -1 -1 68730989 29772797 68730985 34273767 -1 61879811 68730988 67015657 68730993 25288248 68730987 -1 -1 -1 19396694 68730986 -1 7501231 68730991 68730986 -1 68730988 30125487 63758400 ...

output:

Unreasonable
Reasonable
Unreasonable
Unreasonable

result:

ok 4 lines

Test #16:

score: 0
Accepted
time: 14ms
memory: 8032kb

input:

2
100000
9 -1 -1 1 2 2 1 -1 0 -1 -1 -1 -1 -1 -1 -1 0 -1 -1 -1 -1 2 0 -1 1 -1 2 -1 0 -1 -1 -1 0 0 1 -1 -1 -1 -1 -1 2 -1 0 0 -1 0 -1 2 -1 -1 -1 -1 -1 -1 -1 0 -1 1 -1 0 -1 1 -1 0 1 -1 -1 -1 -1 -1 -1 2 -1 -1 -1 -1 -1 2 -1 1 -1 2 -1 0 1 0 -1 -1 1 -1 -1 -1 1 2 -1 -1 -1 -1 -1 2 -1 -1 -1 1 -1 -1 1 -1 1 0 -1...

output:

Reasonable
Unreasonable

result:

ok 2 lines