QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#152628 | #6654. 大纲 | qzhwlzy | WA | 45ms | 8416kb | C++14 | 991b | 2023-08-28 15:29:56 | 2023-08-28 15:29:56 |
Judging History
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]=top[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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 18ms
memory: 4624kb
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: 4680kb
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: 45ms
memory: 8416kb
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: 34ms
memory: 3588kb
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: 32ms
memory: 3536kb
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: -100
Wrong Answer
time: 33ms
memory: 3632kb
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:
wrong answer 1305th lines differ - expected: 'Reasonable', found: 'Unreasonable'