QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#234823 | #6654. 大纲 | stcmuyi# | WA | 28ms | 7988kb | C++20 | 1.6kb | 2023-11-01 23:10:28 | 2023-11-01 23:10:28 |
Judging History
answer
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define i64 long long
#define endl '\n'
#define lb(x) ((x) & (-x))
using namespace std;
const i64 mod = 1e9+7;
const int maxn = 1e4+10;
signed main()
{
IOS;
int t; cin >> t;
while(t--)
{
int n; cin >> n;
vector<int> l(n+1),r(n+1);
for(int i = 1; i <= n; ++i)
{
cin >> l[i];
r[i] = l[i];
if(l[i] == -1) l[i] = 0,r[i] = mod;
}
vector<vector<int>> v(n+1);
for(int i = 1; i < n; ++i)
{
int x,y; cin >> x >> y;
v[x].push_back(y);
v[y].push_back(x);
}
bool ok = 1;
auto dfs = [&](auto self,int x,int f) -> void
{
bool vis = 0;
for(int &u : v[x])
{
if(u == f) continue;
vis = 1;
self(self,u,x);
}
if(!vis) return;
int lmx = 0,cnt = 0,rmx = 0;
for(int &u : v[x])
{
if(u == f) continue;
if(l[u] > lmx) lmx = l[u],cnt = 1;
else if(l[u] == lmx) cnt++;
rmx = max(rmx,r[u]);
}
if(r[x] < lmx || l[x] > rmx) ok = 0;
if(r[x] == lmx && cnt > 1) ok = 0;
if(cnt > 1) l[x] = lmx+1;
else l[x] = lmx;
};
dfs(dfs,1,0);
cout << (ok ? "Reasonable" : "Unreasonable") << endl;
}
return 0;
}
/*
2
3
0 -1 0
1 2
2 3
3
0 -1 0
1 2
1 3
*/
详细
Test #1:
score: 0
Wrong Answer
time: 28ms
memory: 7988kb
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'