QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#769809#6654. 大纲ANIG#WA 24ms7456kbC++141.2kb2024-11-21 19:27:512024-11-21 19:27:51

Judging History

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

  • [2024-11-21 19:27:51]
  • 评测
  • 测评结果:WA
  • 用时:24ms
  • 内存:7456kb
  • [2024-11-21 19:27:51]
  • 提交

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'