QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#152428 | #6654. 大纲 | rsj | WA | 59ms | 8696kb | C++14 | 986b | 2023-08-28 08:23:18 | 2023-08-28 08:23:19 |
Judging History
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=0;
int a1=0,a2=0;
for(edge *cur=head[u];cur;cur=cur->nex) {
dfs(cur->to);
L=max(L,l[cur->to]);
R=max(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() {
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: 0
Wrong Answer
time: 59ms
memory: 8696kb
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:
Unreasonable Unreasonable
result:
wrong answer 1st lines differ - expected: 'Reasonable', found: 'Unreasonable'