QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#769809 | #6654. 大纲 | ANIG# | WA | 24ms | 7456kb | C++14 | 1.2kb | 2024-11-21 19:27:51 | 2024-11-21 19:27:51 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
vector<int> a;
vector<vector<int>> ver;
int n;
const int inf=1e9+1e6;
pair<int,int> dfs(int u){
int l=0,r=inf;
if(!ver[u].size()){
if(a[u]!=-1) l=r=a[u];
return make_pair(l,r);
}
int cnt=0;
for(auto p:ver[u]){
auto T=dfs(p);
l=max(l,T.first);
r=min(r,T.second);
if(l==a[u]) cnt++;
}
if(l>r) return make_pair(l,r);
if(a[u]!=-1){
if(l<=a[u]&&a[u]<=r){
if(!(cnt==ver[u].size()&&l==a[u]&&cnt>1)) return make_pair(a[u],a[u]);
}
if(l<=a[u]&&a[u]==r+1){
if(ver[u].size()>1){
return make_pair(a[u],a[u]);
}
}
return make_pair(inf,0);
}
else return make_pair(l,r);
}
void solve(){
cin>>n;
a=vector<int>(n+1);
for(int i=1; i<=n; i++){
cin>>a[i];
}
ver=vector<vector<int>>(n+1);
for(int i=1; i<n; i++){
int x,y;
cin>>x>>y;
ver[x].emplace_back(y);
}
auto T=dfs(1);
if(T.first<=T.second) cout<<"Reasonable\n";
else cout<<"Unreasonable\n";
}
int main(){
cin.tie(0),cout.tie(0)->sync_with_stdio(false);
int T;
cin>>T;
while(T--) solve();
return 0;
}
/*
2
3
0 -1 0
1 2
2 3
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: 24ms
memory: 7456kb
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 Reasonable
result:
wrong answer 2nd lines differ - expected: 'Unreasonable', found: 'Reasonable'